summaryrefslogtreecommitdiff
path: root/cpp/bindings/qpid/dotnet/src/Session.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/bindings/qpid/dotnet/src/Session.cpp')
-rw-r--r--cpp/bindings/qpid/dotnet/src/Session.cpp574
1 files changed, 321 insertions, 253 deletions
diff --git a/cpp/bindings/qpid/dotnet/src/Session.cpp b/cpp/bindings/qpid/dotnet/src/Session.cpp
index 0e918769a3..929dddf80c 100644
--- a/cpp/bindings/qpid/dotnet/src/Session.cpp
+++ b/cpp/bindings/qpid/dotnet/src/Session.cpp
@@ -45,27 +45,36 @@ namespace Messaging {
/// Session is a managed wrapper for a ::qpid::messaging::Session
/// </summary>
+ // Disallow access if object has been destroyed.
+ void Session::ThrowIfDisposed()
+ {
+ if (IsDisposed)
+ throw gcnew ObjectDisposedException (GetType()->FullName);
+ }
+
+
// unmanaged clone
- Session::Session(const ::qpid::messaging::Session & session,
- Org::Apache::Qpid::Messaging::Connection ^ connRef) :
- parentConnectionp(connRef)
+ Session::Session(const ::qpid::messaging::Session & session,
+ Org::Apache::Qpid::Messaging::Connection ^ connRef) :
+ parentConnectionp(connRef)
{
System::Exception ^ newException = nullptr;
- try
- {
- sessionp = new ::qpid::messaging::Session (session);
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ privateLock = gcnew System::Object();
+ nativeObjPtr = new ::qpid::messaging::Session (session);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -79,12 +88,15 @@ namespace Messaging {
// Finalizer
Session::!Session()
{
- msclr::lock lk(this);
-
- if (NULL != sessionp)
+ if (NULL != nativeObjPtr)
{
- delete sessionp;
- sessionp = NULL;
+ privateLock = gcnew System::Object();
+
+ if (NULL != nativeObjPtr)
+ {
+ delete nativeObjPtr;
+ nativeObjPtr = NULL;
+ }
}
}
@@ -95,22 +107,23 @@ namespace Messaging {
{
System::Exception ^ newException = nullptr;
- try
- {
- sessionp = new ::qpid::messaging::Session(
- *(const_cast<Session ^>(session)->NativeSession));
-
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ privateLock = gcnew System::Object();
+ nativeObjPtr = new ::qpid::messaging::Session(
+ *(const_cast<Session ^>(session)->NativeSession));
+
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Copy constructor implicitly dereferenced (C++)
@@ -119,83 +132,93 @@ namespace Messaging {
{
System::Exception ^ newException = nullptr;
- try
- {
- sessionp = new ::qpid::messaging::Session(
- *(const_cast<Session %>(session).NativeSession));
-
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ privateLock = gcnew System::Object();
+ nativeObjPtr = new ::qpid::messaging::Session(
+ *(const_cast<Session %>(session).NativeSession));
+
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Close()
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->close();
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->close();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Commit()
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->commit();
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->commit();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Rollback()
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->rollback();
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->rollback();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Acknowledge()
@@ -205,22 +228,25 @@ namespace Messaging {
void Session::Acknowledge(bool sync)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->acknowledge(sync);
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->acknowledge(sync);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Acknowledge(Message ^ message)
@@ -230,22 +256,25 @@ namespace Messaging {
void Session::Acknowledge(Message ^ message, bool sync)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->acknowledge(*(message->NativeMessage), sync);
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->acknowledge(*(message->NativeMessage), sync);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::AcknowledgeUpTo(Message ^ message)
@@ -255,62 +284,71 @@ namespace Messaging {
void Session::AcknowledgeUpTo(Message ^ message, bool sync)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->acknowledgeUpTo(*(message->NativeMessage), sync);
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->acknowledgeUpTo(*(message->NativeMessage), sync);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Reject(Message ^ message)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->::qpid::messaging::Session::reject(*(message->NativeMessage));
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->::qpid::messaging::Session::reject(*(message->NativeMessage));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Release(Message ^ message)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->::qpid::messaging::Session::release(*(message->NativeMessage));
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->::qpid::messaging::Session::release(*(message->NativeMessage));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Session::Sync()
@@ -320,22 +358,25 @@ namespace Messaging {
void Session::Sync(bool block)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->sync(block);
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->sync(block);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// next(receiver)
@@ -346,18 +387,21 @@ namespace Messaging {
bool Session::NextReceiver(Receiver ^ rcvr, Duration ^ timeout)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- // create a duration object
+ try
+ {
+ // create a duration object
::qpid::messaging::Duration dur(timeout->Milliseconds);
- // wait for the next received message
- return sessionp->nextReceiver(*(rcvr->NativeReceiver), dur);
- }
- catch (const ::qpid::types::Exception & error)
- {
+ // wait for the next received message
+ return nativeObjPtr->nextReceiver(*(rcvr->NativeReceiver), dur);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
if ("No message to fetch" == errmsg){
return false;
@@ -365,10 +409,10 @@ namespace Messaging {
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
return true;
}
@@ -381,19 +425,22 @@ namespace Messaging {
Receiver ^ Session::NextReceiver(Duration ^ timeout)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
try
{
::qpid::messaging::Duration dur(timeout->Milliseconds);
- ::qpid::messaging::Receiver receiver = sessionp->::qpid::messaging::Session::nextReceiver(dur);
+ ::qpid::messaging::Receiver receiver = nativeObjPtr->::qpid::messaging::Session::nextReceiver(dur);
Receiver ^ newRcvr = gcnew Receiver(receiver, this);
return newRcvr;
- }
- catch (const ::qpid::types::Exception & error)
+ }
+ catch (const ::qpid::types::Exception & error)
{
String ^ errmsg = gcnew String(error.what());
if ("No message to fetch" == errmsg)
@@ -403,30 +450,33 @@ namespace Messaging {
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
- return nullptr;
+ return nullptr;
}
Sender ^ Session::CreateSender (System::String ^ address)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
Sender ^ newSender = nullptr;
try
{
// create the sender
- ::qpid::messaging::Sender sender =
- sessionp->::qpid::messaging::Session::createSender(QpidMarshal::ToNative(address));
+ ::qpid::messaging::Sender sender =
+ nativeObjPtr->::qpid::messaging::Session::createSender(QpidMarshal::ToNative(address));
// create a managed sender
newSender = gcnew Sender(sender, this);
- }
- catch (const ::qpid::types::Exception & error)
+ }
+ catch (const ::qpid::types::Exception & error)
{
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
@@ -435,16 +485,16 @@ namespace Messaging {
{
if (newException != nullptr)
{
- if (newSender != nullptr)
- {
- delete newSender;
- }
+ if (newSender != nullptr)
+ {
+ delete newSender;
+ }
}
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
return newSender;
}
@@ -452,19 +502,22 @@ namespace Messaging {
Sender ^ Session::CreateSender (Address ^ address)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
Sender ^ newSender = nullptr;
try
{
// allocate a native sender
- ::qpid::messaging::Sender sender =
- sessionp->::qpid::messaging::Session::createSender(*(address->NativeAddress));
+ ::qpid::messaging::Sender sender =
+ nativeObjPtr->::qpid::messaging::Session::createSender(*(address->NativeAddress));
// create a managed sender
newSender = gcnew Sender(sender, this);
- }
- catch (const ::qpid::types::Exception & error)
+ }
+ catch (const ::qpid::types::Exception & error)
{
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
@@ -473,92 +526,98 @@ namespace Messaging {
{
if (newException != nullptr)
{
- if (newSender != nullptr)
- {
- delete newSender;
- }
+ if (newSender != nullptr)
+ {
+ delete newSender;
+ }
}
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
return newSender;
}
- Receiver ^ Session::CreateReceiver(System::String ^ address)
+ Receiver ^ Session::CreateReceiver(System::String ^ address)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
Receiver ^ newReceiver = nullptr;
- try
- {
+ try
+ {
// create the receiver
- ::qpid::messaging::Receiver receiver =
- sessionp->createReceiver(QpidMarshal::ToNative(address));
+ ::qpid::messaging::Receiver receiver =
+ nativeObjPtr->createReceiver(QpidMarshal::ToNative(address));
// create a managed receiver
newReceiver = gcnew Receiver(receiver, this);
- }
- catch (const ::qpid::types::Exception & error)
- {
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- finally
- {
+ finally
+ {
if (newException != nullptr)
- {
- if (newReceiver != nullptr)
- {
- delete newReceiver;
- }
+ {
+ if (newReceiver != nullptr)
+ {
+ delete newReceiver;
+ }
}
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
return newReceiver;
}
- Receiver ^ Session::CreateReceiver(Address ^ address)
+ Receiver ^ Session::CreateReceiver(Address ^ address)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
Receiver ^ newReceiver = nullptr;
- try
- {
+ try
+ {
// create the receiver
::qpid::messaging::Receiver receiver =
- sessionp->createReceiver(*(address->NativeAddress));
+ nativeObjPtr->createReceiver(*(address->NativeAddress));
// create a managed receiver
newReceiver = gcnew Receiver(receiver, this);
- }
- catch (const ::qpid::types::Exception & error)
- {
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- finally
- {
+ finally
+ {
if (newException != nullptr)
- {
- if (newReceiver != nullptr)
- {
- delete newReceiver;
- }
+ {
+ if (newReceiver != nullptr)
+ {
+ delete newReceiver;
+ }
}
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
return newReceiver;
}
@@ -566,35 +625,38 @@ namespace Messaging {
Sender ^ Session::GetSender(System::String ^ name)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
Sender ^ newSender = nullptr;
try
{
- ::qpid::messaging::Sender senderp =
- sessionp->::qpid::messaging::Session::getSender(QpidMarshal::ToNative(name));
+ ::qpid::messaging::Sender senderp =
+ nativeObjPtr->::qpid::messaging::Session::getSender(QpidMarshal::ToNative(name));
newSender = gcnew Sender(senderp, this);
- }
- catch (const ::qpid::types::Exception & error)
+ }
+ catch (const ::qpid::types::Exception & error)
{
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- finally
- {
+ finally
+ {
if (newException != nullptr)
- {
- if (newSender != nullptr)
- {
- delete newSender;
- }
+ {
+ if (newSender != nullptr)
+ {
+ delete newSender;
+ }
}
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
return newSender;
}
@@ -603,35 +665,38 @@ namespace Messaging {
Receiver ^ Session::GetReceiver(System::String ^ name)
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
Receiver ^ newReceiver = nullptr;
try
{
- ::qpid::messaging::Receiver receiver =
- sessionp->::qpid::messaging::Session::getReceiver(QpidMarshal::ToNative(name));
+ ::qpid::messaging::Receiver receiver =
+ nativeObjPtr->::qpid::messaging::Session::getReceiver(QpidMarshal::ToNative(name));
newReceiver = gcnew Receiver(receiver, this);
- }
- catch (const ::qpid::types::Exception & error)
+ }
+ catch (const ::qpid::types::Exception & error)
{
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- finally
- {
+ finally
+ {
if (newException != nullptr)
- {
- if (newReceiver != nullptr)
- {
- delete newReceiver;
- }
+ {
+ if (newReceiver != nullptr)
+ {
+ delete newReceiver;
+ }
}
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
return newReceiver;
}
@@ -640,21 +705,24 @@ namespace Messaging {
void Session::CheckError()
{
+ msclr::lock lk(privateLock);
+ ThrowIfDisposed();
+
System::Exception ^ newException = nullptr;
- try
- {
- sessionp->checkError();
- }
- catch (const ::qpid::types::Exception & error)
- {
+ try
+ {
+ nativeObjPtr->checkError();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
String ^ errmsg = gcnew String(error.what());
newException = gcnew QpidException(errmsg);
}
- if (newException != nullptr)
- {
- throw newException;
- }
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
}}}}