summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp/bindings/qmf2/examples/cpp/Makefile.am7
-rw-r--r--cpp/bindings/qmf2/examples/cpp/list_agents.cpp67
-rwxr-xr-xcpp/bindings/qmf2/examples/python/agent.py18
-rw-r--r--cpp/src/qmf/AgentSession.cpp2
-rw-r--r--cpp/src/qmf/ConsoleSession.cpp17
5 files changed, 102 insertions, 9 deletions
diff --git a/cpp/bindings/qmf2/examples/cpp/Makefile.am b/cpp/bindings/qmf2/examples/cpp/Makefile.am
index 2244ddab3e..9c3bd615d6 100644
--- a/cpp/bindings/qmf2/examples/cpp/Makefile.am
+++ b/cpp/bindings/qmf2/examples/cpp/Makefile.am
@@ -21,6 +21,11 @@ INCLUDE = -I$(top_srcdir)/include
AM_CPPFLAGS = $(INCLUDE)
-noinst_PROGRAMS=agent
+noinst_PROGRAMS=agent list_agents
+
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
+
diff --git a/cpp/bindings/qmf2/examples/cpp/list_agents.cpp b/cpp/bindings/qmf2/examples/cpp/list_agents.cpp
new file mode 100644
index 0000000000..f94ad9ed45
--- /dev/null
+++ b/cpp/bindings/qmf2/examples/cpp/list_agents.cpp
@@ -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 <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();
+
+ while (true) {
+ ConsoleEvent event;
+ if (session.nextEvent(event)) {
+ if (event.getType() == CONSOLE_AGENT_ADD)
+ cout << "Agent Added: " << event.getAgent().getName() << 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/cpp/bindings/qmf2/examples/python/agent.py b/cpp/bindings/qmf2/examples/python/agent.py
index a915ed59b1..d354106042 100755
--- a/cpp/bindings/qmf2/examples/python/agent.py
+++ b/cpp/bindings/qmf2/examples/python/agent.py
@@ -35,12 +35,14 @@ class ExampleAgent(AgentHandler):
## Create and open a messaging connection to a broker.
##
self.connection = cqpid.Connection(url)
+ 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.setDomain("test")
self.session.setVendor('profitron.com')
self.session.setProduct('blastinator')
self.session.setAttribute('attr1', 1000)
@@ -56,7 +58,8 @@ class ExampleAgent(AgentHandler):
"""
Clean up the session and connection.
"""
- self.session.close()
+ if self.session:
+ self.session.close()
self.connection.close()
@@ -141,10 +144,13 @@ class ExampleAgent(AgentHandler):
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
-agent = ExampleAgent("localhost")
-agent.setupSchema()
-agent.populateData()
-agent.run() # Use agent.start() to launch the agent in a separate thread
-agent.shutdown()
diff --git a/cpp/src/qmf/AgentSession.cpp b/cpp/src/qmf/AgentSession.cpp
index 47e40ed24a..20beda4851 100644
--- a/cpp/src/qmf/AgentSession.cpp
+++ b/cpp/src/qmf/AgentSession.cpp
@@ -175,7 +175,7 @@ AgentSessionImpl::AgentSessionImpl(Connection& c, const string& options) :
schemaUpdateTime(uint64_t(qpid::sys::Duration(qpid::sys::EPOCH, qpid::sys::now())))
{
//
- // Set Capability Level to 1
+ // Set Agent Capability Level
//
attributes["qmf.agent_capability"] = AGENT_CAPABILITY_0_8;
diff --git a/cpp/src/qmf/ConsoleSession.cpp b/cpp/src/qmf/ConsoleSession.cpp
index 6eb9b94bf8..dc2bbe34ee 100644
--- a/cpp/src/qmf/ConsoleSession.cpp
+++ b/cpp/src/qmf/ConsoleSession.cpp
@@ -110,9 +110,17 @@ void ConsoleSessionImpl::setAgentFilter(const string& predicate)
enqueueEventLH(eventImpl.release());
}
- if (!connectedBrokerInAgentList && agentQuery.matchesPredicate(connectedBrokerAgent.getAttributes())) {
+ if (!connectedBrokerInAgentList && connectedBrokerAgent.isValid() &&
+ agentQuery.matchesPredicate(connectedBrokerAgent.getAttributes())) {
agents[connectedBrokerAgent.getName()] = connectedBrokerAgent;
connectedBrokerInAgentList = true;
+
+ //
+ // Enqueue a notification of the new agent.
+ //
+ auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_ADD));
+ eventImpl->setAgent(connectedBrokerAgent);
+ enqueueEventLH(ConsoleEvent(eventImpl.release()));
}
}
@@ -393,6 +401,13 @@ void ConsoleSessionImpl::handleAgentUpdate(const string& agentName, const Varian
if (!agentQuery || agentQuery.matchesPredicate(attrs)) {
connectedBrokerInAgentList = true;
agents[agentName] = agent;
+
+ //
+ // Enqueue a notification of the new agent.
+ //
+ auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_ADD));
+ eventImpl->setAgent(agent);
+ enqueueEventLH(ConsoleEvent(eventImpl.release()));
}
return;
}