diff --git a/openwire-dotnet/src/OpenWire.Client/Connection.cs b/openwire-dotnet/src/OpenWire.Client/Connection.cs new file mode 100755 index 0000000000..486f021ba9 --- /dev/null +++ b/openwire-dotnet/src/OpenWire.Client/Connection.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections; +using OpenWire.Client.Commands; +using OpenWire.Client.Core; + +namespace OpenWire.Client { + /// + /// Represents a connection with a message broker + /// + public class Connection : IConnection { + + private Transport transport; + IList sessions = new ArrayList(); + private bool transacted; + private AcknowledgementMode acknowledgementMode; + + /// + /// Creates a new session to work on this connection + /// + public ISession CreateSession() { + return CreateSession(transacted, acknowledgementMode); + } + + /// + /// Creates a new session to work on this connection + /// + public ISession CreateSession(bool transacted, AcknowledgementMode acknowledgementMode) { + Session session = new Session(this, acknowledgementMode); + sessions.Add(session); + return session; + } + + public void Dispose() { + foreach (Session session in sessions) { + session.Dispose(); + } + } + + // Properties + + public Transport Transport { + get { return transport; } + set { this.transport = value; } + } + + public bool Transacted { + get { return transacted; } + set { this.transacted = value; } + } + + public AcknowledgementMode AcknowledgementMode { + get { return acknowledgementMode; } + set { this.acknowledgementMode = value; } + } + } +} diff --git a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQDestination.cs b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQDestination.cs index 47b4c5bc0c..a1901bbdee 100755 --- a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQDestination.cs +++ b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQDestination.cs @@ -7,7 +7,7 @@ namespace OpenWire.Client.Core { /// /// Summary description for ActiveMQDestination. /// - public abstract class ActiveMQDestination : AbstractCommand, Destination { + public abstract class ActiveMQDestination : AbstractCommand, IDestination { /** * Topic Destination object @@ -165,7 +165,7 @@ namespace OpenWire.Client.Core { * @return a descriptive string for this queue or topic */ public static String Inspect(ActiveMQDestination destination) { - if (destination is Topic) { + if (destination is ITopic) { return "Topic(" + destination.ToString() + ")"; } else { return "Queue(" + destination.ToString() + ")"; @@ -177,20 +177,20 @@ namespace OpenWire.Client.Core { * @return @throws JMSException * @throws javax.jms.JMSException */ - public static ActiveMQDestination transformDestination(Destination destination) { + public static ActiveMQDestination transformDestination(IDestination destination) { ActiveMQDestination result = null; if (destination != null) { if (destination is ActiveMQDestination) { result = (ActiveMQDestination) destination; } else { - if (destination is TemporaryQueue) { - result = new ActiveMQTempQueue(((Queue) destination).QueueName); - } else if (destination is TemporaryTopic) { - result = new ActiveMQTempTopic(((Topic) destination).TopicName); - } else if (destination is Queue) { - result = new ActiveMQQueue(((Queue) destination).QueueName); - } else if (destination is Topic) { - result = new ActiveMQTopic(((Topic) destination).TopicName); + if (destination is ITemporaryQueue) { + result = new ActiveMQTempQueue(((IQueue) destination).QueueName); + } else if (destination is ITemporaryTopic) { + result = new ActiveMQTempTopic(((ITopic) destination).TopicName); + } else if (destination is IQueue) { + result = new ActiveMQQueue(((IQueue) destination).QueueName); + } else if (destination is ITopic) { + result = new ActiveMQTopic(((ITopic) destination).TopicName); } } } diff --git a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQQueue.cs b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQQueue.cs index a382512db7..12e391e689 100755 --- a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQQueue.cs +++ b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQQueue.cs @@ -7,7 +7,7 @@ namespace OpenWire.Client.Core { /// /// Summary description for ActiveMQQueue. /// - public class ActiveMQQueue : ActiveMQDestination, Queue { + public class ActiveMQQueue : ActiveMQDestination, IQueue { public const byte ID_ActiveMQQueue = 100; public ActiveMQQueue() : base() { diff --git a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTempQueue.cs b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTempQueue.cs index 3771d312cd..b3e0694074 100755 --- a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTempQueue.cs +++ b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTempQueue.cs @@ -7,7 +7,7 @@ namespace OpenWire.Client.Core { /// /// Summary description for ActiveMQTempQueue. /// - public class ActiveMQTempQueue : ActiveMQDestination, TemporaryQueue { + public class ActiveMQTempQueue : ActiveMQDestination, ITemporaryQueue { public const byte ID_ActiveMQTempQueue = 102; public ActiveMQTempQueue() : base() { diff --git a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTempTopic.cs b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTempTopic.cs index ea2564fcc6..a6ea40a255 100755 --- a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTempTopic.cs +++ b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTempTopic.cs @@ -7,7 +7,7 @@ namespace OpenWire.Client.Core { /// /// Summary description for ActiveMQTempTopic. /// - public class ActiveMQTempTopic : ActiveMQDestination, TemporaryTopic { + public class ActiveMQTempTopic : ActiveMQDestination, ITemporaryTopic { public const byte ID_ActiveMQTempTopic = 103; public ActiveMQTempTopic() : base() { diff --git a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTopic.cs b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTopic.cs index 4dc2eaaeda..063fe2c0da 100755 --- a/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTopic.cs +++ b/openwire-dotnet/src/OpenWire.Client/Core/ActiveMQTopic.cs @@ -7,7 +7,7 @@ namespace OpenWire.Client.Core { /// /// Summary description for ActiveMQTopic. /// - public class ActiveMQTopic : ActiveMQDestination, Topic { + public class ActiveMQTopic : ActiveMQDestination, ITopic { public const byte ID_ActiveMQTopic = 101; public ActiveMQTopic() : base() { diff --git a/openwire-dotnet/src/OpenWire.Client/Core/FutureResponse.cs b/openwire-dotnet/src/OpenWire.Client/Core/FutureResponse.cs new file mode 100755 index 0000000000..d21b4f23c6 --- /dev/null +++ b/openwire-dotnet/src/OpenWire.Client/Core/FutureResponse.cs @@ -0,0 +1,44 @@ +using System; +using System.Threading; + +using OpenWire.Client; +using OpenWire.Client.Commands; + +namespace OpenWire.Client.Core { + /// + /// Handles asynchronous responses + /// + public class FutureResponse : IAsyncResult { + + private Response response; + private Mutex asyncWaitHandle = new Mutex(); + private bool isCompleted; + + public WaitHandle AsyncWaitHandle { + get { return asyncWaitHandle; } + } + + public object AsyncState { + get { return response; } + set { response = (Response) value; } + } + + public bool IsCompleted { + get { return isCompleted; } + } + + public bool CompletedSynchronously { + get { return false; } + } + + public Response Response { + get { return response; } + set { + asyncWaitHandle.WaitOne(); + response = value; + isCompleted = true; + asyncWaitHandle.ReleaseMutex(); + } + } + } +} diff --git a/openwire-dotnet/src/OpenWire.Client/Core/Transport.cs b/openwire-dotnet/src/OpenWire.Client/Core/Transport.cs new file mode 100755 index 0000000000..a1f3903e91 --- /dev/null +++ b/openwire-dotnet/src/OpenWire.Client/Core/Transport.cs @@ -0,0 +1,25 @@ +using System; + +using OpenWire.Client; +using OpenWire.Client.Commands; +using OpenWire.Client.Core; + +namespace OpenWire.Client.Core { + + public delegate void CommandHandler(Transport sender, Command command); + public delegate void ExceptionHandler(Transport sender, Exception command); + + /// + /// Represents the logical networking transport layer. + /// + public interface Transport { + void Oneway(Command command); + + FutureResponse AsyncRequest(Command command); + + Response Request(Command command); + + event CommandHandler Command; + event ExceptionHandler Exception; + } +} diff --git a/openwire-dotnet/src/OpenWire.Client/IConnection.cs b/openwire-dotnet/src/OpenWire.Client/IConnection.cs new file mode 100755 index 0000000000..b44d49726e --- /dev/null +++ b/openwire-dotnet/src/OpenWire.Client/IConnection.cs @@ -0,0 +1,39 @@ +using System; +using OpenWire.Client.Commands; + +namespace OpenWire.Client { + + public enum AcknowledgementMode { + Unknown, AutoAcknowledge, ClientAcknowledge, Transactional + } + + + /// + /// Represents a connection with a message broker + /// + public interface IConnection : IDisposable { + + /// + /// Creates a new session to work on this connection + /// + ISession CreateSession(); + + /// + /// Creates a new session to work on this connection + /// + ISession CreateSession(bool transacted, AcknowledgementMode acknowledgementMode); + + + // Properties + + bool Transacted { + get; + set; + } + + AcknowledgementMode AcknowledgementMode { + get; + set; + } + } +} diff --git a/openwire-dotnet/src/OpenWire.Client/Destination.cs b/openwire-dotnet/src/OpenWire.Client/IDestination.cs similarity index 81% rename from openwire-dotnet/src/OpenWire.Client/Destination.cs rename to openwire-dotnet/src/OpenWire.Client/IDestination.cs index 303bc1e08a..87f2f57138 100755 --- a/openwire-dotnet/src/OpenWire.Client/Destination.cs +++ b/openwire-dotnet/src/OpenWire.Client/IDestination.cs @@ -5,6 +5,6 @@ namespace OpenWire.Client { /// /// Summary description for Destination. /// - public interface Destination { + public interface IDestination { } } diff --git a/openwire-dotnet/src/OpenWire.Client/Queue.cs b/openwire-dotnet/src/OpenWire.Client/IQueue.cs similarity index 70% rename from openwire-dotnet/src/OpenWire.Client/Queue.cs rename to openwire-dotnet/src/OpenWire.Client/IQueue.cs index 3ad258c5ea..f41782826a 100755 --- a/openwire-dotnet/src/OpenWire.Client/Queue.cs +++ b/openwire-dotnet/src/OpenWire.Client/IQueue.cs @@ -3,9 +3,9 @@ using OpenWire.Client.Commands; namespace OpenWire.Client { /// - /// Summary description for Queue. + /// Summary description for IQueue. /// - public interface Queue : Destination { + public interface IQueue : IDestination { String QueueName { get; diff --git a/openwire-dotnet/src/OpenWire.Client/ISession.cs b/openwire-dotnet/src/OpenWire.Client/ISession.cs new file mode 100755 index 0000000000..ff81479404 --- /dev/null +++ b/openwire-dotnet/src/OpenWire.Client/ISession.cs @@ -0,0 +1,11 @@ +using System; +using OpenWire.Client.Commands; + +namespace OpenWire.Client { + /// + /// Represents a single unit of work on an IConnection. + /// So the ISession can be used to perform transactional receive and sends + /// + public interface ISession { + } +} diff --git a/openwire-dotnet/src/OpenWire.Client/TemporaryQueue.cs b/openwire-dotnet/src/OpenWire.Client/ITemporaryQueue.cs similarity index 54% rename from openwire-dotnet/src/OpenWire.Client/TemporaryQueue.cs rename to openwire-dotnet/src/OpenWire.Client/ITemporaryQueue.cs index 7bdb1c59ee..9c48c7b0d2 100755 --- a/openwire-dotnet/src/OpenWire.Client/TemporaryQueue.cs +++ b/openwire-dotnet/src/OpenWire.Client/ITemporaryQueue.cs @@ -3,8 +3,8 @@ using OpenWire.Client.Commands; namespace OpenWire.Client { /// - /// Summary description for TemporaryQueue. + /// Summary description for ITemporaryQueue. /// - public interface TemporaryQueue : Destination { + public interface ITemporaryQueue : IDestination { } } diff --git a/openwire-dotnet/src/OpenWire.Client/TemporaryTopic.cs b/openwire-dotnet/src/OpenWire.Client/ITemporaryTopic.cs similarity index 76% rename from openwire-dotnet/src/OpenWire.Client/TemporaryTopic.cs rename to openwire-dotnet/src/OpenWire.Client/ITemporaryTopic.cs index 060525eb9f..462f7c038d 100755 --- a/openwire-dotnet/src/OpenWire.Client/TemporaryTopic.cs +++ b/openwire-dotnet/src/OpenWire.Client/ITemporaryTopic.cs @@ -5,6 +5,6 @@ namespace OpenWire.Client { /// /// Summary description for TemporaryTopic. /// - public interface TemporaryTopic : Destination { + public interface ITemporaryTopic : IDestination { } } diff --git a/openwire-dotnet/src/OpenWire.Client/Topic.cs b/openwire-dotnet/src/OpenWire.Client/ITopic.cs similarity index 70% rename from openwire-dotnet/src/OpenWire.Client/Topic.cs rename to openwire-dotnet/src/OpenWire.Client/ITopic.cs index eb76667f25..5815ce8053 100755 --- a/openwire-dotnet/src/OpenWire.Client/Topic.cs +++ b/openwire-dotnet/src/OpenWire.Client/ITopic.cs @@ -3,9 +3,9 @@ using OpenWire.Client.Commands; namespace OpenWire.Client { /// - /// Summary description for Topic. + /// Summary description for ITopic. /// - public interface Topic : Destination { + public interface ITopic : IDestination { String TopicName { get; diff --git a/openwire-dotnet/src/OpenWire.Client/Session.cs b/openwire-dotnet/src/OpenWire.Client/Session.cs new file mode 100755 index 0000000000..f6131b8651 --- /dev/null +++ b/openwire-dotnet/src/OpenWire.Client/Session.cs @@ -0,0 +1,28 @@ +using System; +using OpenWire.Client.Commands; +using OpenWire.Client.Core; + +namespace OpenWire.Client { + /// + /// Default provider of ISession + /// + public class Session : ISession, IDisposable { + private Connection connection; + private AcknowledgementMode acknowledgementMode; + + public Session(Connection connection, AcknowledgementMode acknowledgementMode) { + this.connection = connection; + this.acknowledgementMode = acknowledgementMode; + } + + public void Dispose() { + } + + public void Acknowledge(Message message) { + if (acknowledgementMode == AcknowledgementMode.ClientAcknowledge) { + MessageAck ack = new MessageAck(); + connection.Transport.Request(ack); + } + } + } +}