summaryrefslogtreecommitdiff
path: root/cpp/examples/failover
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-10-10 21:19:46 +0000
committerAlan Conway <aconway@apache.org>2008-10-10 21:19:46 +0000
commit91f45702afcf3b675fe80dbcf3a452daa61469e4 (patch)
treed3a59d07dd3b4c88fa6a16d23b168dc6de20622b /cpp/examples/failover
parent792e46cad9a978c0d297c245772e57c0759cec31 (diff)
downloadqpid-python-91f45702afcf3b675fe80dbcf3a452daa61469e4.tar.gz
Failover client and example fixes & tidy up.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@703575 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/examples/failover')
-rw-r--r--cpp/examples/failover/direct_producer.cpp136
-rw-r--r--cpp/examples/failover/listener.cpp37
2 files changed, 64 insertions, 109 deletions
diff --git a/cpp/examples/failover/direct_producer.cpp b/cpp/examples/failover/direct_producer.cpp
index d8e74cdc41..4f91c9c4d4 100644
--- a/cpp/examples/failover/direct_producer.cpp
+++ b/cpp/examples/failover/direct_producer.cpp
@@ -1,14 +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.
+ *
+ */
+
#include <qpid/client/FailoverConnection.h>
#include <qpid/client/Session.h>
#include <qpid/client/AsyncSession.h>
#include <qpid/client/Message.h>
-#include <unistd.h>
-#include <cstdlib>
#include <iostream>
-#include <fstream>
-
#include <sstream>
using namespace qpid::client;
@@ -16,102 +33,46 @@ using namespace qpid::framing;
using namespace std;
-
-
-
int
main ( int argc, char ** argv)
{
- try {
- struct timeval broker_killed_time = {0,0};
- struct timeval failover_complete_time = {0,0};
- struct timeval duration = {0,0};
-
-
- if ( argc < 3 )
- {
- std::cerr << "Usage: ./direct_producer host cluster_port_file_name\n";
- std::cerr << "i.e. for host: 127.0.0.1\n";
- exit(1);
- }
-
- char const * host = argv[1];
- int port = atoi(argv[2]);
- char const * broker_to_kill = 0;
-
- if ( argc > 3 )
- {
- broker_to_kill = argv[3];
- std::cerr << "main: Broker marked for death is process ID "
- << broker_to_kill
- << endl;
- }
- else
- {
- std::cerr << "PRODUCER main: there is no broker to kill.\n";
- }
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
+ int count = argc>3 ? atoi(argv[3]) : 30;
+ try {
FailoverConnection connection;
FailoverSession * session;
Message message;
string program_name = "PRODUCER";
-
- connection.failoverCompleteTime = & failover_complete_time;
- connection.name = program_name;
connection.open ( host, port );
-
session = connection.newSession();
- session->name = program_name;
-
- int send_this_many = 30,
- messages_sent = 0;
-
- while ( messages_sent < send_this_many )
- {
- if ( (messages_sent == 13) && broker_to_kill )
- {
- char command[1000];
- std::cerr << program_name << " killing broker " << broker_to_kill << ".\n";
- sprintf(command, "kill -9 %s", broker_to_kill);
- system ( command );
- gettimeofday ( & broker_killed_time, 0 );
- }
-
+ int sent = 0;
+ while ( sent < count ) {
message.getDeliveryProperties().setRoutingKey("routing_key");
-
- std::cerr << "sending message "
- << messages_sent
+ std::cout << "sending message "
+ << sent
<< " of "
- << send_this_many
+ << count
<< ".\n";
-
stringstream message_data;
- message_data << messages_sent;
+ message_data << sent;
message.setData(message_data.str());
- try
- {
- /* MICK FIXME
- session.messageTransfer ( arg::content=message,
- arg::destination="amq.direct"
- ); */
- session->messageTransfer ( "amq.direct",
- 1,
- 0,
- message
- );
- }
- catch ( const std::exception& error)
- {
- cerr << program_name << " exception: " << error.what() << endl;
- }
-
+ /* MICK FIXME
+ session.messageTransfer ( arg::content=message,
+ arg::destination="amq.direct"
+ ); */
+ session->messageTransfer ( "amq.direct",
+ 1,
+ 0,
+ message
+ );
sleep ( 1 );
- ++ messages_sent;
+ ++ sent;
}
-
message.setData ( "That's all, folks!" );
/* MICK FIXME
@@ -127,22 +88,7 @@ main ( int argc, char ** argv)
session->sync();
connection.close();
-
- // This will be incorrect if you killed more than one...
- if ( broker_to_kill )
- {
- timersub ( & failover_complete_time,
- & broker_killed_time,
- & duration
- );
- fprintf ( stderr,
- "Failover time: %ld.%.6ld\n",
- duration.tv_sec,
- duration.tv_usec
- );
- }
return 0;
-
} catch(const std::exception& error) {
std::cout << error.what() << std::endl;
}
diff --git a/cpp/examples/failover/listener.cpp b/cpp/examples/failover/listener.cpp
index d5ade9b9e2..c4c7d096b3 100644
--- a/cpp/examples/failover/listener.cpp
+++ b/cpp/examples/failover/listener.cpp
@@ -1,11 +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.
+ *
+ */
#include <qpid/client/FailoverConnection.h>
#include <qpid/client/Session.h>
#include <qpid/client/Message.h>
#include <qpid/client/SubscriptionManager.h>
-#include <unistd.h>
-#include <cstdlib>
#include <iostream>
#include <fstream>
@@ -16,8 +34,6 @@ using namespace qpid::framing;
using namespace std;
-
-
struct Recorder
{
unsigned int max_messages;
@@ -211,19 +227,12 @@ Listener::parse_message ( const std::string & msg )
int
main ( int argc, char ** argv )
{
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
+
try {
string program_name = "LISTENER";
- if ( argc < 3 )
- {
- std::cerr << "Usage: ./listener host cluster_port_file_name\n";
- std::cerr << "i.e. for host: 127.0.0.1\n";
- exit(1);
- }
-
- char const * host = argv[1];
- int port = atoi(argv[2]);
-
FailoverConnection connection;
FailoverSession * session;
Recorder recorder;