You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/03/17 00:09:53 UTC
svn commit: r1082340 - in /activemq/activemq-cpp/trunk/activemq-cpp/src:
main/ main/activemq/core/ main/activemq/threads/ main/activemq/util/
main/decaf/util/ test/ test/activemq/threads/
Author: tabish
Date: Wed Mar 16 23:09:53 2011
New Revision: 1082340
URL: http://svn.apache.org/viewvc?rev=1082340&view=rev
Log:
Attempting to fix: https://issues.apache.org/jira/browse/AMQCPP-355
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.h (with props)
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.h
activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=1082340&r1=1082339&r2=1082340&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Wed Mar 16 23:09:53 2011
@@ -116,6 +116,8 @@ cc_sources = \
activemq/state/TransactionState.cpp \
activemq/threads/CompositeTaskRunner.cpp \
activemq/threads/DedicatedTaskRunner.cpp \
+ activemq/threads/Scheduler.cpp \
+ activemq/threads/SchedulerTimerTask.cpp \
activemq/transport/AbstractTransportFactory.cpp \
activemq/transport/IOTransport.cpp \
activemq/transport/TransportFilter.cpp \
@@ -150,6 +152,10 @@ cc_sources = \
activemq/util/PrimitiveMap.cpp \
activemq/util/PrimitiveValueConverter.cpp \
activemq/util/PrimitiveValueNode.cpp \
+ activemq/util/Service.cpp \
+ activemq/util/ServiceListener.cpp \
+ activemq/util/ServiceStopper.cpp \
+ activemq/util/ServiceSupport.cpp \
activemq/util/URISupport.cpp \
activemq/wireformat/WireFormatRegistry.cpp \
activemq/wireformat/openwire/OpenWireFormat.cpp \
@@ -603,6 +609,8 @@ h_sources = \
activemq/threads/CompositeTask.h \
activemq/threads/CompositeTaskRunner.h \
activemq/threads/DedicatedTaskRunner.h \
+ activemq/threads/Scheduler.h \
+ activemq/threads/SchedulerTimerTask.h \
activemq/threads/Task.h \
activemq/threads/TaskRunner.h \
activemq/transport/AbstractTransportFactory.h \
@@ -647,6 +655,10 @@ h_sources = \
activemq/util/PrimitiveMap.h \
activemq/util/PrimitiveValueConverter.h \
activemq/util/PrimitiveValueNode.h \
+ activemq/util/Service.h \
+ activemq/util/ServiceListener.h \
+ activemq/util/ServiceStopper.h \
+ activemq/util/ServiceSupport.h \
activemq/util/URISupport.h \
activemq/util/Usage.h \
activemq/wireformat/MarshalAware.h \
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp?rev=1082340&r1=1082339&r2=1082340&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp Wed Mar 16 23:09:53 2011
@@ -67,6 +67,7 @@ using namespace activemq::core;
using namespace activemq::core::policies;
using namespace activemq::commands;
using namespace activemq::exceptions;
+using namespace activemq::threads;
using namespace activemq::transport;
using namespace activemq::transport::failover;
using namespace decaf;
@@ -103,6 +104,7 @@ namespace core{
Pointer<decaf::util::Properties> properties;
Pointer<transport::Transport> transport;
Pointer<util::IdGenerator> clientIdGenerator;
+ Pointer<Scheduler> scheduler;
util::LongSequenceGenerator sessionIds;
util::LongSequenceGenerator tempDestinationIds;
@@ -149,6 +151,7 @@ namespace core{
ConnectionConfig() : properties(),
transport(),
clientIdGenerator(),
+ scheduler(),
sessionIds(),
tempDestinationIds(),
localTransactionIds(),
@@ -188,9 +191,12 @@ namespace core{
this->brokerInfoReceived.reset( new CountDownLatch(1) );
// Generate a connectionId
+ std::string uniqueId = CONNECTION_ID_GENERATOR.generateId();
decaf::lang::Pointer<ConnectionId> connectionId( new ConnectionId() );
- connectionId->setValue( CONNECTION_ID_GENERATOR.generateId() );
+ connectionId->setValue(uniqueId);
this->connectionInfo->setConnectionId( connectionId );
+ this->scheduler.reset(new Scheduler(std::string("ActiveMQConnection[")+uniqueId+"] Scheduler"));
+ this->scheduler->start();
}
void waitForBrokerInfo() {
@@ -409,6 +415,13 @@ void ActiveMQConnection::close() {
// passed on from the transport as it goes down.
this->closing.set( true );
+ if(this->config->scheduler != NULL) {
+ try {
+ this->config->scheduler->stop();
+ }
+ AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
+ }
+
// Get the complete list of active sessions.
std::auto_ptr< Iterator<ActiveMQSession*> > iter( this->config->activeSessions.iterator() );
@@ -1180,6 +1193,11 @@ transport::Transport& ActiveMQConnection
}
////////////////////////////////////////////////////////////////////////////////
+threads::Scheduler& ActiveMQConnection::getScheduler() const {
+ return *( this->config->scheduler );
+}
+
+////////////////////////////////////////////////////////////////////////////////
bool ActiveMQConnection::isMessagePrioritySupported() const {
return this->config->messagePrioritySupported;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h?rev=1082340&r1=1082339&r2=1082340&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.h Wed Mar 16 23:09:53 2011
@@ -29,6 +29,7 @@
#include <activemq/exceptions/ActiveMQException.h>
#include <activemq/transport/Transport.h>
#include <activemq/transport/TransportListener.h>
+#include <activemq/threads/Scheduler.h>
#include <decaf/util/Properties.h>
#include <decaf/util/concurrent/atomic/AtomicBoolean.h>
#include <decaf/util/concurrent/CopyOnWriteArrayList.h>
@@ -590,6 +591,13 @@ namespace core{
transport::Transport& getTransport() const;
/**
+ * Gets a reference to the Connection objects built in Scheduler instance.
+ *
+ * @return a reference to a Scheduler instance owned by this Connection.
+ */
+ threads::Scheduler& getScheduler() const;
+
+ /**
* Returns the Id of the Resource Manager that this client will use should
* it be entered into an XA Transaction.
*
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp?rev=1082340&r1=1082339&r2=1082340&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQSession.cpp Wed Mar 16 23:09:53 2011
@@ -50,6 +50,7 @@
#include <decaf/lang/Boolean.h>
#include <decaf/lang/Integer.h>
+#include <decaf/lang/Runnable.h>
#include <decaf/lang/Long.h>
#include <decaf/lang/Math.h>
#include <decaf/util/Queue.h>
@@ -71,6 +72,39 @@ using namespace decaf::lang::exceptions;
namespace {
/**
+ * Class used to clear a Consumer's dispatch queue asynchronously from the
+ * connection class's Scheduler instance.
+ */
+ class ClearConsumerTask : public Runnable {
+ private:
+
+ ActiveMQConsumer* consumer;
+
+ private:
+
+ ClearConsumerTask( const ClearConsumerTask& );
+ ClearConsumerTask& operator= ( const ClearConsumerTask& );
+
+ public:
+
+ ClearConsumerTask( ActiveMQConsumer* consumer ) : Runnable(), consumer(NULL) {
+
+ if( consumer == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Synchronization Created with NULL Consumer.");
+ }
+
+ this->consumer = consumer;
+ }
+
+ virtual ~ClearConsumerTask() {}
+
+ virtual void run() {
+ this->consumer->clearMessagesInProgress();
+ }
+ };
+
+ /**
* Class used to Hook a session that has been closed into the Transaction
* it is currently a part of. Once the Transaction has been Committed or
* Rolled back this Synchronization can finish the Close of the session.
@@ -397,8 +431,9 @@ void ActiveMQSession::clearMessagesInPro
std::vector< ActiveMQConsumer* >::iterator iter = consumers.begin();
for( ; iter != consumers.end(); ++iter ) {
(*iter)->inProgressClearRequired();
- // Todo - This should occur asynchronously.
- (*iter)->clearMessagesInProgress();
+
+ this->connection->getScheduler().executeAfterDelay(
+ new ClearConsumerTask(*iter), 0LL);
}
}
}
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.cpp?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.cpp Wed Mar 16 23:09:53 2011
@@ -0,0 +1,141 @@
+/*
+ * 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 "Scheduler.h"
+
+#include <activemq/exceptions/ActiveMQException.h>
+#include <activemq/threads/SchedulerTimerTask.h>
+#include <activemq/util/ServiceStopper.h>
+
+#include <decaf/lang/Pointer.h>
+#include <decaf/util/Timer.h>
+#include <decaf/lang/Runnable.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
+
+using namespace activemq;
+using namespace activemq::threads;
+using namespace activemq::util;
+using namespace activemq::exceptions;
+using namespace decaf;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+Scheduler::Scheduler(const std::string& name) : name(name), timer(NULL), tasks() {
+
+ if(name.empty()) {
+ throw IllegalArgumentException(__FILE__, __LINE__, "Scheduler name must not be empty.");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Scheduler::~Scheduler() {
+ try{
+
+ if(this->timer != NULL) {
+ this->timer->cancel();
+ }
+
+ this->tasks.clear();
+
+ delete this->timer;
+ }
+ AMQ_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Scheduler::executePeriodically(Runnable* task, long long period, bool ownsTask) {
+
+ if(!isStarted()) {
+ throw IllegalStateException(__FILE__, __LINE__, "Scheduler is not started.");
+ }
+
+ synchronized(&mutex) {
+ TimerTask* timerTask = new SchedulerTimerTask(task, ownsTask);
+ this->timer->scheduleAtFixedRate(timerTask, period, period);
+ this->tasks.put(task, timerTask);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Scheduler::schedualPeriodically(Runnable* task, long long period, bool ownsTask) {
+
+ if(!isStarted()) {
+ throw IllegalStateException(__FILE__, __LINE__, "Scheduler is not started.");
+ }
+
+ synchronized(&mutex) {
+ TimerTask* timerTask = new SchedulerTimerTask(task, ownsTask);
+ this->timer->schedule(timerTask, period, period);
+ this->tasks.put(task, timerTask);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Scheduler::cancel(Runnable* task) {
+
+ if(!isStarted()) {
+ throw IllegalStateException(__FILE__, __LINE__, "Scheduler is not started.");
+ }
+
+ synchronized(&mutex) {
+ TimerTask* ticket = this->tasks.remove(task);
+ if(ticket != NULL) {
+ ticket->cancel();
+ this->timer->purge();
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Scheduler::executeAfterDelay(Runnable* task, long long delay, bool ownsTask) {
+
+ if(!isStarted()) {
+ throw IllegalStateException(__FILE__, __LINE__, "Scheduler is not started.");
+ }
+
+ synchronized(&mutex) {
+ TimerTask* timerTask = new SchedulerTimerTask(task, ownsTask);
+ this->timer->schedule(timerTask, delay);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Scheduler::shutdown() {
+ if(this->timer != NULL) {
+ this->timer->cancel();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Scheduler::doStart() {
+ synchronized(&mutex) {
+ this->timer = new Timer(name);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Scheduler::doStop(ServiceStopper* stopper) {
+ synchronized(&mutex) {
+ if(this->timer != NULL) {
+ this->timer->cancel();
+ }
+ }
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.h?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.h Wed Mar 16 23:09:53 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_THREADS_SCHEDULER_H_
+#define _ACTIVEMQ_THREADS_SCHEDULER_H_
+
+#include <activemq/util/Config.h>
+#include <activemq/util/ServiceSupport.h>
+
+#include <decaf/lang/Runnable.h>
+#include <decaf/util/Timer.h>
+#include <decaf/util/StlMap.h>
+#include <decaf/util/concurrent/Mutex.h>
+
+#include <string>
+
+namespace activemq {
+namespace threads {
+
+ /**
+ * Scheduler class for use in executing Runnable Tasks either periodically or
+ * one time only with optional delay.
+ *
+ * @since 3.3.0
+ */
+ class AMQCPP_API Scheduler : public activemq::util::ServiceSupport {
+ private:
+
+ decaf::util::concurrent::Mutex mutex;
+ std::string name;
+ decaf::util::Timer* timer;
+ decaf::util::StlMap<decaf::lang::Runnable*, decaf::util::TimerTask*> tasks;
+
+ private:
+
+ Scheduler(const Scheduler&);
+ Scheduler& operator= (const Scheduler&);
+
+ public:
+
+ Scheduler(const std::string& name);
+
+ virtual ~Scheduler();
+
+ public:
+
+ void executePeriodically(decaf::lang::Runnable* task, long long period, bool ownsTask = true);
+
+ void schedualPeriodically(decaf::lang::Runnable* task, long long period, bool ownsTask = true);
+
+ void cancel(decaf::lang::Runnable* task);
+
+ void executeAfterDelay(decaf::lang::Runnable* task, long long delay, bool ownsTask = true);
+
+ void shutdown();
+
+ protected:
+
+ virtual void doStart();
+
+ virtual void doStop(activemq::util::ServiceStopper* stopper);
+
+ };
+
+}}
+
+#endif /* _ACTIVEMQ_THREADS_SCHEDULER_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/Scheduler.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.cpp?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.cpp Wed Mar 16 23:09:53 2011
@@ -0,0 +1,54 @@
+/*
+ * 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 "SchedulerTimerTask.h"
+
+#include <activemq/exceptions/ActiveMQException.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+
+using namespace activemq;
+using namespace activemq::threads;
+using namespace activemq::exceptions;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+SchedulerTimerTask::SchedulerTimerTask(Runnable* task, bool ownsTask) : task(task), ownsTask(ownsTask) {
+
+ if(task == NULL) {
+ throw NullPointerException(__FILE__, __LINE__, "Assigned Task cannot be NULL.");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SchedulerTimerTask::~SchedulerTimerTask() {
+
+ try{
+ if(ownsTask) {
+ delete this->task;
+ }
+ }
+ AMQ_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SchedulerTimerTask::run() {
+ if(this->task != NULL) {
+ this->task->run();
+ }
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.h?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.h Wed Mar 16 23:09:53 2011
@@ -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.
+ */
+
+#ifndef _ACTIVEMQ_THREADS_SCHEDULERTIMERTASK_H_
+#define _ACTIVEMQ_THREADS_SCHEDULERTIMERTASK_H_
+
+#include <activemq/util/Config.h>
+
+#include <decaf/util/TimerTask.h>
+#include <decaf/lang/Runnable.h>
+
+namespace activemq {
+namespace threads {
+
+ /**
+ * Extension of the Decaf TimerTask that adds a Runnable instance which is
+ * the target of this task.
+ *
+ * @since 3.3.0
+ */
+ class AMQCPP_API SchedulerTimerTask : public decaf::util::TimerTask {
+ private:
+
+ decaf::lang::Runnable* task;
+ bool ownsTask;
+
+ private:
+
+ SchedulerTimerTask(const SchedulerTimerTask&);
+ SchedulerTimerTask& operator= (const SchedulerTimerTask&);
+
+ public:
+
+ SchedulerTimerTask(decaf::lang::Runnable* task, bool ownsTask = true);
+
+ virtual ~SchedulerTimerTask();
+
+ virtual void run();
+ };
+
+}}
+
+#endif /* _ACTIVEMQ_THREADS_SCHEDULERTIMERTASK_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/SchedulerTimerTask.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.cpp?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.cpp Wed Mar 16 23:09:53 2011
@@ -0,0 +1,25 @@
+/*
+ * 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 "Service.h"
+
+using namespace activemq;
+using namespace activemq::util;
+
+////////////////////////////////////////////////////////////////////////////////
+Service::~Service() {
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.h?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.h Wed Mar 16 23:09:53 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_UTIL_SERVICE_H_
+#define _ACTIVEMQ_UTIL_SERVICE_H_
+
+#include <activemq/util/Config.h>
+
+namespace activemq {
+namespace util {
+
+ /**
+ * Base interface for all classes that run as a Service inside the application
+ *
+ * @since 3.3.0
+ */
+ class AMQCPP_API Service {
+ public:
+
+ virtual ~Service();
+
+ public:
+
+ virtual void start() = 0;
+
+ virtual void stop() = 0;
+
+ };
+
+}}
+
+#endif /* _ACTIVEMQ_UTIL_SERVICE_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Service.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.cpp?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.cpp Wed Mar 16 23:09:53 2011
@@ -0,0 +1,25 @@
+/*
+ * 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 "ServiceListener.h"
+
+using namespace activemq;
+using namespace activemq::util;
+
+////////////////////////////////////////////////////////////////////////////////
+ServiceListener::~ServiceListener() {
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.h?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.h Wed Mar 16 23:09:53 2011
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_UTIL_SERVICELISTENER_H_
+#define _ACTIVEMQ_UTIL_SERVICELISTENER_H_
+
+#include <activemq/util/Config.h>
+
+namespace activemq {
+namespace util {
+
+ class Service;
+
+ /**
+ * Listener interface for observers of Service related events.
+ *
+ * @since 3.3.0
+ */
+ class AMQCPP_API ServiceListener {
+ public:
+
+ virtual ~ServiceListener();
+
+ /**
+ * indicates that the target service has completed its start operation.
+ *
+ * @param target
+ * The service that triggered this notification.
+ */
+ virtual void started(const Service* target) = 0;
+
+ /**
+ * indicates that the target service has completed its stop operation.
+ *
+ * @param target
+ * The service that triggered this notification.
+ */
+ virtual void stopped(const Service* target) = 0;
+
+ };
+
+}}
+
+#endif /* _ACTIVEMQ_UTIL_SERVICELISTENER_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceListener.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.cpp?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.cpp Wed Mar 16 23:09:53 2011
@@ -0,0 +1,70 @@
+/*
+ * 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 "ServiceStopper.h"
+
+#include <activemq/util/Service.h>
+#include <activemq/exceptions/ActiveMQException.h>
+
+using namespace activemq;
+using namespace activemq::util;
+using namespace activemq::exceptions;
+using namespace decaf;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+ServiceStopper::ServiceStopper() : firstException(), hasException(false) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ServiceStopper::~ServiceStopper() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServiceStopper::stop(Service* service) {
+
+ if(service == NULL) {
+ return;
+ }
+
+ try{
+ service->stop();
+ } catch(Exception& ex) {
+ this->onException(service, ex);
+ } catch(std::exception& stdex) {
+ ActiveMQException wrapper(__FILE__, __LINE__, stdex.what());
+ this->onException(service, wrapper);
+ } catch(...) {
+ ActiveMQException wrapper(__FILE__, __LINE__, "Caught Unknown Exception");
+ this->onException(service, wrapper);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServiceStopper::throwFirstException() {
+ if(this->hasException) {
+ throw this->firstException;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServiceStopper::onException(Service* service, Exception& ex) {
+ if(!this->hasException) {
+ this->firstException = ex;
+ this->hasException = true;
+ }
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.h?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.h Wed Mar 16 23:09:53 2011
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_UTIL_SERVICESTOPPER_H_
+#define _ACTIVEMQ_UTIL_SERVICESTOPPER_H_
+
+#include <activemq/util/Config.h>
+
+#include <decaf/lang/Exception.h>
+
+namespace activemq {
+namespace util {
+
+ class Service;
+
+ class AMQCPP_API ServiceStopper {
+ private:
+
+ decaf::lang::Exception firstException;
+ bool hasException;
+
+ private:
+
+ ServiceStopper(const ServiceStopper&);
+ ServiceStopper& operator= (const ServiceStopper&);
+
+ public:
+
+ ServiceStopper();
+ virtual ~ServiceStopper();
+
+ void stop(Service* service);
+
+ void throwFirstException();
+
+ virtual void onException(Service* service, decaf::lang::Exception& ex);
+
+ };
+
+}}
+
+#endif /* _ACTIVEMQ_UTIL_SERVICESTOPPER_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceStopper.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.cpp?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.cpp Wed Mar 16 23:09:53 2011
@@ -0,0 +1,123 @@
+/*
+ * 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 "ServiceSupport.h"
+
+#include <memory>
+#include <activemq/util/ServiceListener.h>
+#include <activemq/util/ServiceStopper.h>
+
+#include <decaf/util/Iterator.h>
+
+using namespace activemq;
+using namespace activemq::util;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+ServiceSupport::ServiceSupport() : Service(), started(), stopping(), stopped(true), listemers() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ServiceSupport::~ServiceSupport() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServiceSupport::dispose(Service* service) {
+ try {
+ if(service != NULL) {
+ service->stop();
+ }
+ } catch (Exception e) {
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServiceSupport::start() {
+ if(started.compareAndSet(false, true)) {
+
+ bool success = false;
+ try {
+ this->doStart();
+ success = true;
+ } catch(...) {
+ this->started.set(success);
+ }
+
+ this->stopping.set(false);
+ this->stopped.set(!success);
+
+ std::auto_ptr< Iterator<ServiceListener*> > iter(this->listemers.iterator());
+ while(iter->hasNext()) {
+ iter->next()->started(this);
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServiceSupport::stop() {
+ if(this->stopped.compareAndSet(false, true)) {
+ this->stopping.set(true);
+ ServiceStopper stopper;
+ try {
+ this->doStop(&stopper);
+ } catch(Exception& e) {
+ stopper.onException(this, e);
+ }
+
+ this->stopped.set(true);
+ this->started.set(false);
+ this->stopping.set(false);
+
+ std::auto_ptr< Iterator<ServiceListener*> > iter(this->listemers.iterator());
+ while(iter->hasNext()) {
+ iter->next()->stopped(this);
+ }
+
+ stopper.throwFirstException();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ServiceSupport::isStarted() const {
+ return this->started.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ServiceSupport::isStopping() const {
+ return this->stopping.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ServiceSupport::isStopped() const {
+ return this->stopped.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServiceSupport::addServiceListener(ServiceListener* listener) {
+ if(listener != NULL) {
+ this->listemers.add(listener);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ServiceSupport::removeServiceListener(ServiceListener* listener) {
+ if(listener != NULL) {
+ this->listemers.remove(listener);
+ }
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.h?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.h Wed Mar 16 23:09:53 2011
@@ -0,0 +1,123 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_UTIL_SERVICESUPPORT_H_
+#define SERVICESUPPORT_H_
+
+#include <activemq/util/Config.h>
+#include <activemq/util/Service.h>
+
+#include <decaf/util/concurrent/atomic/AtomicBoolean.h>
+#include <decaf/util/concurrent/CopyOnWriteArrayList.h>
+
+namespace activemq {
+namespace util {
+
+ class ServiceListener;
+ class ServiceStopper;
+
+ /**
+ * Provides a base class for Service implementations.
+ *
+ * @since 3.3.0
+ */
+ class AMQCPP_API ServiceSupport : public Service {
+ private:
+
+ decaf::util::concurrent::atomic::AtomicBoolean started;
+ decaf::util::concurrent::atomic::AtomicBoolean stopping;
+ decaf::util::concurrent::atomic::AtomicBoolean stopped;
+ decaf::util::concurrent::CopyOnWriteArrayList<ServiceListener*> listemers;
+
+ public:
+
+ ServiceSupport(const ServiceSupport&);
+ ServiceSupport& operator=(const ServiceSupport&);
+
+ public:
+
+ ServiceSupport();
+
+ virtual ~ServiceSupport();
+
+ public:
+
+ /**
+ * Safely shuts down a service.
+ *
+ * @param service
+ * The service to stop.
+ */
+ static void dispose(Service* service);
+
+ /**
+ * Starts the Service, notifying any registered listeners of the start
+ * if it is successful.
+ */
+ void start();
+
+ /**
+ * Stops the Service.
+ */
+ void stop();
+
+ /**
+ * @return true if this service has been started
+ */
+ bool isStarted() const;
+
+ /**
+ * @return true if this service is in the process of closing
+ */
+ bool isStopping() const;
+
+ /**
+ * @return true if this service is closed
+ */
+ bool isStopped() const;
+
+ /**
+ * Adds the given listener to this Service's list of listeners, call retains
+ * ownership of the pointer.
+ */
+ void addServiceListener(ServiceListener* listener);
+
+ /**
+ * Removes the given listener to this Service's list of listeners, call retains
+ * ownership of the pointer.
+ */
+ void removeServiceListener(ServiceListener* llistener);
+
+ protected:
+
+ /**
+ * Performs the actual stop operation on the service, ensuring that all
+ * resources held are released, must be implemented in derived class.
+ */
+ virtual void doStop(ServiceStopper* stopper) = 0;
+
+ /**
+ * Performs the actual start operation on the service, acquiring all the
+ * resources needed to run the service. Must be implemented in derived class.
+ */
+ virtual void doStart() = 0;
+
+ };
+
+}}
+
+#endif /* _ACTIVEMQ_UTIL_SERVICESUPPORT_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/ServiceSupport.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.cpp?rev=1082340&r1=1082339&r2=1082340&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.cpp Wed Mar 16 23:09:53 2011
@@ -46,7 +46,9 @@ namespace util{
public:
- TimerImpl() : heap(), cancelled( false ) {}
+ TimerImpl() : Thread(), heap(), cancelled( false ) {}
+
+ TimerImpl(const std::string& name) : Thread(name), heap(), cancelled( false ) {}
~TimerImpl() {
try{
@@ -199,6 +201,11 @@ Timer::Timer() : internal( new TimerImpl
}
////////////////////////////////////////////////////////////////////////////////
+Timer::Timer(const std::string& name) : internal( new TimerImpl(name) ) {
+ this->internal->start();
+}
+
+////////////////////////////////////////////////////////////////////////////////
Timer::~Timer() {
try{
delete this->internal;
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.h?rev=1082340&r1=1082339&r2=1082340&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Timer.h Wed Mar 16 23:09:53 2011
@@ -67,6 +67,14 @@ namespace util {
Timer();
+ /**
+ * Create a new Timer whose associated thread is assigned the name given.
+ *
+ * @param name
+ * The name to assign to this Timer's Thread.
+ */
+ Timer(const std::string& name);
+
virtual ~Timer();
/**
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=1082340&r1=1082339&r2=1082340&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Wed Mar 16 23:09:53 2011
@@ -48,6 +48,7 @@ cc_sources = \
activemq/state/TransactionStateTest.cpp \
activemq/threads/CompositeTaskRunnerTest.cpp \
activemq/threads/DedicatedTaskRunnerTest.cpp \
+ activemq/threads/SchedulerTest.cpp \
activemq/transport/IOTransportTest.cpp \
activemq/transport/TransportRegistryTest.cpp \
activemq/transport/correlator/ResponseCorrelatorTest.cpp \
@@ -268,6 +269,7 @@ h_sources = \
activemq/state/TransactionStateTest.h \
activemq/threads/CompositeTaskRunnerTest.h \
activemq/threads/DedicatedTaskRunnerTest.h \
+ activemq/threads/SchedulerTest.h \
activemq/transport/IOTransportTest.h \
activemq/transport/TransportRegistryTest.h \
activemq/transport/correlator/ResponseCorrelatorTest.h \
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.cpp?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.cpp Wed Mar 16 23:09:53 2011
@@ -0,0 +1,263 @@
+/*
+ * 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 "SchedulerTest.h"
+
+#include <activemq/threads/Scheduler.h>
+#include <decaf/lang/Runnable.h>
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace activemq;
+using namespace activemq::threads;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+ class CounterTask : public Runnable {
+ private:
+
+ int count;
+
+ public:
+
+ CounterTask() : count(0) {
+
+ }
+
+ virtual ~CounterTask() {}
+
+ int getCount() const {
+ return count;
+ }
+
+ virtual void run() {
+ count++;
+ }
+
+ };
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SchedulerTest::SchedulerTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SchedulerTest::~SchedulerTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SchedulerTest::testConstructor() {
+
+ Scheduler scheduler("testExecutePeriodically");
+ CPPUNIT_ASSERT_EQUAL(false, scheduler.isStarted());
+ CPPUNIT_ASSERT_EQUAL(false, scheduler.isStopping());
+ CPPUNIT_ASSERT_EQUAL(true, scheduler.isStopped());
+ scheduler.start();
+ CPPUNIT_ASSERT_EQUAL(true, scheduler.isStarted());
+ CPPUNIT_ASSERT_EQUAL(false, scheduler.isStopping());
+ CPPUNIT_ASSERT_EQUAL(false, scheduler.isStopped());
+ scheduler.shutdown();
+ CPPUNIT_ASSERT_EQUAL(true, scheduler.isStarted());
+ CPPUNIT_ASSERT_EQUAL(false, scheduler.isStopping());
+ CPPUNIT_ASSERT_EQUAL(false, scheduler.isStopped());
+ scheduler.stop();
+ CPPUNIT_ASSERT_EQUAL(false, scheduler.isStarted());
+ CPPUNIT_ASSERT_EQUAL(false, scheduler.isStopping());
+ CPPUNIT_ASSERT_EQUAL(true, scheduler.isStopped());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SchedulerTest::testScheduleNullRunnableThrows() {
+
+ Scheduler scheduler("testSchedualPeriodically");
+ scheduler.start();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should have thrown a NullPointerException",
+ scheduler.schedualPeriodically(NULL, 400),
+ NullPointerException);
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should have thrown a NullPointerException",
+ scheduler.executePeriodically(NULL, 400),
+ NullPointerException);
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should have thrown a NullPointerException",
+ scheduler.executeAfterDelay(NULL, 400),
+ NullPointerException);
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SchedulerTest::testExecutePeriodically() {
+
+ {
+ Scheduler scheduler("testExecutePeriodically");
+ scheduler.start();
+ CounterTask* task = new CounterTask();
+ scheduler.executePeriodically(task, 500);
+ CPPUNIT_ASSERT(task->getCount() == 0);
+ Thread::sleep(600);
+ CPPUNIT_ASSERT(task->getCount() >= 1);
+ Thread::sleep(600);
+ CPPUNIT_ASSERT(task->getCount() >= 2);
+ CPPUNIT_ASSERT(task->getCount() < 5);
+ }
+
+ {
+ Scheduler scheduler("testSchedualPeriodically");
+ scheduler.start();
+ CounterTask* task = new CounterTask();
+ scheduler.schedualPeriodically(task, 1000);
+ CPPUNIT_ASSERT(task->getCount() == 0);
+ scheduler.cancel(task);
+
+ try{
+ scheduler.cancel(task);
+ CPPUNIT_FAIL("Should have thrown an exception");
+ } catch(...) {
+ }
+
+ scheduler.shutdown();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SchedulerTest::testSchedualPeriodically() {
+
+ {
+ Scheduler scheduler("testSchedualPeriodically");
+ scheduler.start();
+ CounterTask* task = new CounterTask();
+ scheduler.schedualPeriodically(task, 400);
+ CPPUNIT_ASSERT(task->getCount() == 0);
+ Thread::sleep(600);
+ CPPUNIT_ASSERT(task->getCount() >= 1);
+ Thread::sleep(600);
+ CPPUNIT_ASSERT(task->getCount() >= 2);
+ CPPUNIT_ASSERT(task->getCount() < 5);
+ }
+
+ {
+ Scheduler scheduler("testSchedualPeriodically");
+ scheduler.start();
+ CounterTask* task = new CounterTask();
+ scheduler.schedualPeriodically(task, 1000);
+ CPPUNIT_ASSERT(task->getCount() == 0);
+ scheduler.cancel(task);
+
+ try{
+ scheduler.cancel(task);
+ CPPUNIT_FAIL("Should have thrown an exception");
+ } catch(...) {
+ }
+
+ scheduler.shutdown();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SchedulerTest::testExecuteAfterDelay() {
+
+ {
+ Scheduler scheduler("testExecuteAfterDelay");
+ scheduler.start();
+ CounterTask task;
+ scheduler.executeAfterDelay(&task, 500, false);
+ CPPUNIT_ASSERT(task.getCount() == 0);
+ Thread::sleep(600);
+ CPPUNIT_ASSERT_EQUAL(1, task.getCount());
+ Thread::sleep(600);
+ CPPUNIT_ASSERT_EQUAL(1, task.getCount());
+ }
+
+ // Should not be any cancelable tasks
+ {
+ Scheduler scheduler("testExecuteAfterDelay");
+ scheduler.start();
+ CounterTask* task = new CounterTask();
+ scheduler.executeAfterDelay(task, 1000);
+ CPPUNIT_ASSERT(task->getCount() == 0);
+
+ try{
+ scheduler.cancel(task);
+ CPPUNIT_FAIL("Should have thrown an exception");
+ } catch(...) {
+ }
+
+ scheduler.shutdown();
+ }
+
+ // This block is for testing memory leaks, no actual Tests.
+ {
+ Scheduler scheduler("testExecuteAfterDelay");
+ scheduler.start();
+ CounterTask* task = new CounterTask();
+ scheduler.executeAfterDelay(task, 300);
+ CPPUNIT_ASSERT(task->getCount() == 0);
+ Thread::sleep(600);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SchedulerTest::testCancel() {
+
+ Scheduler scheduler("testCancel");
+ scheduler.start();
+ CounterTask task;
+ scheduler.executePeriodically(&task, 500, false);
+ scheduler.cancel(&task);
+ CPPUNIT_ASSERT(task.getCount() == 0);
+ Thread::sleep(600);
+ CPPUNIT_ASSERT_EQUAL(0, task.getCount());
+ Thread::sleep(600);
+ CPPUNIT_ASSERT_EQUAL(0, task.getCount());
+ scheduler.shutdown();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SchedulerTest::testShutdown() {
+
+ {
+ Scheduler scheduler("testShutdown");
+ scheduler.start();
+ CounterTask task;
+ scheduler.executePeriodically(&task, 500, false);
+ scheduler.shutdown();
+ CPPUNIT_ASSERT(task.getCount() == 0);
+ Thread::sleep(600);
+ CPPUNIT_ASSERT_EQUAL(0, task.getCount());
+ Thread::sleep(600);
+ CPPUNIT_ASSERT_EQUAL(0, task.getCount());
+ }
+
+ {
+ Scheduler scheduler("testShutdown");
+ scheduler.start();
+ CounterTask* task = new CounterTask();
+ scheduler.executeAfterDelay(task, 1000);
+ CPPUNIT_ASSERT(task->getCount() == 0);
+ scheduler.shutdown();
+ scheduler.stop();
+ CPPUNIT_ASSERT(scheduler.isStopped());
+ }
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.h?rev=1082340&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.h Wed Mar 16 23:09:53 2011
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+#ifndef _ACTIVEMQ_THREADS_SCHEDULERTEST_H_
+#define _ACTIVEMQ_THREADS_SCHEDULERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace activemq {
+namespace threads {
+
+ class SchedulerTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( SchedulerTest );
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testScheduleNullRunnableThrows );
+ CPPUNIT_TEST( testExecutePeriodically );
+ CPPUNIT_TEST( testSchedualPeriodically );
+ CPPUNIT_TEST( testExecuteAfterDelay );
+ CPPUNIT_TEST( testCancel );
+ CPPUNIT_TEST( testShutdown );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ SchedulerTest();
+ virtual ~SchedulerTest();
+
+ void testConstructor();
+ void testScheduleNullRunnableThrows();
+ void testExecutePeriodically();
+ void testSchedualPeriodically();
+ void testExecuteAfterDelay();
+ void testCancel();
+ void testShutdown();
+
+ };
+
+}}
+
+#endif /* _ACTIVEMQ_THREADS_SCHEDULERTEST_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/threads/SchedulerTest.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp?rev=1082340&r1=1082339&r2=1082340&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Wed Mar 16 23:09:53 2011
@@ -134,6 +134,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( activem
#include <activemq/util/MarshallingSupportTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION( activemq::util::MarshallingSupportTest );
+#include <activemq/threads/SchedulerTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::threads::SchedulerTest );
#include <activemq/threads/DedicatedTaskRunnerTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION( activemq::threads::DedicatedTaskRunnerTest );
#include <activemq/threads/CompositeTaskRunnerTest.h>