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 2007/06/15 21:15:08 UTC
svn commit: r547768 - in
/activemq/activemq-cpp/trunk/src/main/activemq/transport: MockTransport.cpp
MockTransport.h MockTransportFactory.cpp MockTransportFactory.h
Author: tabish
Date: Fri Jun 15 12:15:05 2007
New Revision: 547768
URL: http://svn.apache.org/viewvc?view=rev&rev=547768
Log:
https://issues.apache.org/activemq/browse/AMQCPP-130
Added:
activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp (with props)
activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h
activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp
activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.h
Added: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp?view=auto&rev=547768
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp Fri Jun 15 12:15:05 2007
@@ -0,0 +1,95 @@
+/*
+ * 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 <activemq/transport/MockTransport.h>
+#include <activemq/support/LibraryInit.h>
+
+using namespace activemq;
+using namespace activemq::transport;
+using namespace activemq::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+MockTransport* MockTransport::instance = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+MockTransport::MockTransport( ResponseBuilder* responseBuilder ,
+ bool own,
+ bool useDefOutgoing ){
+
+ this->responseBuilder = NULL;
+ this->commandListener = NULL;
+ this->outgoingCommandListener = NULL;
+ this->exceptionListener = NULL;
+ this->responseBuilder = responseBuilder;
+ this->own = own;
+ this->nextCommandId = 0;
+ this->instance = this;
+ if( useDefOutgoing )
+ {
+ this->outgoingCommandListener = &defaultListener;
+ this->defaultListener.setTransport( this );
+ this->defaultListener.setResponseBuilder( responseBuilder );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+MockTransport::~MockTransport(){
+
+ if( own ){
+ delete responseBuilder;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned int MockTransport::getNextCommandId() throw ( exceptions::ActiveMQException ) {
+
+ try{
+ synchronized( &commandIdMutex ){
+ return ++nextCommandId;
+ }
+
+ // Should never get here, but some compilers aren't
+ // smart enough to figure out we'll never get here.
+ return 0;
+ }
+ AMQ_CATCHALL_THROW( transport::CommandIOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MockTransport::oneway( Command* command )
+ throw(CommandIOException, exceptions::UnsupportedOperationException)
+{
+ if( outgoingCommandListener != NULL ){
+ outgoingCommandListener->onCommand( command );
+ return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Response* MockTransport::request( Command* command )
+ throw(CommandIOException,
+ exceptions::UnsupportedOperationException)
+{
+ if( responseBuilder != NULL ){
+ command->setCommandId( getNextCommandId() );
+ command->setResponseRequired( true );
+ return responseBuilder->buildResponse( command );
+ }
+
+ throw CommandIOException( __FILE__, __LINE__,
+ "no response builder available" );
+}
Propchange: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.cpp
------------------------------------------------------------------------------
svn:executable = *
Added: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h?view=auto&rev=547768
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h Fri Jun 15 12:15:05 2007
@@ -0,0 +1,211 @@
+/*
+ * 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_TANSPORT_MOCKTRANSPORT_H_
+#define ACTIVEMQ_TANSPORT_MOCKTRANSPORT_H_
+
+#include <activemq/transport/Transport.h>
+#include <activemq/concurrent/Concurrent.h>
+#include <activemq/transport/CommandListener.h>
+#include <activemq/transport/TransportExceptionListener.h>
+#include <activemq/transport/CommandIOException.h>
+#include <activemq/concurrent/Concurrent.h>
+#include <activemq/concurrent/Mutex.h>
+#include <activemq/concurrent/Thread.h>
+#include <activemq/util/Config.h>
+#include <activemq/concurrent/CountDownLatch.h>
+
+namespace activemq{
+namespace transport{
+
+ class MockTransport : public Transport{
+
+ public:
+
+ class ResponseBuilder{
+ public:
+ virtual ~ResponseBuilder(){}
+
+ virtual Response* buildResponse( const Command* cmd ) = 0;
+ virtual Command* buildIncomingCommand( const Command* cmd ) = 0;
+ };
+
+ class InternalCommandListener :
+ public CommandListener,
+ public concurrent::Thread
+ {
+ private:
+
+ MockTransport* transport;
+ ResponseBuilder* responseBuilder;
+ concurrent::Mutex mutex;
+ Command* command;
+ Command* response;
+ bool done;
+ concurrent::CountDownLatch startedLatch;
+
+ public:
+
+ InternalCommandListener(void) : startedLatch(1) {
+ command = NULL;
+ response = NULL;
+ transport = NULL;
+ responseBuilder = NULL;
+ done = false;
+
+ this->start();
+ startedLatch.await();
+ }
+
+ virtual ~InternalCommandListener() {
+ done = true;
+ synchronized( &mutex )
+ {
+ mutex.notifyAll();
+ }
+ this->join();
+
+ delete response;
+ }
+
+ void setTransport( DummyTransport* transport ){
+ this->transport = transport;
+ }
+
+ void setResponseBuilder( ResponseBuilder* responseBuilder ) {
+ this->responseBuilder = responseBuilder;
+ }
+
+ virtual void onCommand( Command* command )
+ {
+ synchronized( &mutex )
+ {
+ this->command = command;
+ // Create a response now before the caller has a
+ // chance to destroy the command.
+ this->response =
+ responseBuilder->buildIncomingCommand( command );
+
+ mutex.notifyAll();
+ }
+ }
+
+ void run(void)
+ {
+ try
+ {
+ synchronized( &mutex )
+ {
+ while( !done )
+ {
+ startedLatch.countDown();
+ mutex.wait();
+
+ if( command == NULL )
+ {
+ continue;
+ }
+
+ // If we created a response then send it.
+ if( response != NULL && transport != NULL )
+ {
+ transport->fireCommand( this->response );
+ }
+
+ this->response = NULL;
+ this->command = NULL;
+ }
+ }
+ }
+ AMQ_CATCHALL_NOTHROW()
+ }
+ };
+
+ private:
+
+ ResponseBuilder* responseBuilder;
+ CommandListener* commandListener;
+ CommandListener* outgoingCommandListener;
+ TransportExceptionListener* exceptionListener;
+ unsigned int nextCommandId;
+ concurrent::Mutex commandIdMutex;
+ bool own;
+ InternalCommandListener defaultListener;
+ static DummyTransport* instance;
+
+ public:
+
+ static MockTransport* getInstance() {
+ return instance;
+ }
+
+ MockTransport( ResponseBuilder* responseBuilder ,
+ bool own = false,
+ bool useDefOutgoing = true );
+
+ virtual ~MockTransport();
+
+ void setResponseBuilder( ResponseBuilder* responseBuilder ){
+ this->responseBuilder = responseBuilder;
+ }
+
+ unsigned int getNextCommandId() throw (exceptions::ActiveMQException);
+
+ virtual void oneway( Command* command )
+ throw(CommandIOException, exceptions::UnsupportedOperationException);
+
+ virtual Response* request( Command* command )
+ throw(CommandIOException,
+ exceptions::UnsupportedOperationException);
+
+ virtual void setCommandListener( CommandListener* listener ){
+ this->commandListener = listener;
+ }
+
+ virtual void setOutgoingCommandListener( CommandListener* listener ){
+ outgoingCommandListener = listener;
+ }
+
+ virtual void setCommandReader( CommandReader* reader AMQCPP_UNUSED){}
+
+ virtual void setCommandWriter( CommandWriter* writer AMQCPP_UNUSED){}
+
+ virtual void setTransportExceptionListener(
+ TransportExceptionListener* listener )
+ {
+ this->exceptionListener = listener;
+ }
+
+ virtual void fireCommand( Command* cmd ){
+ if( commandListener != NULL ){
+ commandListener->onCommand( cmd );
+ }
+ }
+
+ virtual void fireException( const exceptions::ActiveMQException& ex ){
+ if( exceptionListener != NULL ){
+ exceptionListener->onTransportException( this, ex );
+ }
+ }
+
+ virtual void start() throw (cms::CMSException){}
+ virtual void close() throw (cms::CMSException){}
+ };
+
+}}
+
+#endif /*ACTIVEMQ_TANSPORT_MOCKTRANSPORT_H_*/
Added: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp?view=auto&rev=547768
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.cpp Fri Jun 15 12:15:05 2007
@@ -0,0 +1,50 @@
+/*
+ * 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 "MockTransportFactory.h"
+#include <activemq/connector/stomp/StompResponseBuilder.h>
+#include <activemq/transport/MockTransport.h>
+
+using namespace activemq;
+using namespace activemq::transport;
+using namespace activemq::util;
+
+////////////////////////////////////////////////////////////////////////////////
+Transport* MockTransportFactory::createTransport(
+ const activemq::util::Properties& properties,
+ Transport* next,
+ bool own ) throw ( exceptions::ActiveMQException )
+{
+ // We don't use the next here, so clean it up now.
+ if( own == true ) {
+ delete next;
+ }
+
+ std::string wireFormat =
+ properties.getProperty( "wireFormat", "stomp" );
+
+ MockTransport::ResponseBuilder* builder = NULL;
+
+ if( wireFormat == "stomp" )
+ {
+ builder = new connector::stomp::StompResponseBuilder(
+ properties.getProperty(
+ "transport.sessionId", "testSessionId" ) );
+ }
+
+ return new MockTransport( builder, true, true );
+}
Added: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.h?view=auto&rev=547768
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.h (added)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransportFactory.h Fri Jun 15 12:15:05 2007
@@ -0,0 +1,48 @@
+/*
+ * 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_TRANSPORT_MOCKTRANSPORTFACTORY_H_
+#define ACTIVEMQ_TRANSPORT_MOCKTRANSPORTFACTORY_H_
+
+#include <activemq/transport/TransportFactory.h>
+
+namespace activemq{
+namespace transport{
+
+ /**
+ * Manufactures MockTransports, which are objects that
+ * read from input streams and write to output streams.
+ */
+ class MockTransportFactory : public TransportFactory{
+ public:
+
+ virtual ~MockTransportFactory(){}
+
+ /**
+ * Creates a Transport instance.
+ * @param properties The properties for the transport.
+ */
+ virtual Transport* createTransport(
+ const activemq::util::Properties& properties,
+ Transport* next = NULL,
+ bool own = true ) throw ( exceptions::ActiveMQException );
+
+ };
+
+}}
+
+#endif /*ACTIVEMQ_TRANSPORT_MOCKTRANSPORTFACTORY_H_*/