You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2007/04/26 18:01:05 UTC
svn commit: r532787 - in /incubator/qpid/branches/M2/cpp: gen/ lib/
lib/broker/ lib/common/ src/ tests/
Author: aconway
Date: Thu Apr 26 09:01:04 2007
New Revision: 532787
URL: http://svn.apache.org/viewvc?view=rev&rev=532787
Log:
Merged revisions 532430 by hand from
https://svn.apache.org/repos/asf/incubator/qpid/branches/trunk/qpid/cpp
------------------------------------------------------------------------
r532430 | aconway | 2007-04-25 14:06:14 -0400 (Wed, 25 Apr 2007) | 10 lines
* qpid/CommonOptions.h:
- Convenience classs/functions to use boost::program_options.
- CommonOptions class for options common to client/broker.
* qpid/broker/Broker.h:
- Replaced broker::Configuration with class Broker::Options,
derived from CommonOptions.
* qpidd.cpp: Updated options handling.
* qpid/Exception.h: Added strError function to get std::string from errno.
------------------------------------------------------------------------
Added:
incubator/qpid/branches/M2/cpp/lib/CommonOptions.cpp
- copied unchanged from r532430, incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp
incubator/qpid/branches/M2/cpp/lib/CommonOptions.h
- copied unchanged from r532430, incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h
incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.cpp
- copied unchanged from r532430, incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp
incubator/qpid/branches/M2/cpp/lib/common/CommonOptions.h
- copied unchanged from r532430, incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h
Removed:
incubator/qpid/branches/M2/cpp/lib/broker/Configuration.cpp
incubator/qpid/branches/M2/cpp/lib/broker/Configuration.h
incubator/qpid/branches/M2/cpp/tests/ConfigurationTest.cpp
Modified:
incubator/qpid/branches/M2/cpp/gen/ (props changed)
incubator/qpid/branches/M2/cpp/lib/broker/Broker.cpp
incubator/qpid/branches/M2/cpp/lib/broker/Broker.h
incubator/qpid/branches/M2/cpp/lib/broker/Makefile.am
incubator/qpid/branches/M2/cpp/lib/common/Exception.cpp
incubator/qpid/branches/M2/cpp/lib/common/Exception.h
incubator/qpid/branches/M2/cpp/lib/common/Makefile.am
incubator/qpid/branches/M2/cpp/src/Makefile.am
incubator/qpid/branches/M2/cpp/src/qpidd.cpp
incubator/qpid/branches/M2/cpp/tests/Makefile.am
Propchange: incubator/qpid/branches/M2/cpp/gen/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Apr 26 09:01:04 2007
@@ -2,3 +2,5 @@
*.cpp
timestamp
*.mk
+Makefile.in
+Makefile
Modified: incubator/qpid/branches/M2/cpp/lib/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/lib/broker/Broker.cpp?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/broker/Broker.cpp (original)
+++ incubator/qpid/branches/M2/cpp/lib/broker/Broker.cpp Thu Apr 26 09:01:04 2007
@@ -22,38 +22,63 @@
#include <memory>
#include <Broker.h>
-
using namespace qpid::broker;
using namespace qpid::sys;
-Broker::Broker(const Configuration& config) :
- acceptor(Acceptor::create(config.getPort(),
- config.getConnectionBacklog(),
- config.getWorkerThreads(),
- config.isTrace())),
- factory(config.getStore())
+Broker::Options::Options() :
+ workerThreads(5),
+ maxConnections(500),
+ connectionBacklog(10),
+ store(),
+ stagingThreshold(5000000)
+{}
+
+void Broker::Options::addTo(po::options_description& desc)
+{
+ using namespace po;
+ CommonOptions::addTo(desc);
+ desc.add_options()
+ ("worker-threads", optValue(workerThreads, "N"),
+ "Broker thread pool size")
+ ("max-connections", optValue(maxConnections, "N"),
+ "Maximum allowed connections")
+ ("connection-backlog", optValue(connectionBacklog, "N"),
+ "Connection backlog limit for server socket.")
+ ("staging-threshold", optValue(stagingThreshold, "N"),
+ "Messages over N bytes are staged to disk.")
+ ("store", optValue(store,"LIBNAME"),
+ "Name of message store shared library.");
+}
+
+
+Broker::Broker(const Options& config) :
+ acceptor(Acceptor::create(config.port,
+ config.connectionBacklog,
+ config.workerThreads,
+ config.trace)),
+ factory(config.store)
{ }
Broker::shared_ptr Broker::create(int16_t port)
{
- Configuration config;
- config.setPort(port);
+ Options config;
+ config.port=port;
return create(config);
}
-Broker::shared_ptr Broker::create(const Configuration& config) {
+Broker::shared_ptr Broker::create(const Options& config) {
return Broker::shared_ptr(new Broker(config));
}
-
+
void Broker::run() {
acceptor->run(&factory);
}
void Broker::shutdown() {
- acceptor->shutdown();
+ if (acceptor)
+ acceptor->shutdown();
}
Broker::~Broker() { }
-const int16_t Broker::DEFAULT_PORT(5672);
Modified: incubator/qpid/branches/M2/cpp/lib/broker/Broker.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/lib/broker/Broker.h?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/broker/Broker.h (original)
+++ incubator/qpid/branches/M2/cpp/lib/broker/Broker.h Thu Apr 26 09:01:04 2007
@@ -22,7 +22,7 @@
*
*/
-#include <Configuration.h>
+#include <CommonOptions.h>
#include <SessionHandlerFactoryImpl.h>
#include <sys/Runnable.h>
#include <sys/Acceptor.h>
@@ -37,7 +37,15 @@
public qpid::SharedObject<Broker>
{
public:
- static const int16_t DEFAULT_PORT;
+ struct Options : public CommonOptions {
+ Options();
+ void addTo(po::options_description&);
+ int workerThreads;
+ int maxConnections;
+ int connectionBacklog;
+ std::string store;
+ long stagingThreshold;
+ };
virtual ~Broker();
@@ -45,12 +53,12 @@
* Create a broker.
* @param port Port to listen on or 0 to pick a port dynamically.
*/
- static shared_ptr create(int16_t port = DEFAULT_PORT);
+ static shared_ptr create(int16_t port = Options::DEFAULT_PORT);
/**
* Create a broker using a Configuration.
*/
- static shared_ptr create(const Configuration& config);
+ static shared_ptr create(const Options& config);
/**
* Return listening port. If called before bind this is
@@ -70,7 +78,8 @@
virtual void shutdown();
private:
- Broker(const Configuration& config);
+ Broker(const Options& config);
+ Options config;
qpid::sys::Acceptor::shared_ptr acceptor;
SessionHandlerFactoryImpl factory;
};
Modified: incubator/qpid/branches/M2/cpp/lib/broker/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/lib/broker/Makefile.am?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/broker/Makefile.am (original)
+++ incubator/qpid/branches/M2/cpp/lib/broker/Makefile.am Thu Apr 26 09:01:04 2007
@@ -24,8 +24,6 @@
BrokerMessage.h \
BrokerQueue.cpp \
BrokerQueue.h \
- Configuration.cpp \
- Configuration.h \
ConnectionToken.h \
Consumer.h \
Content.h \
Modified: incubator/qpid/branches/M2/cpp/lib/common/Exception.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/lib/common/Exception.cpp?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/common/Exception.cpp (original)
+++ incubator/qpid/branches/M2/cpp/lib/common/Exception.cpp Thu Apr 26 09:01:04 2007
@@ -19,10 +19,16 @@
*
*/
-#include <Exception.h>
+#include "Exception.h"
+#include <cerrno>
namespace qpid {
+std::string strError(int err) {
+ char buf[512];
+ return std::string(strerror_r(err, buf, sizeof(buf)));
+}
+
Exception::Exception() throw() {}
Exception::Exception(const std::string& str) throw() : whatStr(str) {}
Modified: incubator/qpid/branches/M2/cpp/lib/common/Exception.h
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/lib/common/Exception.h?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/common/Exception.h (original)
+++ incubator/qpid/branches/M2/cpp/lib/common/Exception.h Thu Apr 26 09:01:04 2007
@@ -29,6 +29,10 @@
namespace qpid
{
+
+/** Get the error message for error number err. */
+std::string strError(int err);
+
/**
* Exception base class for all Qpid exceptions.
*/
Modified: incubator/qpid/branches/M2/cpp/lib/common/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/lib/common/Makefile.am?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/common/Makefile.am (original)
+++ incubator/qpid/branches/M2/cpp/lib/common/Makefile.am Thu Apr 26 09:01:04 2007
@@ -44,13 +44,14 @@
gen = $(srcdir)/../../gen
lib_LTLIBRARIES = libqpidcommon.la
-libqpidcommon_la_LIBADD = \
- $(APR_LIBS) \
- $(LIB_DLOPEN) \
- $(LIB_CLOCK_GETTIME)
+libqpidcommon_la_LIBADD = \
+ $(APR_LIBS) \
+ $(LIB_DLOPEN) \
+ $(LIB_CLOCK_GETTIME) \
+ -lboost_program_options
-libqpidcommon_la_LDFLAGS = \
- -version-info \
+libqpidcommon_la_LDFLAGS = \
+ -version-info \
$(LIBTOOL_VERSION_INFO_ARG)
libqpidcommon_la_SOURCES = \
@@ -72,12 +73,13 @@
$(framing)/ProtocolVersionException.cpp \
$(framing)/Value.cpp \
$(gen)/AMQP_ClientProxy.cpp \
- $(gen)/AMQP_HighestVersion.h \
+ $(gen)/AMQP_HighestVersion.h \
$(gen)/AMQP_MethodVersionMap.cpp \
$(gen)/AMQP_ServerProxy.cpp \
Exception.cpp \
ExceptionHolder.cpp \
QpidError.cpp \
+ CommonOptions.cpp \
sys/Runnable.cpp \
sys/Time.cpp
@@ -109,6 +111,7 @@
ExceptionHolder.h \
QpidError.h \
SharedObject.h \
+ CommonOptions.cpp \
sys/Acceptor.h \
sys/AtomicCount.h \
sys/Module.h \
Modified: incubator/qpid/branches/M2/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/src/Makefile.am?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/src/Makefile.am (original)
+++ incubator/qpid/branches/M2/cpp/src/Makefile.am Thu Apr 26 09:01:04 2007
@@ -1,14 +1,16 @@
AM_CXXFLAGS = $(WARNING_CFLAGS)
-INCLUDES = \
- -I$(top_srcdir)/gen \
- -I$(top_srcdir)/lib/broker \
- -I$(top_srcdir)/lib/common \
- -I$(top_srcdir)/lib/common/framing \
+
+INCLUDES = \
+ -I$(top_srcdir)/gen \
+ -I$(top_srcdir)/lib/broker \
+ -I$(top_srcdir)/lib/common \
+ -I$(top_srcdir)/lib/common/framing \
-I$(top_srcdir)/lib/common/sys
-LDADD = \
- ../lib/broker/libqpidbroker.la \
- ../lib/common/libqpidcommon.la
+LDADD = \
+ ../lib/broker/libqpidbroker.la \
+ ../lib/common/libqpidcommon.la \
+ -lboost_program_options
sbin_PROGRAMS = qpidd
qpidd_SOURCES = qpidd.cpp
Modified: incubator/qpid/branches/M2/cpp/src/qpidd.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/src/qpidd.cpp?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/src/qpidd.cpp (original)
+++ incubator/qpid/branches/M2/cpp/src/qpidd.cpp Thu Apr 26 09:01:04 2007
@@ -19,62 +19,92 @@
*
*/
#include <Broker.h>
-#include <Configuration.h>
#include <signal.h>
#include <iostream>
#include <memory>
-#include <cerrno>
#include <config.h>
#include <unistd.h>
-static char const* programName = "qpidd";
+using namespace qpid;
using namespace qpid::broker;
using namespace qpid::sys;
+using namespace std;
-Broker::shared_ptr broker;
+/** Command line options */
+struct QpiddOptions : public Broker::Options
+{
+ bool help;
+ bool version;
+ bool daemon;
+ po::options_description desc;
+
+ QpiddOptions() :
+ help(false), version(false), daemon(false), desc("Options")
+ {
+ using namespace po;
+ desc.add_options()
+ ("daemon,d", optValue(daemon), "Run as a daemon");
+ Broker::Options::addTo(desc);
+ desc.add_options()
+ ("help,h", optValue(help), "Print help message")
+ ("version,v", optValue(version), "Print version information");
+ }
+
+ void parse(int argc, char* argv[]) {
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ po::notify(vm);
+ };
+
+ void usage(std::ostream& out) const {
+ out << "Usage: qpidd [OPTIONS]" << endl
+ << "Start the Qpid AMQP broker." << endl << endl
+ << desc << endl;
+ };
+};
+
+std::ostream& operator<<(std::ostream& out, const QpiddOptions& config) {
+ config.usage(out); return out;
+}
+
+Broker::shared_ptr brokerPtr;
void handle_signal(int /*signal*/){
- std::cerr << "Shutting down..." << std::endl;
- broker->shutdown();
+ if (brokerPtr) {
+ cerr << "Shutting down..." << endl;
+ brokerPtr->shutdown();
+ }
}
-int main(int argc, char** argv)
+int main(int argc, char* argv[])
{
- Configuration config;
+ QpiddOptions config;
try {
- config.parse(programName, argc, argv);
-
- if(config.isHelp()){
- config.usage();
- }else if(config.isVersion()){
- std::cout << programName << " (" << PACKAGE_NAME << ") version "
- << PACKAGE_VERSION << std::endl;
- }else{
- broker = Broker::create(config);
+ config.parse(argc, argv);
+ if(config.help) {
+ config.usage(cout);
+ }
+ else if (config.version) {
+ cout << "qpidd (" << PACKAGE_NAME << ") version "
+ << PACKAGE_VERSION << endl;
+ }
+ else {
+ brokerPtr=Broker::create(config);
signal(SIGINT, handle_signal);
- if (config.isDaemon()) {
- // Detach & run as daemon.
- int chdirRoot = 0; // 0 means chdir to root.
- int closeStd = 0; // 0 means close stdin/out/err
- if (daemon(chdirRoot, closeStd) < 0) {
- char buf[512];
-
- std::cerr << "Failed to detach as daemon: "
- << strerror_r(errno, buf, sizeof(buf))
- << std::endl;;
- return 1;
- }
+ if (config.daemon) {
+ if (daemon(0, 0) < 0) // daemon(nochdir, noclose)
+ throw QPID_ERROR(
+ INTERNAL_ERROR,
+ "Failed to detach as daemon: "+ strError(errno));
}
- broker->run();
+ brokerPtr->run();
}
return 0;
}
- catch (const Configuration::BadOptionException& e) {
- std::cerr << e.what() << std::endl << std::endl;
- config.usage();
- } catch(const std::exception& e) {
- std::cerr << e.what() << std::endl;
+ catch(const exception& e) {
+ cerr << "Error: " << e.what() << endl
+ << "Type 'qpidd --help' for usage." << endl;
}
return 1;
}
Modified: incubator/qpid/branches/M2/cpp/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/cpp/tests/Makefile.am?view=diff&rev=532787&r1=532786&r2=532787
==============================================================================
--- incubator/qpid/branches/M2/cpp/tests/Makefile.am (original)
+++ incubator/qpid/branches/M2/cpp/tests/Makefile.am Thu Apr 26 09:01:04 2007
@@ -29,7 +29,6 @@
broker_tests = \
AccumulatedAckTest \
ChannelTest \
- ConfigurationTest \
ExchangeTest \
HeadersExchangeTest \
InMemoryContentTest \
@@ -66,6 +65,9 @@
noinst_PROGRAMS = $(client_tests)
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+
TESTS_ENVIRONMENT = \
VALGRIND=$(VALGRIND) \
abs_builddir='$(abs_builddir)' \
@@ -80,7 +82,6 @@
include gen.mk
-abs_builddir = @abs_builddir@
extra_libs = $(CPPUNIT_LIBS)
lib_client = $(abs_builddir)/../lib/client/libqpidclient.la
lib_common = $(abs_builddir)/../lib/common/libqpidcommon.la