summaryrefslogtreecommitdiff
path: root/RC9/qpid/cpp/examples/qmf-console
diff options
context:
space:
mode:
Diffstat (limited to 'RC9/qpid/cpp/examples/qmf-console')
-rw-r--r--RC9/qpid/cpp/examples/qmf-console/Makefile.am41
-rw-r--r--RC9/qpid/cpp/examples/qmf-console/console.cpp150
-rw-r--r--RC9/qpid/cpp/examples/qmf-console/ping.cpp129
-rw-r--r--RC9/qpid/cpp/examples/qmf-console/printevents.cpp105
4 files changed, 425 insertions, 0 deletions
diff --git a/RC9/qpid/cpp/examples/qmf-console/Makefile.am b/RC9/qpid/cpp/examples/qmf-console/Makefile.am
new file mode 100644
index 0000000000..e115fc0fb0
--- /dev/null
+++ b/RC9/qpid/cpp/examples/qmf-console/Makefile.am
@@ -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.
+#
+
+examplesdir=$(pkgdatadir)/examples/qmf-console
+
+MAKELDFLAG = qmfconsole
+include $(top_srcdir)/examples/makedist.mk
+
+noinst_PROGRAMS=console printevents ping
+
+console_SOURCES=console.cpp
+console_LDADD=$(CONSOLE_LIB)
+
+printevents_SOURCES=printevents.cpp
+printevents_LDADD=$(CONSOLE_LIB)
+
+ping_SOURCES=ping.cpp
+ping_LDADD=$(CONSOLE_LIB)
+
+examples_DATA= \
+ console.cpp \
+ printevents.cpp \
+ ping.cpp \
+ $(MAKEDIST)
+
diff --git a/RC9/qpid/cpp/examples/qmf-console/console.cpp b/RC9/qpid/cpp/examples/qmf-console/console.cpp
new file mode 100644
index 0000000000..5700d5556f
--- /dev/null
+++ b/RC9/qpid/cpp/examples/qmf-console/console.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/console/ConsoleListener.h"
+#include "qpid/console/SessionManager.h"
+
+using namespace std;
+using namespace qpid::console;
+
+class Listener : public ConsoleListener {
+public:
+ ~Listener() {}
+
+ void brokerConnected(const Broker& broker) {
+ cout << "brokerConnected: " << broker << endl;
+ }
+
+ void brokerDisconnected(const Broker& broker) {
+ cout << "brokerDisconnected: " << broker << endl;
+ }
+
+ void newPackage(const std::string& name) {
+ cout << "newPackage: " << name << endl;
+ }
+
+ void newClass(const ClassKey& classKey) {
+ cout << "newClass: key=" << classKey << endl;
+ }
+
+ void newAgent(const Agent& agent) {
+ cout << "newAgent: " << agent << endl;
+ }
+
+ void delAgent(const Agent& agent) {
+ cout << "delAgent: " << agent << endl;
+ }
+
+ void objectProps(Broker& broker, Object& object) {
+ cout << "objectProps: broker=" << broker << " object=" << object << endl;
+ }
+
+ void objectStats(Broker& broker, Object& object) {
+ cout << "objectStats: broker=" << broker << " object=" << object << endl;
+ }
+
+ void event(Event& event) {
+ cout << "event: " << event << endl;
+ }
+};
+
+
+//==============================================================
+// Main program
+//==============================================================
+int main_int(int /*argc*/, char** /*argv*/)
+{
+ //Listener listener;
+ qpid::client::ConnectionSettings settings;
+
+ cout << "Creating SessionManager" << endl;
+ SessionManager sm;
+ cout << "Adding broker" << endl;
+ Broker* broker;
+
+ broker = sm.addBroker(settings);
+
+ cout << "Package List:" << endl;
+ vector<string> packages;
+ sm.getPackages(packages);
+ for (vector<string>::iterator iter = packages.begin(); iter != packages.end(); iter++) {
+ cout << " " << *iter << endl;
+ SessionManager::KeyVector classKeys;
+ sm.getClasses(classKeys, *iter);
+ for (SessionManager::KeyVector::iterator cIter = classKeys.begin();
+ cIter != classKeys.end(); cIter++)
+ cout << " " << *cIter << endl;
+ }
+
+ Object::Vector list;
+ cout << "getting exchanges..." << endl;
+ sm.getObjects(list, "exchange");
+ cout << " returned " << list.size() << " elements" << endl;
+
+ for (Object::Vector::iterator i = list.begin(); i != list.end(); i++) {
+ cout << "exchange: " << *i << endl;
+ }
+
+ list.clear();
+ cout << "getting queues..." << endl;
+ sm.getObjects(list, "queue");
+ cout << " returned " << list.size() << " elements" << endl;
+
+ for (Object::Vector::iterator i = list.begin(); i != list.end(); i++) {
+ cout << "queue: " << *i << endl;
+ cout << " bindingCount=" << i->attrUint("bindingCount") << endl;
+ cout << " arguments=" << i->attrMap("arguments") << endl;
+ }
+
+ list.clear();
+ sm.getObjects(list, "broker");
+ if (list.size() == 1) {
+ Object& broker = *list.begin();
+
+ cout << "Broker: " << broker << endl;
+
+ Object::AttributeMap args;
+ MethodResponse result;
+ args.addUint("sequence", 1);
+ args.addString("body", "Testing...");
+
+ cout << "Call echo method..." << endl;
+ broker.invokeMethod("echo", args, result);
+ cout << "Result: code=" << result.code << " text=" << result.text << endl;
+ for (Object::AttributeMap::iterator aIter = result.arguments.begin();
+ aIter != result.arguments.end(); aIter++) {
+ cout << " Output Arg: " << aIter->first << " => " << aIter->second->str() << endl;
+ }
+ }
+
+ sm.delBroker(broker);
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ try {
+ return main_int(argc, argv);
+ } catch(std::exception& e) {
+ cout << "Top Level Exception: " << e.what() << endl;
+ }
+}
+
diff --git a/RC9/qpid/cpp/examples/qmf-console/ping.cpp b/RC9/qpid/cpp/examples/qmf-console/ping.cpp
new file mode 100644
index 0000000000..debca7428a
--- /dev/null
+++ b/RC9/qpid/cpp/examples/qmf-console/ping.cpp
@@ -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.
+ *
+ */
+
+#include "qpid/console/SessionManager.h"
+
+using namespace std;
+using namespace qpid::console;
+
+//==============================================================
+// Main program
+//==============================================================
+int main_int(int /*argc*/, char** /*argv*/)
+{
+ //
+ // Declare connection settings for the messaging broker. The settings default to
+ // localhost:5672 with user guest (password guest). Refer to the header file
+ // <qpid/client/ConnectionSettings.h> for full details.
+ //
+ qpid::client::ConnectionSettings connSettings;
+
+ //
+ // Declare the (optional) session manager settings. Override the default timeout
+ // for methods calls to be 2 seconds.
+ //
+ SessionManager::Settings smSettings;
+ smSettings.methodTimeout = 2;
+
+ //
+ // Declare the console session manager. With a null listener argument, it defaults to
+ // synchronous-only access mode.
+ //
+ SessionManager sm(0, smSettings);
+
+ //
+ // Add a broker connection to the session manager.
+ //
+ Broker* broker = sm.addBroker(connSettings);
+
+ uint32_t count = 5; // The number of echo requests we will send to the broker.
+ Object::Vector list; // A container for holding objects retrieved from the broker.
+
+ //
+ // Query for a list of 'broker' objects from the Management Database
+ //
+ sm.getObjects(list, "broker");
+
+ //
+ // We expect one object (since we are connected to only one broker)
+ //
+ if (list.size() == 1) {
+ Object& brokerObject = *(list.begin());
+
+ for (uint32_t iter = 0; iter < count; iter++) {
+ //
+ // Declare a container for arguments to be sent with the "echo" method
+ // that we will invoke on the remote "broker" object.
+ //
+ Object::AttributeMap args;
+
+ //
+ // Declare a container for the result of the method invocation.
+ //
+ MethodResponse result;
+
+ //
+ // Set the values of the input arguments.
+ //
+ args.addUint("sequence", iter);
+ args.addString("body", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+
+ cout << "Ping Broker: " << broker->getUrl() << "... ";
+ cout.flush();
+
+ //
+ // Invoke the method. This is a synchronous operation that will block until
+ // the method completes and returns a result.
+ //
+ brokerObject.invokeMethod("echo", args, result);
+
+ //
+ // result.code is the return code (0 => Success)
+ // result.text is the return text
+ // result.arguments is a container (of type Object::AttributeMap) that holds
+ // the output arguments (if any) from the method.
+ //
+ cout << "Result: code=" << result.code << " text=" << result.text;
+ if (result.code == 0)
+ cout << " seq=" << result.arguments["sequence"]->asUint();
+ cout << endl;
+
+ if (result.code == 0 && iter < count - 1)
+ ::sleep(1);
+ }
+ }
+
+ //
+ // Disconnect the broker from the session manager.
+ //
+ sm.delBroker(broker);
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ try {
+ return main_int(argc, argv);
+ } catch(std::exception& e) {
+ cout << "Top Level Exception: " << e.what() << endl;
+ }
+}
+
diff --git a/RC9/qpid/cpp/examples/qmf-console/printevents.cpp b/RC9/qpid/cpp/examples/qmf-console/printevents.cpp
new file mode 100644
index 0000000000..bbec2c1af0
--- /dev/null
+++ b/RC9/qpid/cpp/examples/qmf-console/printevents.cpp
@@ -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/console/ConsoleListener.h"
+#include "qpid/console/SessionManager.h"
+#include "qpid/sys/Time.h"
+
+using namespace std;
+using namespace qpid::console;
+
+//
+// Define a listener class to receive asynchronous events.
+//
+class Listener : public ConsoleListener {
+public:
+ void brokerConnected(const Broker& broker) {
+ cout << qpid::sys::now() << " NOTIC qpid-printevents:brokerConnected broker=" <<
+ broker.getUrl() << endl;
+ }
+
+ void brokerDisconnected(const Broker& broker) {
+ cout << qpid::sys::now() << " NOTIC qpid-printevents:brokerDisonnected broker=" <<
+ broker.getUrl() << endl;
+ }
+
+ void event(Event& event) {
+ cout << event << endl;
+ }
+};
+
+
+//==============================================================
+// Main program
+//==============================================================
+int main_int(int /*argc*/, char** /*argv*/)
+{
+ //
+ // Declare an instance of our listener.
+ //
+ Listener listener;
+
+ //
+ // Declare connection settings for the messaging broker. The settings default to
+ // localhost:5672 with user guest (password guest). Refer to the header file
+ // <qpid/client/ConnectionSettings.h> for full details.
+ //
+ qpid::client::ConnectionSettings connSettings;
+
+ //
+ // Declare the (optional) session manager settings. Disable the reception of
+ // object updates and heartbeats. Note that by disabling the reception of things
+ // we don't need, we don't unnecessarily use network bandwidth.
+ //
+ SessionManager::Settings smSettings;
+ smSettings.rcvObjects = false;
+ smSettings.rcvHeartbeats = false;
+
+ //
+ // Declare the console session manager.
+ //
+ SessionManager sm(&listener, smSettings);
+
+ //
+ // Add a broker connection to the session manager. If desired, multiple brokers may
+ // be connected.
+ //
+ Broker* broker = sm.addBroker(connSettings);
+
+ //
+ // Sleep indefinitely while asynchronous events are handled by the listener.
+ //
+ for (;;)
+ ::sleep(1);
+
+ sm.delBroker(broker);
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ try {
+ return main_int(argc, argv);
+ } catch(std::exception& e) {
+ cout << "Top Level Exception: " << e.what() << endl;
+ }
+}
+