You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by fi...@apache.org on 2012/08/02 16:57:47 UTC
svn commit: r1368503 - in /incubator/etch/trunk/binding-cpp/runtime:
include/support/ include/transport/ src/main/ src/main/support/
src/main/transport/ src/test/ src/test/support/ src/test/transport/
Author: fitzner
Date: Thu Aug 2 14:57:46 2012
New Revision: 1368503
URL: http://svn.apache.org/viewvc?rev=1368503&view=rev
Log:
ETCH-214: Implementation of EtchMailboxManager
EtchMailboxManager Implementation
Change-Id: I2022932d3437255968b4b3e44c50ab928657a6ec
Added:
incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h
- copied, changed from r1368502, incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h
incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h
incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h
incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp
incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h
incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
Modified: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h?rev=1368503&r1=1368502&r2=1368503&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h Thu Aug 2 14:57:46 2012
@@ -23,6 +23,7 @@
#include "common/EtchLong.h"
#include "transport/EtchWho.h"
#include "transport/EtchMessage.h"
+
/**
* Adapter between remote and message source.
*/
@@ -31,8 +32,10 @@ public:
class EtchElement;
class EtchNotify;
+ /**
+ * Destructure
+ */
virtual ~EtchMailbox() {
-
}
/**
@@ -44,16 +47,15 @@ public:
* Queues the message to the mailbox.
* @param sender
* @param msg
- * @param true if the message was accepted.
*/
- virtual status_t message(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg, capu::bool_t &result) = 0;
+ virtual status_t message(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg) = 0;
/**
* @param the next message to be read from the mailbox, or null if
* the mailbox is empty and closed. Wait forever for such a message
* to be delivered.
*/
- virtual status_t read(capu::SmartPointer<EtchElement> &result) = 0;
+ virtual status_t read(EtchElement *&result) = 0;
/**
* @param maxDelay the maximum amount of time in milliseconds to
@@ -62,26 +64,20 @@ public:
* @param the message read from the mailbox, or null if the mailbox
* is empty and closed, or if the time limit was exceeeded.
*/
- virtual status_t read(capu::int32_t maxDelay, capu::SmartPointer<EtchElement> &result) = 0;
+ virtual status_t read(EtchElement *&result, capu::int32_t maxDelay) = 0;
/**
* Closes the mailbox so that no more messages can be delivered.
- * Queued messages remain to be read. Reading an empty closed
- * mailbox returns null.
- * @param true if this call closed the mailbox (that is, if action was
- * taken), false if the mailbox was already closed.
+ * Queued messages remain to be read.
*/
- virtual status_t closeDelivery(capu::bool_t &result) = 0;
+ virtual status_t closeDelivery() = 0;
/**
* Closes the mailbox so that no more messages will be delivered or
* read. Any remaining queued messages are delivered to a default
* handler.
- * @return true if this call closed the mailbox (that is, if action was
- * taken), false if the mailbox was already closed.
*/
- virtual status_t closeRead(capu::bool_t &result) = 0;
-
+ virtual status_t closeRead() = 0;
/**
* Registers a Notify interface implementation to receive a callback
* when a mailbox's status is changed.
@@ -94,7 +90,7 @@ public:
* forever. The mailbox is closed upon timeout.
* @throws IllegalStateException notify already registered.
*/
- virtual status_t registerNotify(capu::SmartPointer<EtchNotify> notify, capu::SmartPointer<EtchObject> state, capu::int32_t maxDelay) = 0;
+ virtual status_t registerNotify(EtchNotify* notify, EtchObject* state, capu::int32_t maxDelay) = 0;
/**
* Unregisters a Notify interface implementation from receiving a callback
@@ -102,7 +98,7 @@ public:
* @param notify a Notify interface implementation which was previously
* registered.
*/
- virtual status_t unregisterNotify(capu::SmartPointer<EtchNotify> notify) = 0;
+ virtual status_t unregisterNotify(EtchNotify* notify) = 0;
/**
* @return true if the mailbox is empty.
@@ -131,24 +127,22 @@ public:
*/
EtchElement(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg)
: mSender(sender), mMsg(msg) {
-
}
/**
* Destructor
*/
virtual ~EtchElement() {
-
}
/**
* The message sender.
*/
- const capu::SmartPointer<EtchWho> mSender;
+ capu::SmartPointer<EtchWho> mSender;
/**
* the message.
*/
- const capu::SmartPointer<EtchMessage> mMsg;
+ capu::SmartPointer<EtchMessage> mMsg;
};
/**
@@ -165,10 +159,8 @@ public:
* the mailbox is now closed to delivery, false if a message
* has arrived.
*/
- virtual status_t mailboxStatus(capu::SmartPointer<EtchMailbox> mb, capu::SmartPointer<EtchObject> state, capu::bool_t& closed) = 0;
+ virtual status_t mailboxStatus(EtchMailbox* mb, EtchObject* state, capu::bool_t closed) = 0;
};
};
-
-
#endif
Copied: incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h (from r1368502, incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h?p2=incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h&p1=incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h&r1=1368502&r2=1368503&rev=1368503&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/support/EtchMailbox.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/support/EtchPlainMailbox.h Thu Aug 2 14:57:46 2012
@@ -16,44 +16,46 @@
* limitations under the License.
*/
-#ifndef __ETCHMAILBOX_H__
-#define __ETCHMAILBOX_H__
+#ifndef __ETCHPLAINMAILBOX_H__
+#define __ETCHPLAINMAILBOX_H__
-#include "common/EtchBool.h"
-#include "common/EtchLong.h"
-#include "transport/EtchWho.h"
-#include "transport/EtchMessage.h"
-/**
- * Adapter between remote and message source.
- */
-class EtchMailbox {
+#include "capu/os/Mutex.h"
+#include "support/EtchMailbox.h"
+#include "util/EtchCircularQueue.h"
+#include "transport/EtchMailboxManager.h"
+
+class EtchPlainMailbox : public EtchMailbox{
public:
- class EtchElement;
- class EtchNotify;
- virtual ~EtchMailbox() {
+ /**
+ * Default Constructor
+ * @param mailboxManager
+ * @param messageId
+ */
+
+ EtchPlainMailbox(EtchMailboxManager* mailboxManager, EtchLong messageId);
- }
+ /**
+ * Destructor
+ */
+ virtual ~EtchPlainMailbox();
/**
* @return the message id of this mailbox.
*/
- virtual EtchLong getMessageId() = 0;
+ EtchLong getMessageId();
/**
- * Queues the message to the mailbox.
- * @param sender
- * @param msg
- * @param true if the message was accepted.
+ * @See EtchMailbox
*/
- virtual status_t message(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg, capu::bool_t &result) = 0;
+ status_t message(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg);
/**
* @param the next message to be read from the mailbox, or null if
* the mailbox is empty and closed. Wait forever for such a message
* to be delivered.
*/
- virtual status_t read(capu::SmartPointer<EtchElement> &result) = 0;
+ status_t read(EtchMailbox::EtchElement*& result);
/**
* @param maxDelay the maximum amount of time in milliseconds to
@@ -62,7 +64,7 @@ public:
* @param the message read from the mailbox, or null if the mailbox
* is empty and closed, or if the time limit was exceeeded.
*/
- virtual status_t read(capu::int32_t maxDelay, capu::SmartPointer<EtchElement> &result) = 0;
+ status_t read(EtchMailbox::EtchElement *& result, capu::int32_t maxDelay);
/**
* Closes the mailbox so that no more messages can be delivered.
@@ -71,16 +73,16 @@ public:
* @param true if this call closed the mailbox (that is, if action was
* taken), false if the mailbox was already closed.
*/
- virtual status_t closeDelivery(capu::bool_t &result) = 0;
+ status_t closeDelivery();
/**
* Closes the mailbox so that no more messages will be delivered or
* read. Any remaining queued messages are delivered to a default
* handler.
- * @return true if this call closed the mailbox (that is, if action was
- * taken), false if the mailbox was already closed.
+ * @return ETCH_OK if this call closed the mailbox (that is, if action was
+ * taken), ETCH_ERROR if the mailbox was already closed.
*/
- virtual status_t closeRead(capu::bool_t &result) = 0;
+ status_t closeRead();
/**
* Registers a Notify interface implementation to receive a callback
@@ -92,83 +94,51 @@ public:
* @param maxDelay the maximum amount of time in milliseconds to
* wait for delivery of a message to the mailbox. 0 means wait
* forever. The mailbox is closed upon timeout.
- * @throws IllegalStateException notify already registered.
+ * @return ETCH_OK registration was successfully, ETCH_ERROR otherwise
*/
- virtual status_t registerNotify(capu::SmartPointer<EtchNotify> notify, capu::SmartPointer<EtchObject> state, capu::int32_t maxDelay) = 0;
+ status_t registerNotify(EtchMailbox::EtchNotify* notify, EtchObject* state, capu::int32_t maxDelay);
/**
* Unregisters a Notify interface implementation from receiving a callback
* when a mailbox's status is changed. Cancels any timeout.
* @param notify a Notify interface implementation which was previously
* registered.
+ * @return ETCH_OK unregistration was successfully, ETCH_ERROR otherwise
*/
- virtual status_t unregisterNotify(capu::SmartPointer<EtchNotify> notify) = 0;
+ status_t unregisterNotify(EtchMailbox::EtchNotify* notify);
/**
* @return true if the mailbox is empty.
*/
- virtual capu::bool_t isEmpty() = 0;
+ capu::bool_t isEmpty();
/**
* @return true if the mailbox is closed.
*/
- virtual capu::bool_t isClosed() = 0;
+ capu::bool_t isClosed();
/**
* @return true if the mailbox is full.
*/
- virtual capu::bool_t isFull() = 0;
+ capu::bool_t isFull();
/**
- * The message as queued, including src and sender.
+ *
+ * @return mailbox manager
*/
- class EtchElement {
- public:
+ EtchMailboxManager* getMailboxManager();
- /**
- * @param sender the message sender.
- * @param msg the message.
- */
- EtchElement(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg)
- : mSender(sender), mMsg(msg) {
-
- }
-
- /**
- * Destructor
- */
- virtual ~EtchElement() {
-
- }
-
- /**
- * The message sender.
- */
- const capu::SmartPointer<EtchWho> mSender;
- /**
- * the message.
- */
- const capu::SmartPointer<EtchMessage> mMsg;
- };
-
- /**
- * Interface used to notify of mailbox status.
- */
- class EtchNotify {
- public:
- /**
- * Notifies of mailbox status change.
- * @param mb the mailbox whose status has changed.
- * @param state the state object passed in the register
- * method.
- * @param closed true if the mailbox timeout has expired and
- * the mailbox is now closed to delivery, false if a message
- * has arrived.
- */
- virtual status_t mailboxStatus(capu::SmartPointer<EtchMailbox> mb, capu::SmartPointer<EtchObject> state, capu::bool_t& closed) = 0;
- };
-};
+private:
+ EtchMailboxManager* mMailboxManager;
+ EtchMailbox::EtchNotify* mNotify;
+ EtchObject* mState;
+ EtchLong mMessageId;
+ capu::bool_t mAlarmSet;
+ EtchCircularQueue mQueue;
+ capu::Mutex mMutex;
+ void fireNotify();
+};
-#endif
+#endif /* ETCHPLAINMAILBOX_H */
Added: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h?rev=1368503&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMailboxManager.h Thu Aug 2 14:57:46 2012
@@ -0,0 +1,62 @@
+/* $Id$
+ *
+ * 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 __ETCHMAILBOXMANAGER_H__
+#define __ETCHMAILBOXMANAGER_H__
+
+#include "transport/EtchSessionMessage.h"
+#include "transport/EtchTransportMessage.h"
+#include "support/EtchMailbox.h"
+
+/**
+ * Interface to the mailbox manager as needed by {@link DeliveryService} and
+ * {@link Mailbox} implementors.
+ */
+class EtchMailboxManager : public EtchSessionMessage, public EtchTransportMessage {
+public:
+ /**
+ * Sends a message which begins a call after allocating a Mailbox to
+ * receive any responses.
+ * @param recipient specifies the recipient when there is the possibility
+ * of more than one.
+ * @param msg the message which begins the call.
+ * @param result the mailbox which will receive responses to this call.
+ * @return status code
+ */
+ virtual status_t transportCall(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage> msg, EtchMailbox*& result) = 0;
+
+ /**
+ * Removes the mailbox from the set of mailboxes receiving responses to
+ * messages.
+ * @param mb a mailbox as returned by {@link #transportCall(Who, Message)}.
+ * @return status code
+ */
+ virtual status_t unregisterMailbox(EtchMailbox* mb) = 0;
+
+ /**
+ * Re-delivers dead letter messages from a closed mailbox.
+ * @param sender
+ * @param msg
+ * @return status code
+ */
+ virtual status_t redeliver(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg) = 0;
+};
+
+#endif /* __ETCHMAILBOXMANAGER_H__ */
Added: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h?rev=1368503&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h Thu Aug 2 14:57:46 2012
@@ -0,0 +1,115 @@
+/* $Id$
+ *
+ * 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 __ETCHPLAINMAILBOXMANAGER_H__
+#define __ETCHPLAINMAILBOXMANAGER_H__
+
+#include "capu/os/Mutex.h"
+#include "util/EtchURL.h"
+#include "util/EtchResources.h"
+#include "util/EtchIdGenerator.h"
+#include "transport/EtchMailboxManager.h"
+#include "support/EtchPlainMailbox.h"
+#include "common/EtchString.h"
+
+class EtchPlainMailboxManager : public EtchMailboxManager {
+public:
+ /**
+ * @param transport used to deliver messages to our peer.
+ * @param uri
+ * @param resources
+ */
+ EtchPlainMailboxManager(EtchTransportMessage* transport, EtchURL* url, EtchResources* resources);
+
+ /**
+ * Destructure
+ */
+ virtual ~EtchPlainMailboxManager();
+
+ /**
+ * @return the transport.
+ */
+ EtchTransportMessage* getTransport();
+
+ /**
+ * @see EtchMailboxManager
+ */
+ status_t redeliver(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg);
+
+ /**
+ * Adds a mailbox to the set of mailbox receiving responses
+ * to messages.
+ * @param mb
+ */
+ status_t registerMailbox(EtchMailbox* mb);
+
+ /**
+ * @see EtchMailboxManager
+ */
+ status_t unregisterMailbox(EtchMailbox* mb);
+
+ /**
+ * Returns the mailbox for the specified msgid. This is a testing api.
+ * @param msgid
+ * @return the mailbox for the specified msgid.
+ */
+ status_t getMailbox(EtchLong msgid, EtchMailbox*& result);
+
+ ////////////////////////////
+ // MessageHandler methods //
+ ////////////////////////////
+ status_t sessionMessage(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg);
+
+ ///////////////////////////
+ // MessageSource methods //
+ ///////////////////////////
+ status_t transportCall(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage> msg, EtchMailbox*& result);
+ status_t transportMessage(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage> message);
+
+ ///////////////////////////
+ // SourceHandler methods //
+ ///////////////////////////
+
+ status_t sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result);
+ status_t sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value);
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event);
+
+ ////////////////////
+ // Source methods //
+ ////////////////////
+ status_t transportQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result);
+ status_t transportControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value);
+ status_t transportNotify(capu::SmartPointer<EtchObject> event);
+ EtchSessionMessage* getSession();
+ void setSession(EtchSessionMessage* session);
+
+ capu::uint64_t count();
+
+
+private:
+ EtchSessionMessage* mSession;
+ EtchTransportMessage* mTransport;
+ capu::bool_t mUp;
+ EtchHashTable<EtchLong, EtchMailbox*> mMailboxes;
+ capu::Mutex mMutex;
+ EtchIdGenerator mIdGen;
+};
+
+
+
+#endif
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1368503&r1=1368502&r2=1368503&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Thu Aug 2 14:57:46 2012
@@ -69,7 +69,11 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/transport/EtchTcpOption.h
${PROJECT_SOURCE_DIR}/include/transport/EtchPacketizer.h
${PROJECT_SOURCE_DIR}/include/transport/EtchMessage.h
+ ${PROJECT_SOURCE_DIR}/include/transport/EtchMailboxManager.h
+ ${PROJECT_SOURCE_DIR}/include/transport/EtchPlainMailboxManager.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidator.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchAsyncMode.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchDirection.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchTypeValidator.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchTypeCodes.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorBoolean.h
@@ -119,6 +123,7 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/support/EtchStubHelper.h
${PROJECT_SOURCE_DIR}/include/support/EtchStubBase.h
${PROJECT_SOURCE_DIR}/include/support/EtchTransportHelper.h
+ ${PROJECT_SOURCE_DIR}/include/support/EtchPlainMailbox.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
${PROJECT_SOURCE_DIR}/include/util/EtchCircularQueue.h
${PROJECT_SOURCE_DIR}/include/util/EtchIdGenerator.h
@@ -156,6 +161,7 @@ SET(MAIN_SOURCES
transport/EtchMessage.cpp
transport/EtchMessagizer.cpp
transport/EtchFormat.cpp
+ transport/EtchPlainMailboxManager.cpp
serialization/EtchTypeValidator.cpp
serialization/EtchValidatorBoolean.cpp
serialization/EtchValidatorByte.cpp
@@ -188,6 +194,7 @@ SET(MAIN_SOURCES
serialization/EtchBinaryTaggedData.cpp
serialization/EtchBinaryTaggedDataInput.cpp
serialization/EtchBinaryTaggedDataOutput.cpp
+ support/EtchPlainMailbox.cpp
support/EtchFreePool.cpp
support/EtchDefaultServerFactory.cpp
support/EtchStubBase.cpp
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp?rev=1368503&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp Thu Aug 2 14:57:46 2012
@@ -0,0 +1,136 @@
+/* $Id$
+ *
+ * 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 "support/EtchPlainMailbox.h"
+
+EtchPlainMailbox::EtchPlainMailbox(EtchMailboxManager* mailboxManager, EtchLong messageId)
+: mMailboxManager(mailboxManager), mNotify(NULL), mState(NULL), mMessageId(messageId), mQueue(1) {
+}
+
+EtchPlainMailbox::~EtchPlainMailbox() {
+ // TODO: Validate dynamic
+ while (!mQueue.isEmpty()) {
+ EtchMailbox::EtchElement* element = NULL;
+ if(ETCH_OK == mQueue.get(&element)) {
+ delete element;
+ }
+ }
+}
+
+EtchMailboxManager* EtchPlainMailbox::getMailboxManager() {
+ return mMailboxManager;
+}
+
+EtchLong EtchPlainMailbox::getMessageId() {
+ return mMessageId;
+}
+
+status_t EtchPlainMailbox::message(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg) {
+ status_t status;
+ EtchMailbox::EtchElement* element = new EtchMailbox::EtchElement(sender, msg);
+
+ status = mQueue.put(element, -1);
+ if(status == ETCH_OK) {
+ fireNotify();
+ return ETCH_OK;
+ } else {
+ // TODO: log error if message could not be put to the mailbox
+ delete element;
+ return ETCH_ERROR;
+ }
+}
+
+void EtchPlainMailbox::fireNotify() {
+ EtchMailbox::EtchNotify* n;
+ EtchObject* s;
+ capu::bool_t c;
+
+ mMutex.lock();
+ n = mNotify;
+ s = mState;
+ c = mQueue.isClosed();
+ mMutex.unlock();
+
+ if (n != NULL) {
+ n->mailboxStatus(this, s, c);
+ }
+}
+
+status_t EtchPlainMailbox::read(EtchMailbox::EtchElement*& result) {
+ status_t status = mQueue.get(&result);
+ if (ETCH_OK == status) {
+ return ETCH_OK;
+ }
+ // TODO: logging
+ return ETCH_ERROR;
+}
+
+status_t EtchPlainMailbox::read(EtchMailbox::EtchElement *& result, capu::int32_t maxDelay) {
+ status_t status = mQueue.get(&result, maxDelay);
+ if(status == ETCH_OK) {
+ return ETCH_OK;
+ }
+ return ETCH_ERROR;
+}
+
+status_t EtchPlainMailbox::closeDelivery() {
+
+ mMutex.lock();
+ if(mQueue.isClosed()) {
+ mMutex.unlock();
+ return ETCH_EINVAL;
+ }
+
+ mMailboxManager->unregisterMailbox(this);
+ mQueue.close();
+ mMutex.unlock();
+
+ fireNotify();
+ return ETCH_OK;
+}
+
+status_t EtchPlainMailbox::closeRead() {
+ if (closeDelivery() == ETCH_OK) {
+ EtchMailbox::EtchElement* mbe = NULL;
+ while ((read(mbe)) == ETCH_OK) {
+ mMailboxManager->redeliver(mbe->mSender, mbe->mMsg);
+ delete mbe;
+ }
+ return ETCH_OK;
+ }
+ return ETCH_ERROR;
+}
+
+status_t EtchPlainMailbox::registerNotify(EtchMailbox::EtchNotify* notify, EtchObject* state, capu::int32_t maxDelay) {
+ return ETCH_EUNIMPL;
+}
+
+status_t EtchPlainMailbox::unregisterNotify(EtchMailbox::EtchNotify* notify) {
+ return ETCH_EUNIMPL;
+}
+
+capu::bool_t EtchPlainMailbox::isEmpty() {
+ return mQueue.isEmpty();
+}
+
+capu::bool_t EtchPlainMailbox::isClosed() {
+ return mQueue.isClosed();
+}
+
+capu::bool_t EtchPlainMailbox::isFull() {
+ return mQueue.isFull();
+}
\ No newline at end of file
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp?rev=1368503&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp Thu Aug 2 14:57:46 2012
@@ -0,0 +1,184 @@
+/* $Id$
+ *
+ * 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 "transport/EtchPlainMailboxManager.h"
+
+EtchPlainMailboxManager::EtchPlainMailboxManager(EtchTransportMessage* transport, EtchURL* url, EtchResources* resources)
+: mSession(NULL), mTransport(transport) {
+ mTransport->setSession(this);
+}
+
+EtchPlainMailboxManager::~EtchPlainMailboxManager() {
+ EtchHashTable<EtchLong, EtchMailbox*>::Iterator it = mMailboxes.begin();
+ EtchHashTable<EtchLong, EtchMailbox*>::Pair p;
+ while (it.hasNext()) {
+ it.next(&p);
+ p.second->closeDelivery();
+ delete p.second;
+ }
+}
+
+EtchTransportMessage* EtchPlainMailboxManager::getTransport() {
+ return mTransport;
+}
+
+status_t EtchPlainMailboxManager::redeliver(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg) {
+ return mSession->sessionMessage(sender, msg);
+}
+
+status_t EtchPlainMailboxManager::registerMailbox(EtchMailbox* mb) {
+ if(mb == NULL) {
+ return ETCH_EINVAL;
+ }
+
+ const EtchLong msgid = mb->getMessageId();
+
+ mMutex.lock();
+ if (!mUp) {
+ mMutex.unlock();
+ return ETCH_EINVAL;
+ }
+
+ EtchMailbox* tmp = NULL;
+ if (mMailboxes.get(msgid, &tmp) != ETCH_ENOT_EXIST) {
+ mMutex.unlock();
+ return ETCH_EINVAL;
+ }
+
+ mMailboxes.put(msgid, mb);
+ mMutex.unlock();
+ return ETCH_OK;
+}
+
+status_t EtchPlainMailboxManager::unregisterMailbox(EtchMailbox* mb) {
+ if(mb == NULL) {
+ return ETCH_EINVAL;
+ }
+
+ EtchMailbox* tmp = NULL;
+ mMailboxes.remove(mb->getMessageId(), &tmp);
+ return ETCH_OK;
+}
+
+status_t EtchPlainMailboxManager::getMailbox(EtchLong msgid, EtchMailbox*& result) {
+ return mMailboxes.get(msgid, &result);
+}
+
+status_t EtchPlainMailboxManager::sessionMessage(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg) {
+ capu::int64_t msgid;
+ if(msg->getInReplyToMessageId(msgid) == ETCH_OK) {
+ EtchMailbox* mb = NULL;
+ if (getMailbox(msgid, mb) == ETCH_OK) {
+ return mb->message(sender, msg);
+ }
+ return ETCH_ERROR;
+ }
+ // no msgid - pass off to session
+ return mSession->sessionMessage(sender, msg);
+}
+
+status_t EtchPlainMailboxManager::transportCall(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage> msg, EtchMailbox*& result) {
+ capu::int64_t tmp;
+ if (msg->getMessageId(tmp) == ETCH_OK) {
+ // message has already been sent
+ return ETCH_ERROR;
+ }
+
+ if (msg->getInReplyToMessageId(tmp) == ETCH_OK) {
+ // message is marked as a reply
+ return ETCH_ERROR;
+ }
+
+ capu::int64_t msgid = mIdGen.next();
+ msg->setMessageId(msgid);
+
+ EtchMailbox *mb = new EtchPlainMailbox(this, msgid);
+ if (registerMailbox(mb) != ETCH_OK) {
+ delete mb;
+ return ETCH_ERROR;
+ }
+ //Log.report( "MailboxManager.send", "msg", msg );
+
+ if (mTransport->transportMessage(recipient, msg) == ETCH_OK) {
+ result = mb;
+ return ETCH_OK;
+ } else {
+ unregisterMailbox(mb);
+ delete mb;
+ return ETCH_ERROR;
+ }
+}
+
+status_t EtchPlainMailboxManager::transportMessage(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage> message) {
+ capu::int64_t tmp;
+ if (message->getMessageId(tmp) == ETCH_OK) {
+ // message has already been sent
+ return ETCH_ERROR;
+ }
+
+ message->setMessageId(mIdGen.next());
+
+ return mTransport->transportMessage(recipient, message);
+}
+
+status_t EtchPlainMailboxManager::sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result) {
+ return mSession->sessionQuery(query, result);
+}
+
+status_t EtchPlainMailboxManager::sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+ return mSession->sessionControl(control, value);
+}
+
+status_t EtchPlainMailboxManager::sessionNotify(capu::SmartPointer<EtchObject> event) {
+ if(event->equals(&EtchSession::UP)) {
+ mUp = true;
+ } else
+ if(event->equals(&EtchSession::DOWN)) {
+ mUp = false;
+ EtchHashTable<EtchLong, EtchMailbox*>::Iterator it = mMailboxes.begin();
+ EtchHashTable<EtchLong, EtchMailbox*>::Pair p;
+ while (it.hasNext()) {
+ it.next(&p);
+ p.second->closeDelivery();
+ }
+ }
+ return mSession->sessionNotify(event);
+}
+
+status_t EtchPlainMailboxManager::transportQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result) {
+ return mTransport->transportQuery(query, result);
+}
+
+status_t EtchPlainMailboxManager::transportControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+ return mTransport->transportControl(control, value);
+}
+
+status_t EtchPlainMailboxManager::transportNotify(capu::SmartPointer<EtchObject> event) {
+ return mTransport->transportNotify(event);
+}
+
+EtchSessionMessage* EtchPlainMailboxManager::getSession() {
+ return mSession;
+}
+
+void EtchPlainMailboxManager::setSession(EtchSessionMessage* session) {
+ mSession = session;
+}
+
+capu::uint64_t EtchPlainMailboxManager::count() {
+ return mMailboxes.count();
+}
\ No newline at end of file
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt?rev=1368503&r1=1368502&r2=1368503&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Thu Aug 2 14:57:46 2012
@@ -1,47 +1,47 @@
-#
-# 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.
-#
-
-# set include dirs
-include_directories (${PROJECT_SOURCE_DIR}/include)
-include_directories (${GTEST})
-include_directories (${GTEST}/include)
+#
+# 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.
+#
+
+# set include dirs
+include_directories (${PROJECT_SOURCE_DIR}/include)
+include_directories (${GTEST})
+include_directories (${GTEST}/include)
include_directories (${GMOCK})
include_directories (${GMOCK}/include)
-include_directories (${CAPU}/include/capu)
-
-
-IF (WIN32 AND BUILD_CHECK_MEMORY)
- include_directories (${VLD}/include)
- add_definitions (-DBUILD_CHECK_MEMORY)
-ENDIF (WIN32 AND BUILD_CHECK_MEMORY)
-
-add_executable (etch-cpp-test
- common/EtchInt32Test.cpp
- common/EtchBoolTest.cpp
- common/EtchByteTest.cpp
- common/EtchShortTest.cpp
- common/EtchLongTest.cpp
- common/EtchFloatTest.cpp
- common/EtchDoubleTest.cpp
- common/EtchStringTest.cpp
- common/EtchListTest.cpp
- common/EtchNativeArrayTest.cpp
- common/EtchHashTableTest.cpp
- common/EtchHashSetTest.cpp
+include_directories (${CAPU}/include/capu)
+
+
+IF (WIN32 AND BUILD_CHECK_MEMORY)
+ include_directories (${VLD}/include)
+ add_definitions (-DBUILD_CHECK_MEMORY)
+ENDIF (WIN32 AND BUILD_CHECK_MEMORY)
+
+add_executable (etch-cpp-test
+ common/EtchInt32Test.cpp
+ common/EtchBoolTest.cpp
+ common/EtchByteTest.cpp
+ common/EtchShortTest.cpp
+ common/EtchLongTest.cpp
+ common/EtchFloatTest.cpp
+ common/EtchDoubleTest.cpp
+ common/EtchStringTest.cpp
+ common/EtchListTest.cpp
+ common/EtchNativeArrayTest.cpp
+ common/EtchHashTableTest.cpp
+ common/EtchHashSetTest.cpp
common/EtchExceptionTest.cpp
common/EtchAuthenticationExceptionTest.cpp
common/EtchRuntimeExceptionTest.cpp
@@ -56,6 +56,7 @@ add_executable (etch-cpp-test
transport/EtchPacketizerTest.cpp
transport/EtchMessageTest.cpp
transport/EtchMessagizerTest.cpp
+ transport/EtchPlainMailboxManagerTest.cpp
serialization/EtchValidatorBooleanTest.cpp
serialization/EtchValidatorByteTest.cpp
serialization/EtchValidatorIntTest.cpp
@@ -83,35 +84,36 @@ add_executable (etch-cpp-test
serialization/EtchValidatorStructValueTest.cpp
serialization/EtchBinaryTaggedDataInputOutputTest.cpp
support/EtchFreePoolTest.cpp
+ support/EtchPlainMailboxTest.cpp
util/EtchCircularQueueTest.cpp
util/EtchUtilTest.cpp
- ${GTEST}/src/gtest-all.cc
+ ${GTEST}/src/gtest-all.cc
${GMOCK}/src/gmock-all.cc
- main.cpp
-)
-
-IF (UNIX)
+ main.cpp
+)
+
+IF (UNIX)
target_link_libraries (etch-cpp-test ${CAPU/lib/Linux_X86_32})
-ELSEIF(WIN32)
+ELSEIF(WIN32)
target_link_libraries (etch-cpp-test ${CAPU/lib/Windows_x86_32})
-ENDIF()
-
+ENDIF()
+
IF (UNIX)
target_link_libraries (etch-cpp-test etch-cpp pthread rt)
ELSEIF(WIN32)
target_link_libraries (etch-cpp-test etch-cpp)
ENDIF()
-
-IF (WIN32 AND BUILD_CHECK_MEMORY)
- file (COPY ${VLD}/vld.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
- file (COPY ${VLD}/bin/dbghelp.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
- file (COPY ${VLD}/bin/vld.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
-
- target_link_libraries (etch-cpp-test ${VLD}/lib/vld.lib)
-ENDIF (WIN32 AND BUILD_CHECK_MEMORY)
-
-IF (UNIX)
+
+IF (WIN32 AND BUILD_CHECK_MEMORY)
+ file (COPY ${VLD}/vld.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+ file (COPY ${VLD}/bin/dbghelp.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+ file (COPY ${VLD}/bin/vld.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
+
+ target_link_libraries (etch-cpp-test ${VLD}/lib/vld.lib)
+ENDIF (WIN32 AND BUILD_CHECK_MEMORY)
+
+IF (UNIX)
set_target_properties (etch-cpp-test PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
-ENDIF (UNIX)
-
-add_dependencies (etch-cpp Capu)
+ENDIF (UNIX)
+
+add_dependencies (etch-cpp Capu)
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp?rev=1368503&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/support/EtchPlainMailboxTest.cpp Thu Aug 2 14:57:46 2012
@@ -0,0 +1,208 @@
+/* $Id$
+ *
+ * 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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include "support/EtchPlainMailbox.h"
+#include "common/EtchList.h"
+
+class MockMailboxManager2 : public virtual EtchMailboxManager {
+public:
+
+ MockMailboxManager2() {
+ unregistered = false;
+ }
+ capu::bool_t unregistered;
+ EtchList<EtchMailbox::EtchElement *> list;
+
+ virtual status_t unregisterMailbox(EtchMailbox* mb) {
+ unregistered = true;
+ return ETCH_OK;
+ }
+
+ status_t redeliver(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg) {
+ return list.add(new EtchMailbox::EtchElement(sender, msg));
+ }
+
+ MOCK_METHOD2(getMailbox, status_t(EtchLong msgid, EtchMailbox*& result));
+
+ MOCK_METHOD2(sessionMessage, status_t(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchMessage> msg));
+
+ MOCK_METHOD3(transportCall, status_t(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage> msg, EtchMailbox*& result));
+
+ MOCK_METHOD2(transportMessage, status_t(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage> message));
+
+ MOCK_METHOD2(transportQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(transportControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ MOCK_METHOD1(transportNotify, status_t(capu::SmartPointer<EtchObject> event));
+
+ MOCK_METHOD0(getSession, EtchSessionMessage* ());
+
+ MOCK_METHOD1(setSession, void(EtchSessionMessage* session));
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
+
+ virtual ~MockMailboxManager2() {
+ EtchMailbox::EtchElement *el;
+ EtchList<EtchMailbox::EtchElement*>::Iterator it = list.begin();
+ while (it.hasNext()) {
+ it.next(&el);
+ delete el;
+ }
+ }
+};
+
+TEST(EtchPlainMessageBoxTest, constructorTest) {
+ MockMailboxManager2 manager;
+ EtchMailbox* mailbox = NULL;
+ EtchLong id(5);
+ mailbox = new EtchPlainMailbox(&manager, id);
+ EXPECT_TRUE(mailbox != NULL);
+ delete mailbox;
+}
+
+TEST(EtchPlainMessageBoxTest, closeDeliveryTest) {
+ MockMailboxManager2* manager = new MockMailboxManager2();
+
+ EtchMailbox* mailbox = NULL;
+ EtchLong id(5);
+ mailbox = new EtchPlainMailbox(manager, id);
+
+ //initial configuration
+ EXPECT_TRUE(true == mailbox->isEmpty());
+ EXPECT_TRUE(false == mailbox->isFull());
+ EXPECT_TRUE(false == mailbox->isClosed());
+ EXPECT_TRUE(false == manager->unregistered);
+
+ mailbox->message(NULL, NULL);
+
+ mailbox->closeDelivery();
+ //configuration after closing
+ EXPECT_TRUE(false == mailbox->isEmpty());
+ EXPECT_TRUE(true == mailbox->isFull());
+ EXPECT_TRUE(true == mailbox->isClosed());
+ EXPECT_TRUE(true == manager->unregistered);
+
+ delete mailbox;
+ delete manager;
+}
+
+TEST(EtchPlainMessageBoxTest, closeReadTest) {
+ MockMailboxManager2* manager = new MockMailboxManager2();
+
+ EtchMailbox* mailbox = NULL;
+ EtchLong id(5);
+ mailbox = new EtchPlainMailbox(manager, id);
+
+ //initial configuration
+ EXPECT_TRUE(true == mailbox->isEmpty());
+ EXPECT_TRUE(false == mailbox->isFull());
+ EXPECT_TRUE(false == mailbox->isClosed());
+ EXPECT_TRUE(false == manager->unregistered);
+
+ mailbox->message(NULL, NULL);
+
+
+ EXPECT_TRUE(ETCH_OK == mailbox->closeRead());
+
+ //configuration after closing
+ EXPECT_TRUE(true == mailbox->isEmpty());
+ EXPECT_TRUE(false == mailbox->isFull());
+ EXPECT_TRUE(true == mailbox->isClosed());
+ EXPECT_TRUE(true == manager->unregistered);
+ EXPECT_EQ(1, manager->list.size());
+
+ delete mailbox;
+ delete manager;
+}
+
+TEST(EtchPlainMessageBoxTest, fullTest) {
+ MockMailboxManager2* manager = new MockMailboxManager2();
+
+ EtchMailbox* mailbox = NULL;
+ EtchLong id(5);
+ mailbox = new EtchPlainMailbox(manager, id);
+
+ //initial configuration
+ EXPECT_TRUE(true == mailbox->isEmpty());
+ EXPECT_TRUE(false == mailbox->isFull());
+ EXPECT_TRUE(false == mailbox->isClosed());
+ EXPECT_TRUE(false == manager->unregistered);
+
+ mailbox->message(NULL, NULL);
+
+ //configuration after closing
+ EXPECT_TRUE(false == mailbox->isEmpty());
+ EXPECT_TRUE(true == mailbox->isFull());
+ EXPECT_TRUE(false == mailbox->isClosed());
+ EXPECT_TRUE(false == manager->unregistered);
+
+ //mailbox is full
+ EXPECT_TRUE(mailbox->isFull());
+
+ //not handled message because it mailbox is full
+ mailbox->message(NULL, NULL);
+ EXPECT_TRUE(false == mailbox->isEmpty());
+ EXPECT_TRUE(true == mailbox->isFull());
+ EXPECT_TRUE(false == mailbox->isClosed());
+ EXPECT_TRUE(false == manager->unregistered);
+
+ delete mailbox;
+ delete manager;
+}
+
+TEST(EtchPlainMessageBoxTest, readTest) {
+ MockMailboxManager2* manager = new MockMailboxManager2();
+
+ EtchMailbox* mailbox = NULL;
+ EtchLong id(5);
+ mailbox = new EtchPlainMailbox(manager, id);
+
+ //initial configuration
+ EXPECT_TRUE(true == mailbox->isEmpty());
+ EXPECT_TRUE(false == mailbox->isFull());
+ EXPECT_TRUE(false == mailbox->isClosed());
+ EXPECT_TRUE(false == manager->unregistered);
+
+ mailbox->message(NULL, NULL);
+
+ mailbox->closeDelivery();
+
+ //configuration after closing
+ EXPECT_TRUE(false == mailbox->isEmpty());
+ EXPECT_TRUE(true == mailbox->isFull());
+ EXPECT_TRUE(true == mailbox->isClosed());
+ EXPECT_TRUE(true == manager->unregistered);
+
+ //try to read now
+ EtchMailbox::EtchElement* element;
+ //there is one element in mailbox
+ EXPECT_TRUE(mailbox->read(element) == ETCH_OK);
+ delete element;
+
+ //now it is empty
+ EXPECT_TRUE(mailbox->read(element) == ETCH_ERROR);
+ delete mailbox;
+ delete manager;
+}
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp?rev=1368503&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPlainMailboxManagerTest.cpp Thu Aug 2 14:57:46 2012
@@ -0,0 +1,338 @@
+/* $Id$
+ *
+ * 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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+#include "support/EtchPlainMailbox.h"
+#include "transport/EtchPlainMailboxManager.h"
+#include "serialization/EtchDefaultValueFactory.h"
+
+class MockSession : public EtchSessionMessage {
+public:
+
+ status_t sessionMessage(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchMessage> buf) {
+ return ETCH_OK;
+ }
+
+ status_t sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result) {
+ return ETCH_OK;
+ }
+
+ status_t sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+ return ETCH_OK;
+ }
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
+ return ETCH_OK;
+ }
+};
+
+class MockTransport : public EtchTransportMessage {
+public:
+
+ status_t transportMessage(capu::SmartPointer<EtchWho> recipient, capu::SmartPointer<EtchMessage> message) {
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD0(getSession, EtchSessionMessage* ());
+
+ void setSession(EtchSessionMessage* session) {
+
+ }
+
+ status_t transportQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result) {
+ return ETCH_OK;
+ }
+
+ status_t transportControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value) {
+ return ETCH_OK;
+ }
+
+ status_t transportNotify(capu::SmartPointer<EtchObject> event) {
+ return ETCH_OK;
+ }
+};
+
+class MockDefaultValueFactory {
+public:
+ EtchTypeMap types;
+ EtchClass2TypeMap class2type;
+ EtchDefaultValueFactory * factory;
+ /**
+ * Constructs the MyValueFactory.
+ * @param uri
+ */
+public:
+
+ MockDefaultValueFactory(EtchString uri) {
+ EtchDefaultValueFactory::Init(&types, &class2type);
+ factory = new EtchDefaultValueFactory(uri, &types, &class2type);
+ }
+
+ ~MockDefaultValueFactory() {
+ delete factory;
+ types.clear();
+ }
+};
+
+TEST(EtchPlainMailboxManager, constructorTest) {
+ MockTransport transport;
+ MockSession session;
+ MockDefaultValueFactory *factory;
+ EtchString uri("tcp://127.0.0.1:4001");
+ factory = new MockDefaultValueFactory(uri);
+ //created value factory
+ EtchURL u(uri);
+ EtchMailboxManager * manager = NULL;
+ manager = new EtchPlainMailboxManager(&transport, &u, NULL);
+
+ EXPECT_TRUE(manager != NULL);
+ manager->setSession(&session);
+
+ delete manager;
+ delete factory;
+}
+
+TEST(EtchPlainMailboxManager, transportMessageTest) {
+ EtchString uri("tcp://127.0.0.1:4001");
+ MockDefaultValueFactory *factory;
+ factory = new MockDefaultValueFactory(uri);
+ //initialization
+ EtchType * type;
+ capu::SmartPointer<EtchValidator> val = NULL;
+ EtchValidatorLong::Get(0, val);
+
+ factory->types.get("add", type);
+ type->putValidator(EtchDefaultValueFactory::_mf__messageId, val);
+ capu::SmartPointer<EtchMessage> message = new EtchMessage(type, factory->factory);
+
+ capu::int64_t id;
+ EXPECT_TRUE(ETCH_OK != message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+
+ MockTransport transport;
+ MockSession session;
+
+ EtchURL u(uri);
+ EtchPlainMailboxManager * manager = NULL;
+ manager = new EtchPlainMailboxManager(&transport, &u, NULL);
+
+ manager->setSession(&session);
+
+ EXPECT_TRUE(ETCH_OK == manager->transportMessage(NULL, message));
+ EXPECT_EQ(0, manager->count());
+ EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+
+ EtchMailbox *mail;
+ EXPECT_TRUE(ETCH_OK != manager->getMailbox(id, mail));
+
+ message->clear();
+ delete manager;
+ delete factory;
+}
+
+TEST(EtchPlainMailboxManager, transportResultMessageTest) {
+ EtchString uri("tcp://127.0.0.1:4001");
+ MockDefaultValueFactory *factory;
+ factory = new MockDefaultValueFactory(uri);
+ //initialization
+ EtchType * type;
+ capu::SmartPointer<EtchValidator> val = NULL;
+ EtchValidatorLong::Get(0, val);
+
+ factory->types.get("add_result", type);
+ type->putValidator(EtchDefaultValueFactory::_mf__messageId, val);
+ type->putValidator(EtchDefaultValueFactory::_mf__inReplyTo, val);
+ capu::SmartPointer<EtchMessage> message = new EtchMessage(type, factory->factory);
+
+ capu::int64_t id;
+ EXPECT_TRUE(ETCH_OK != message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+
+ message->setInReplyToMessageId(1L);
+
+ MockTransport transport;
+ MockSession session;
+
+ EtchURL u(uri);
+ EtchPlainMailboxManager * manager = NULL;
+ manager = new EtchPlainMailboxManager(&transport, &u, NULL);
+
+ manager->setSession(&session);
+
+ EXPECT_TRUE(ETCH_OK == manager->transportMessage(NULL, message));
+ EXPECT_EQ(0, manager->count());
+ EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK == message->getInReplyToMessageId(id));
+ EXPECT_TRUE(id == 1L);
+ EtchMailbox *mail;
+ EXPECT_TRUE(ETCH_OK != manager->getMailbox(id, mail));
+
+ message->clear();
+ delete manager;
+ delete factory;
+}
+
+TEST(EtchPlainMailboxManager, transportCallTest) {
+ EtchString uri("tcp://127.0.0.1:4001");
+ MockDefaultValueFactory *factory;
+ factory = new MockDefaultValueFactory(uri);
+ //initialization
+ EtchType * type;
+ capu::SmartPointer<EtchValidator> val = NULL;
+ EtchValidatorLong::Get(0, val);
+
+ factory->types.get("add", type);
+ type->putValidator(EtchDefaultValueFactory::_mf__messageId, val);
+ capu::SmartPointer<EtchMessage> message = new EtchMessage(type, factory->factory);
+
+ capu::int64_t id;
+ EXPECT_TRUE(ETCH_OK != message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+
+ MockTransport transport;
+ MockSession session;
+
+ EtchURL u(uri);
+ EtchPlainMailboxManager * manager = NULL;
+ manager = new EtchPlainMailboxManager(&transport, &u, NULL);
+
+ manager->setSession(&session);
+ //in order to notify upper layers that the connection is open
+ manager->sessionNotify(new EtchString(EtchSession::UP));
+
+ EtchMailbox *mail;
+ EXPECT_TRUE(ETCH_OK == manager->transportCall(NULL, message, mail));
+ EXPECT_EQ(1, manager->count());
+ EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+
+ EXPECT_TRUE(ETCH_OK == manager->getMailbox(id, mail));
+
+ message->clear();
+ delete manager;
+ delete factory;
+}
+
+TEST(EtchPlainMailboxManager, replicatedTransportCallTest) {
+ EtchString uri("tcp://127.0.0.1:4001");
+ MockDefaultValueFactory *factory;
+ factory = new MockDefaultValueFactory(uri);
+ //initialization
+ EtchType * type;
+ capu::SmartPointer<EtchValidator> val = NULL;
+ EtchValidatorLong::Get(0, val);
+
+ factory->types.get("add", type);
+ type->putValidator(EtchDefaultValueFactory::_mf__messageId, val);
+ capu::SmartPointer<EtchMessage> message = new EtchMessage(type, factory->factory);
+
+ capu::int64_t id;
+ EXPECT_TRUE(ETCH_OK != message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+
+ MockTransport transport;
+ MockSession session;
+
+ // test sending a call message that has already been sent (has a message id)
+ message->setMessageId(2);
+
+ EtchURL u(uri);
+ EtchPlainMailboxManager * manager = NULL;
+ manager = new EtchPlainMailboxManager(&transport, &u, NULL);
+
+ manager->setSession(&session);
+ //in order to notify upper layers that the connection is open
+ manager->sessionNotify(new EtchString(EtchSession::UP));
+
+ EtchMailbox *mail;
+ EXPECT_TRUE(ETCH_ERROR == manager->transportCall(NULL, message, mail));
+ //should not create a mailbox
+ EXPECT_EQ(0, manager->count());
+ EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+ //there should be no mailbox
+ EXPECT_TRUE(ETCH_OK != manager->getMailbox(id, mail));
+
+ message->clear();
+ delete manager;
+ delete factory;
+}
+
+TEST(EtchPlainMailboxManager, sessionMessageTest) {
+ EtchString uri("tcp://127.0.0.1:4001");
+ MockDefaultValueFactory *factory;
+ factory = new MockDefaultValueFactory(uri);
+ //initialization
+ EtchType * type;
+ EtchType * replyType;
+ capu::SmartPointer<EtchValidator> val = NULL;
+ EtchValidatorLong::Get(0, val);
+
+ factory->types.get("add_result", replyType);
+ factory->types.get("add", type);
+ type->putValidator(EtchDefaultValueFactory::_mf__messageId, val);
+ replyType->putValidator(EtchDefaultValueFactory::_mf__inReplyTo, val);
+ replyType->putValidator(EtchDefaultValueFactory::_mf__messageId, val);
+ capu::SmartPointer<EtchMessage> message = new EtchMessage(type, factory->factory);
+
+ capu::int64_t id;
+ EXPECT_TRUE(ETCH_OK != message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+
+ MockTransport transport;
+ MockSession session;
+
+ EtchURL u(uri);
+ EtchPlainMailboxManager * manager = NULL;
+ manager = new EtchPlainMailboxManager(&transport, &u, NULL);
+
+ manager->setSession(&session);
+ //in order to notify upper layers that the connection is open
+ manager->sessionNotify(new EtchString(EtchSession::UP));
+
+ //perform the call
+ EtchMailbox *mail;
+ EXPECT_TRUE(ETCH_OK == manager->transportCall(NULL, message, mail));
+ EXPECT_EQ(1, manager->count());
+ EXPECT_TRUE(ETCH_OK == message->getMessageId(id));
+ EXPECT_TRUE(ETCH_OK != message->getInReplyToMessageId(id));
+ //get the created mailbox
+ EXPECT_TRUE(ETCH_OK == manager->getMailbox(id, mail));
+
+ capu::SmartPointer<EtchMessage> replymessage;
+ //create a reply message
+ message->createReplyMessage(replyType, replymessage);
+ EXPECT_TRUE(ETCH_OK == replymessage->getInReplyToMessageId(id));
+ capu::SmartPointer<EtchMessage> replymess = replymessage;
+
+ //test the notification mechanism of mailbox manager
+ EXPECT_TRUE(ETCH_OK == manager->sessionMessage(NULL, replymess));
+ EtchMailbox::EtchElement* x;
+ //check if the reply message is delivered to the correct mailbox
+ EXPECT_TRUE(ETCH_OK == mail->read(x));
+ EXPECT_TRUE(NULL == x->mSender.get());
+ EXPECT_TRUE(replymessage.get() == x->mMsg.get());
+
+ //deallocations
+ delete x;
+ delete manager;
+ delete factory;
+}
+