summaryrefslogtreecommitdiff
path: root/qpid/cpp/bindings/qmf2/examples
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/bindings/qmf2/examples')
-rw-r--r--qpid/cpp/bindings/qmf2/examples/cpp/Makefile.am33
-rw-r--r--qpid/cpp/bindings/qmf2/examples/cpp/agent.cpp250
-rw-r--r--qpid/cpp/bindings/qmf2/examples/cpp/list_agents.cpp73
-rw-r--r--qpid/cpp/bindings/qmf2/examples/cpp/print_events.cpp64
-rwxr-xr-xqpid/cpp/bindings/qmf2/examples/python/agent.py196
-rw-r--r--qpid/cpp/bindings/qmf2/examples/python/find_agents.py57
-rw-r--r--qpid/cpp/bindings/qmf2/examples/ruby/agent_external.rb84
-rw-r--r--qpid/cpp/bindings/qmf2/examples/ruby/agent_internal.rb77
-rw-r--r--qpid/cpp/bindings/qmf2/examples/ruby/find_agents.rb63
9 files changed, 897 insertions, 0 deletions
diff --git a/qpid/cpp/bindings/qmf2/examples/cpp/Makefile.am b/qpid/cpp/bindings/qmf2/examples/cpp/Makefile.am
new file mode 100644
index 0000000000..84207d43c4
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/cpp/Makefile.am
@@ -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.
+#
+
+INCLUDE = -I$(top_srcdir)/include
+
+AM_CPPFLAGS = $(INCLUDE)
+
+noinst_PROGRAMS=agent list_agents print_events
+
+agent_SOURCES=agent.cpp
+agent_LDADD=$(top_builddir)/src/libqmf2.la
+
+list_agents_SOURCES=list_agents.cpp
+list_agents_LDADD=$(top_builddir)/src/libqmf2.la
+
+print_events_SOURCES=print_events.cpp
+print_events_LDADD=$(top_builddir)/src/libqmf2.la
diff --git a/qpid/cpp/bindings/qmf2/examples/cpp/agent.cpp b/qpid/cpp/bindings/qmf2/examples/cpp/agent.cpp
new file mode 100644
index 0000000000..00554539eb
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/cpp/agent.cpp
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT 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/Connection.h>
+#include <qpid/messaging/Duration.h>
+#include <qmf/AgentSession.h>
+#include <qmf/AgentEvent.h>
+#include <qmf/Schema.h>
+#include <qmf/SchemaProperty.h>
+#include <qmf/SchemaMethod.h>
+#include <qmf/Data.h>
+#include <qmf/DataAddr.h>
+#include <qpid/types/Variant.h>
+#include <string>
+#include <iostream>
+
+using namespace std;
+using namespace qmf;
+using qpid::types::Variant;
+using qpid::messaging::Duration;
+
+class ExampleAgent {
+public:
+ ExampleAgent(const string& url);
+ ~ExampleAgent();
+
+ void setupSchema();
+ void populateData();
+ void run();
+private:
+ qpid::messaging::Connection connection;
+ AgentSession session;
+ Schema sch_exception;
+ Schema sch_control;
+ Schema sch_child;
+ Schema sch_event;
+ Data control;
+ DataAddr controlAddr;
+
+ bool method(AgentEvent& event);
+};
+
+
+ExampleAgent::ExampleAgent(const string& url)
+{
+ //
+ // Create and open a messaging connection to a broker.
+ //
+ connection = qpid::messaging::Connection(url, "{reconnect:True}");
+ connection.open();
+
+ //
+ // Create, configure, and open a QMFv2 agent session using the connection.
+ //
+ session = AgentSession(connection, "{interval:30}");
+ session.setVendor("profitron.com");
+ session.setProduct("gizmo");
+ session.setAttribute("attr1", 2000);
+ session.open();
+}
+
+ExampleAgent::~ExampleAgent()
+{
+ //
+ // Clean up the QMF session and the AMQP connection.
+ //
+ session.close();
+ connection.close();
+}
+
+void ExampleAgent::setupSchema()
+{
+ //
+ // Create and register schema for this agent.
+ //
+ string package("com.profitron.gizmo");
+
+ //
+ // Declare a schema for a structured exception that can be used in failed
+ // method invocations.
+ //
+ sch_exception = Schema(SCHEMA_TYPE_DATA, package, "exception");
+ sch_exception.addProperty(SchemaProperty("whatHappened", SCHEMA_DATA_STRING));
+ sch_exception.addProperty(SchemaProperty("howBad", SCHEMA_DATA_INT));
+ sch_exception.addProperty(SchemaProperty("details", SCHEMA_DATA_MAP));
+
+ //
+ // Declare a control object to test methods against.
+ //
+ sch_control = Schema(SCHEMA_TYPE_DATA, package, "control");
+ sch_control.addProperty(SchemaProperty("state", SCHEMA_DATA_STRING));
+ sch_control.addProperty(SchemaProperty("methodCount", SCHEMA_DATA_INT));
+
+ SchemaMethod stopMethod("stop", "{desc:'Stop Agent'}");
+ stopMethod.addArgument(SchemaProperty("message", SCHEMA_DATA_STRING));
+ sch_control.addMethod(stopMethod);
+
+ SchemaMethod echoMethod("echo", "{desc:'Echo Arguments'}");
+ echoMethod.addArgument(SchemaProperty("sequence", SCHEMA_DATA_INT, "{dir:INOUT}"));
+ echoMethod.addArgument(SchemaProperty("map", SCHEMA_DATA_MAP, "{dir:INOUT}"));
+ sch_control.addMethod(echoMethod);
+
+ SchemaMethod eventMethod("event", "{desc:'Raise an Event'}");
+ eventMethod.addArgument(SchemaProperty("text", SCHEMA_DATA_STRING, "{dir:IN}"));
+ eventMethod.addArgument(SchemaProperty("severity", SCHEMA_DATA_INT, "{dir:IN}"));
+ sch_control.addMethod(eventMethod);
+
+ SchemaMethod failMethod("fail", "{desc:'Expected to Fail'}");
+ failMethod.addArgument(SchemaProperty("useString", SCHEMA_DATA_BOOL, "{dir:IN}"));
+ failMethod.addArgument(SchemaProperty("stringVal", SCHEMA_DATA_STRING, "{dir:IN}"));
+ failMethod.addArgument(SchemaProperty("details", SCHEMA_DATA_MAP, "{dir:IN}"));
+ sch_control.addMethod(failMethod);
+
+ SchemaMethod createMethod("create_child", "{desc:'Create Child Object'}");
+ createMethod.addArgument(SchemaProperty("name", SCHEMA_DATA_STRING, "{dir:IN}"));
+ createMethod.addArgument(SchemaProperty("childAddr", SCHEMA_DATA_MAP, "{dir:OUT}"));
+ sch_control.addMethod(createMethod);
+
+ //
+ // Declare the child class
+ //
+ sch_child = Schema(SCHEMA_TYPE_DATA, package, "child");
+ sch_child.addProperty(SchemaProperty("name", SCHEMA_DATA_STRING));
+
+ //
+ // Declare the event class
+ //
+ sch_event = Schema(SCHEMA_TYPE_EVENT, package, "event");
+ sch_event.addProperty(SchemaProperty("text", SCHEMA_DATA_STRING));
+
+ //
+ // Register our schemata with the agent session.
+ //
+ session.registerSchema(sch_exception);
+ session.registerSchema(sch_control);
+ session.registerSchema(sch_child);
+ session.registerSchema(sch_event);
+}
+
+void ExampleAgent::populateData()
+{
+ //
+ // Create a control object and give it to the agent session to manage.
+ //
+ control = Data(sch_control);
+ control.setProperty("state", "OPERATIONAL");
+ control.setProperty("methodCount", 0);
+ controlAddr = session.addData(control, "singleton");
+}
+
+void ExampleAgent::run()
+{
+ AgentEvent event;
+ bool running(true);
+
+ while (running) {
+ bool valid(session.nextEvent(event, Duration::SECOND));
+ if (valid && running) {
+ switch (event.getType()) {
+ case AGENT_METHOD:
+ running = method(event);
+ break;
+ }
+ }
+ }
+}
+
+bool ExampleAgent::method(AgentEvent& event)
+{
+ const string& name(event.getMethodName());
+ control.setProperty("methodCount", control.getProperty("methodCount").asUint32() + 1);
+
+ try {
+ if (controlAddr == event.getDataAddr()) {
+ if (name == "stop") {
+ cout << "Stopping: message=" << event.getArguments()["message"] << endl;
+ session.methodSuccess(event);
+ return false;
+ }
+
+ if (name == "echo") {
+ event.addReturnArgument("sequence", event.getArguments()["sequence"]);
+ event.addReturnArgument("map", event.getArguments()["map"]);
+ session.methodSuccess(event);
+ return true;
+ }
+
+ if (name == "event") {
+ Data ev(sch_event);
+ ev.setProperty("text", event.getArguments()["text"]);
+ session.raiseEvent(ev, event.getArguments()["severity"]);
+ session.methodSuccess(event);
+ return true;
+ }
+
+ if (name == "fail") {
+ if (event.getArguments()["useString"])
+ session.raiseException(event, event.getArguments()["stringVal"]);
+ else {
+ Data ex(sch_exception);
+ ex.setProperty("whatHappened", "It Failed");
+ ex.setProperty("howBad", 75);
+ ex.setProperty("details", event.getArguments()["details"]);
+ session.raiseException(event, ex);
+ }
+ }
+
+ if (name == "create_child") {
+ const string& name(event.getArguments()["name"]);
+ Data child(sch_child);
+ child.setProperty("name", name);
+ DataAddr addr(session.addData(child, name));
+ event.addReturnArgument("childAddr", addr.asMap());
+ session.methodSuccess(event);
+ }
+ }
+ } catch (const exception& e) {
+ //
+ // Pass the exception on to the caller.
+ //
+ session.raiseException(event, e.what());
+ }
+
+ return true;
+}
+
+int main()
+{
+ ExampleAgent agent("localhost");
+ agent.setupSchema();
+ agent.populateData();
+ agent.run();
+}
+
diff --git a/qpid/cpp/bindings/qmf2/examples/cpp/list_agents.cpp b/qpid/cpp/bindings/qmf2/examples/cpp/list_agents.cpp
new file mode 100644
index 0000000000..327da9661f
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/cpp/list_agents.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 <qpid/messaging/Connection.h>
+#include <qpid/messaging/Duration.h>
+#include <qmf/ConsoleSession.h>
+#include <qmf/ConsoleEvent.h>
+#include <qmf/Agent.h>
+#include <qpid/types/Variant.h>
+#include <string>
+#include <iostream>
+
+using namespace std;
+using namespace qmf;
+using qpid::types::Variant;
+using qpid::messaging::Duration;
+
+int main(int argc, char** argv)
+{
+ string url("localhost");
+ string connectionOptions;
+ string sessionOptions;
+
+ if (argc > 1)
+ url = argv[1];
+ if (argc > 2)
+ connectionOptions = argv[2];
+ if (argc > 3)
+ sessionOptions = argv[3];
+
+ qpid::messaging::Connection connection(url, connectionOptions);
+ connection.open();
+
+ ConsoleSession session(connection, sessionOptions);
+ session.open();
+
+ session.setAgentFilter("");
+
+ while (true) {
+ ConsoleEvent event;
+ if (session.nextEvent(event)) {
+ if (event.getType() == CONSOLE_AGENT_ADD) {
+ string extra;
+ if (event.getAgent().getName() == session.getConnectedBrokerAgent().getName())
+ extra = " [Connected Broker]";
+ cout << "Agent Added: " << event.getAgent().getName() << extra << endl;
+ }
+ if (event.getType() == CONSOLE_AGENT_DEL) {
+ if (event.getAgentDelReason() == AGENT_DEL_AGED)
+ cout << "Agent Aged: " << event.getAgent().getName() << endl;
+ else
+ cout << "Agent Filtered: " << event.getAgent().getName() << endl;
+ }
+ }
+ }
+}
+
diff --git a/qpid/cpp/bindings/qmf2/examples/cpp/print_events.cpp b/qpid/cpp/bindings/qmf2/examples/cpp/print_events.cpp
new file mode 100644
index 0000000000..9883a19962
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/cpp/print_events.cpp
@@ -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.
+ */
+
+#include <qpid/messaging/Connection.h>
+#include <qpid/messaging/Duration.h>
+#include <qmf/ConsoleSession.h>
+#include <qmf/ConsoleEvent.h>
+#include <qmf/Data.h>
+#include <qpid/types/Variant.h>
+#include <string>
+#include <iostream>
+
+using namespace std;
+using namespace qmf;
+using qpid::types::Variant;
+using qpid::messaging::Duration;
+
+int main(int argc, char** argv)
+{
+ string url("localhost");
+ string connectionOptions;
+ string sessionOptions;
+
+ if (argc > 1)
+ url = argv[1];
+ if (argc > 2)
+ connectionOptions = argv[2];
+ if (argc > 3)
+ sessionOptions = argv[3];
+
+ qpid::messaging::Connection connection(url, connectionOptions);
+ connection.open();
+
+ ConsoleSession session(connection, sessionOptions);
+ session.open();
+
+ while (true) {
+ ConsoleEvent event;
+ if (session.nextEvent(event)) {
+ if (event.getType() == CONSOLE_EVENT) {
+ const Data& data(event.getData(0));
+ cout << "Event: timestamp=" << event.getTimestamp() << " severity=" <<
+ event.getSeverity() << " content=" << data.getProperties() << endl;
+ }
+ }
+ }
+}
+
diff --git a/qpid/cpp/bindings/qmf2/examples/python/agent.py b/qpid/cpp/bindings/qmf2/examples/python/agent.py
new file mode 100755
index 0000000000..b24890f531
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/python/agent.py
@@ -0,0 +1,196 @@
+#!/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 cqpid
+from qmf2 import *
+
+
+class ExampleAgent(AgentHandler):
+ """
+ This example agent is implemented as a single class that inherits AgentHandler.
+ It does not use a separate thread since once set up, it is driven strictly by
+ incoming method calls.
+ """
+
+ def __init__(self, url):
+ ##
+ ## Create and open a messaging connection to a broker.
+ ##
+ self.connection = cqpid.Connection(url, "{reconnect:True}")
+ self.session = None
+ self.connection.open()
+
+ ##
+ ## Create, configure, and open a QMFv2 agent session using the connection.
+ ##
+ self.session = AgentSession(self.connection, "{interval:30}")
+ self.session.setVendor('profitron.com')
+ self.session.setProduct('blastinator')
+ self.session.setAttribute('attr1', 1000)
+ self.session.open()
+
+ ##
+ ## Initialize the parent class.
+ ##
+ AgentHandler.__init__(self, self.session)
+
+
+ def shutdown(self):
+ """
+ Clean up the session and connection.
+ """
+ if self.session:
+ self.session.close()
+ self.connection.close()
+
+
+ def method(self, handle, methodName, args, subtypes, addr, userId):
+ """
+ Handle incoming method calls.
+ """
+ if addr == self.controlAddr:
+ self.control.methodCount += 1
+
+ try:
+ if methodName == "stop":
+ self.session.methodSuccess(handle)
+ self.cancel()
+
+ elif methodName == "echo":
+ handle.addReturnArgument("sequence", args["sequence"])
+ handle.addReturnArgument("map", args["map"])
+ self.session.methodSuccess(handle)
+
+ elif methodName == "event":
+ ev = Data(self.sch_event)
+ ev.text = args['text']
+ self.session.raiseEvent(ev, args['severity'])
+ self.session.methodSuccess(handle)
+
+ elif methodName == "fail":
+ if args['useString']:
+ self.session.raiseException(handle, args['stringVal'])
+ else:
+ ex = Data(self.sch_exception)
+ ex.whatHappened = "It Failed"
+ ex.howBad = 75
+ ex.details = args['details']
+ self.session.raiseException(handle, ex)
+
+ elif methodName == "create_child":
+ name = args['name']
+ child = Data(self.sch_child)
+ child.name = name
+ addr = self.session.addData(child, name)
+ handle.addReturnArgument("childAddr", addr.asMap())
+ self.session.methodSuccess(handle)
+ except BaseException, e:
+ self.session.raiseException(handle, "%r" % e)
+
+
+ def setupSchema(self):
+ """
+ Create and register the schema for this agent.
+ """
+ package = "com.profitron.bntor"
+
+ ##
+ ## Declare a schema for a structured exception that can be used in failed
+ ## method invocations.
+ ##
+ self.sch_exception = Schema(SCHEMA_TYPE_DATA, package, "exception")
+ self.sch_exception.addProperty(SchemaProperty("whatHappened", SCHEMA_DATA_STRING))
+ self.sch_exception.addProperty(SchemaProperty("howBad", SCHEMA_DATA_INT))
+ self.sch_exception.addProperty(SchemaProperty("details", SCHEMA_DATA_MAP))
+
+ ##
+ ## Declare a control object to test methods against.
+ ##
+ self.sch_control = Schema(SCHEMA_TYPE_DATA, package, "control")
+ self.sch_control.addProperty(SchemaProperty("state", SCHEMA_DATA_STRING))
+ self.sch_control.addProperty(SchemaProperty("methodCount", SCHEMA_DATA_INT))
+
+ stopMethod = SchemaMethod("stop", desc="Stop Agent")
+ stopMethod.addArgument(SchemaProperty("message", SCHEMA_DATA_STRING, direction=DIR_IN))
+ self.sch_control.addMethod(stopMethod)
+
+ echoMethod = SchemaMethod("echo", desc="Echo Arguments")
+ echoMethod.addArgument(SchemaProperty("sequence", SCHEMA_DATA_INT, direction=DIR_IN_OUT))
+ echoMethod.addArgument(SchemaProperty("map", SCHEMA_DATA_MAP, direction=DIR_IN_OUT))
+ self.sch_control.addMethod(echoMethod)
+
+ eventMethod = SchemaMethod("event", desc="Raise an Event")
+ eventMethod.addArgument(SchemaProperty("text", SCHEMA_DATA_STRING, direction=DIR_IN))
+ eventMethod.addArgument(SchemaProperty("severity", SCHEMA_DATA_INT, direction=DIR_IN))
+ self.sch_control.addMethod(eventMethod)
+
+ failMethod = SchemaMethod("fail", desc="Expected to Fail")
+ failMethod.addArgument(SchemaProperty("useString", SCHEMA_DATA_BOOL, direction=DIR_IN))
+ failMethod.addArgument(SchemaProperty("stringVal", SCHEMA_DATA_STRING, direction=DIR_IN))
+ failMethod.addArgument(SchemaProperty("details", SCHEMA_DATA_MAP, direction=DIR_IN))
+ self.sch_control.addMethod(failMethod)
+
+ createMethod = SchemaMethod("create_child", desc="Create Child Object")
+ createMethod.addArgument(SchemaProperty("name", SCHEMA_DATA_STRING, direction=DIR_IN))
+ createMethod.addArgument(SchemaProperty("childAddr", SCHEMA_DATA_MAP, direction=DIR_OUT))
+ self.sch_control.addMethod(createMethod)
+
+ ##
+ ## Declare a child object
+ ##
+ self.sch_child = Schema(SCHEMA_TYPE_DATA, package, "child")
+ self.sch_child.addProperty(SchemaProperty("name", SCHEMA_DATA_STRING))
+
+ ##
+ ## Declare the event class
+ ##
+ self.sch_event = Schema(SCHEMA_TYPE_EVENT, package, "event")
+ self.sch_event.addProperty(SchemaProperty("text", SCHEMA_DATA_STRING))
+
+ ##
+ ## Register our schemata with the agent session.
+ ##
+ self.session.registerSchema(self.sch_exception)
+ self.session.registerSchema(self.sch_control)
+ self.session.registerSchema(self.sch_child)
+ self.session.registerSchema(self.sch_event)
+
+
+ def populateData(self):
+ """
+ Create a control object and give it to the agent session to manage.
+ """
+ self.control = Data(self.sch_control)
+ self.control.state = "OPERATIONAL"
+ self.control.methodCount = 0
+ self.controlAddr = self.session.addData(self.control, "singleton")
+
+
+try:
+ agent = ExampleAgent("localhost")
+ agent.setupSchema()
+ agent.populateData()
+ agent.run() # Use agent.start() to launch the agent in a separate thread
+ agent.shutdown()
+except Exception, e:
+ print "Exception Caught:", e
+
+
diff --git a/qpid/cpp/bindings/qmf2/examples/python/find_agents.py b/qpid/cpp/bindings/qmf2/examples/python/find_agents.py
new file mode 100644
index 0000000000..5fd71b3f1c
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/python/find_agents.py
@@ -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.
+#
+
+import cqpid
+import qmf2
+
+class FindAgents(qmf2.ConsoleHandler):
+
+ def __init__(self, session):
+ qmf2.ConsoleHandler.__init__(self, session)
+
+ def agentAdded(self, agent):
+ print "Agent Added: %r" % agent
+
+ def agentDeleted(self, agent, reason):
+ print "Agent Deleted: %r reason: %s" % (agent, reason)
+
+ def agentRestarted(self, agent):
+ print "Agent Restarted: %r" % agent
+
+ def agentSchemaUpdated(self, agent):
+ print "Agent Schema Updated: %r" % agent
+
+ def eventRaised(self, agent, data, timestamp, severity):
+ print "Event: data=%r time=%d sev=%d" % (data.getProperties(), timestamp, severity)
+
+
+
+url = "localhost"
+options = ""
+
+connection = cqpid.Connection(url, options)
+connection.open()
+
+session = qmf2.ConsoleSession(connection)
+session.open()
+session.setAgentFilter("[]")
+
+main = FindAgents(session)
+main.run()
+
diff --git a/qpid/cpp/bindings/qmf2/examples/ruby/agent_external.rb b/qpid/cpp/bindings/qmf2/examples/ruby/agent_external.rb
new file mode 100644
index 0000000000..75171931ed
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/ruby/agent_external.rb
@@ -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.
+#
+
+require 'cqpid'
+require 'qmf2'
+
+class MyAgent < Qmf2::AgentHandler
+
+ def initialize(session, data)
+ super(session)
+ @data = data
+ end
+
+ def authorize_query(query, user_id)
+ puts "Authorizing #{user_id}"
+ return true
+ end
+
+ def get_query(context, query, user_id)
+ puts "Get Query"
+ context.response(@data)
+ context.complete
+ end
+
+ def method_call(context, method_name, data_addr, args, user_id)
+ puts "Method: #{method_name}"
+ context._success
+ end
+
+end
+
+
+class Program
+
+ def initialize(url)
+ @url = url
+ @sess_options = "{allow-queries:False, external:True}"
+ end
+
+ def setup_schema(agent)
+ @cls_control = Qmf2::Schema.new(Qmf2::SCHEMA_TYPE_DATA, "org.package", "control")
+ @cls_control.add_property(Qmf2::SchemaProperty.new("state", Qmf2::SCHEMA_DATA_STRING))
+ agent.register_schema(@cls_control)
+ end
+
+ def run
+ connection = Cqpid::Connection.new(@url)
+ connection.open
+
+ session = Qmf2::AgentSession.new(connection, @sess_options)
+ session.set_vendor("package.org")
+ session.set_product("external_agent")
+ setup_schema(session)
+ session.open
+
+ @control = Qmf2::Data.new(@cls_control)
+ @control.state = "OPERATIONAL-EXTERNAL"
+ @control.set_addr(Qmf2::DataAddr.new("singleton"))
+
+ main = MyAgent.new(session, @control)
+ main.run
+ end
+end
+
+prog = Program.new("localhost")
+prog.run
+
+
diff --git a/qpid/cpp/bindings/qmf2/examples/ruby/agent_internal.rb b/qpid/cpp/bindings/qmf2/examples/ruby/agent_internal.rb
new file mode 100644
index 0000000000..fc49a885f7
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/ruby/agent_internal.rb
@@ -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.
+#
+
+require 'cqpid'
+require 'qmf2'
+
+class MyAgent < Qmf2::AgentHandler
+
+ def initialize(session)
+ super(session)
+ end
+
+ def authorize_query(query, user_id)
+ puts "Authorizing #{user_id}"
+ return true
+ end
+
+ def method_call(context, method_name, data_addr, args, user_id)
+ puts "Method: #{method_name}"
+ context._success
+ end
+
+end
+
+
+class Program
+
+ def initialize(url)
+ @url = url
+ @sess_options = "{allow-queries:False}"
+ end
+
+ def setup_schema(agent)
+ @cls_control = Qmf2::Schema.new(Qmf2::SCHEMA_TYPE_DATA, "org.package", "control")
+ @cls_control.add_property(Qmf2::SchemaProperty.new("state", Qmf2::SCHEMA_DATA_STRING))
+ agent.register_schema(@cls_control)
+ end
+
+ def run
+ connection = Cqpid::Connection.new(@url)
+ connection.open
+
+ session = Qmf2::AgentSession.new(connection, @sess_options)
+ session.set_vendor("package.org")
+ session.set_product("internal_agent")
+ setup_schema(session)
+ session.open
+
+ control = Qmf2::Data.new(@cls_control)
+ control.state = "OPERATIONAL"
+ session.add_data(control)
+
+ main = MyAgent.new(session)
+ main.run
+ end
+end
+
+prog = Program.new("localhost")
+prog.run
+
+
diff --git a/qpid/cpp/bindings/qmf2/examples/ruby/find_agents.rb b/qpid/cpp/bindings/qmf2/examples/ruby/find_agents.rb
new file mode 100644
index 0000000000..41de7e5abe
--- /dev/null
+++ b/qpid/cpp/bindings/qmf2/examples/ruby/find_agents.rb
@@ -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.
+#
+
+require 'cqpid'
+require 'qmf2'
+
+class FindAgents < Qmf2::ConsoleHandler
+
+ def initialize(session)
+ super(session)
+ end
+
+ def agent_added(agent)
+ puts "Agent Added: #{agent.name}"
+ end
+
+ def agent_deleted(agent, reason)
+ puts "Agent Deleted: #{agent.to_s} reason: #{reason}"
+ end
+
+ def agent_restarted(agent)
+ puts "Agent Restarted: #{agent.to_s} epoch: #{agent.epoch}"
+ end
+
+ def agent_schema_updated(agent)
+ puts "Agent with new Schemata: #{agent.to_s}"
+ end
+
+ def event_raised(agent, data, timestamp, severity)
+ puts "Event Raised time=#{timestamp} sev=#{severity} data=#{data.properties}"
+ end
+end
+
+
+url = "localhost"
+options = ""
+
+connection = Cqpid::Connection.new(url, options)
+connection.open
+
+session = Qmf2::ConsoleSession.new(connection)
+session.open
+session.set_agent_filter("[]")
+
+main = FindAgents.new(session)
+main.run
+