activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r367642 - in /incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client: ./ Commands/ Core/ IO/
Date Tue, 10 Jan 2006 15:29:10 GMT
Author: jstrachan
Date: Tue Jan 10 07:28:53 2006
New Revision: 367642

URL: http://svn.apache.org/viewcvs?rev=367642&view=rev
Log:
added support for exceptions and for IConnectionFactory

Added:
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/BrokerException.cs   (with
props)
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/ConnectionFactory.cs   (with
props)
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/BrokerError.cs   (with
props)
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IConnectionFactory.cs   (with
props)
Modified:
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ConnectionError.cs
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ExceptionResponse.cs
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Connection.cs
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/AbstractCommandMarshaller.cs
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ConnectionErrorMarshaller.cs
    incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ExceptionResponseMarshaller.cs

Added: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/BrokerException.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/BrokerException.cs?rev=367642&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/BrokerException.cs (added)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/BrokerException.cs Tue Jan
10 07:28:53 2006
@@ -0,0 +1,17 @@
+using System;
+using System.Collections;
+using OpenWire.Client.Commands;
+using OpenWire.Client.Core;
+
+namespace OpenWire.Client {
+        /// <summary>
+        /// Exception thrown when the broker returns an error
+        /// </summary>
+        public class BrokerException : OpenWireException {
+                public BrokerException(BrokerError cause) : base("The operation failed: Type:
"
+                        + cause.ExceptionClass
+                        + " stack: "
+                        + cause.StackTrace) {
+                } 
+        } 
+}

Propchange: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/BrokerException.cs
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ConnectionError.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ConnectionError.cs?rev=367642&r1=367641&r2=367642&view=diff
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ConnectionError.cs
(original)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ConnectionError.cs
Tue Jan 10 07:28:53 2006
@@ -19,7 +19,7 @@
     {
     			public const byte ID_ConnectionError = 16;
     			
-        byte[] exception;
+        BrokerError exception;
         ConnectionId connectionId;
 
 
@@ -36,7 +36,7 @@
 
         // Properties
 
-        public byte[] Exception
+        public BrokerError Exception
         {
             get { return exception; }
             set { this.exception = value; }            

Modified: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ExceptionResponse.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ExceptionResponse.cs?rev=367642&r1=367641&r2=367642&view=diff
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ExceptionResponse.cs
(original)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Commands/ExceptionResponse.cs
Tue Jan 10 07:28:53 2006
@@ -19,7 +19,7 @@
     {
     			public const byte ID_ExceptionResponse = 31;
     			
-        byte[] exception;
+        BrokerError exception;
 
 
 
@@ -35,7 +35,7 @@
 
         // Properties
 
-        public byte[] Exception
+        public BrokerError Exception
         {
             get { return exception; }
             set { this.exception = value; }            

Modified: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Connection.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Connection.cs?rev=367642&r1=367641&r2=367642&view=diff
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Connection.cs (original)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Connection.cs Tue Jan 10
07:28:53 2006
@@ -13,6 +13,7 @@
                 private Transport transport;
                 IList sessions = new ArrayList();
                 private bool transacted;
+                private bool connected;
                 private bool closed;
                 private AcknowledgementMode acknowledgementMode;
                 private long sessionCounter;
@@ -33,8 +34,9 @@
                 /// Creates a new session to work on this connection
                 /// </summary>
                 public ISession CreateSession(bool transacted, AcknowledgementMode acknowledgementMode)
{
-                        CheckClosed();
+                        CheckConnected();
                         SessionInfo info = CreateSessionInfo(transacted, acknowledgementMode);
+                        SyncRequest(info);
                         Session session = new Session(this, info);
                         sessions.Add(session);
                         return session; 
@@ -65,13 +67,23 @@
                         set { this.acknowledgementMode = value; } 
                 }
 
+                public string ClientId {
+                        get { return info.ClientId; }
+                        set {
+                                if (connected) {
+                                        throw new OpenWireException("You cannot change the
ClientId once the Connection is connected"); 
+                                }
+                                info.ClientId = value;
+                        }
+                }
+
                 // Implementation methods
 
                 /// <summary>
                 /// Performs a synchronous request-response with the broker
                 /// </summary>
                 public Response SyncRequest(Command command) {
-                        CheckClosed();
+                        CheckConnected();
                         Response response = Transport.Request(command);
                         if (response is ExceptionResponse) {
                                 ExceptionResponse exceptionResponse = (ExceptionResponse)
response;
@@ -93,9 +105,13 @@
                         return answer; 
                 }
 
-                protected void CheckClosed() {
+                protected void CheckConnected() {
                         if (closed) {
                                 throw new ConnectionClosedException(); 
+                        }
+                        if (!connected) {
+                                SyncRequest(info);
+                                connected = true; 
                         } 
                 } 
         } 

Added: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/ConnectionFactory.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/ConnectionFactory.cs?rev=367642&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/ConnectionFactory.cs (added)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/ConnectionFactory.cs Tue
Jan 10 07:28:53 2006
@@ -0,0 +1,77 @@
+using System;
+using System.Collections;
+using OpenWire.Client.Commands;
+using OpenWire.Client.Core;
+
+namespace OpenWire.Client {
+        /// <summary>
+        /// Represents a connection with a message broker
+        /// </summary>
+        public class ConnectionFactory : IConnectionFactory {
+                private string host = "localhost";
+                private int port = 61616;
+                private string userName;
+                private string password;
+                private string clientId;
+
+                public IConnection CreateConnection() {
+                        return CreateConnection(userName, password); 
+                }
+
+                public IConnection CreateConnection(string userName, string password) {
+                        ConnectionInfo info = CreateConnectionInfo(userName, password);
+                        Transport transport = CreateTransport();
+                        Connection connection = new Connection(transport, info);
+                        connection.ClientId = clientId;
+                        return connection; 
+                }
+
+                // Properties
+
+                public string Host {
+                        get { return host; }
+                        set { host = value; } 
+                }
+
+                public int Port {
+                        get { return port; }
+                        set { port = value; } 
+                }
+
+                public string UserName {
+                        get { return userName; }
+                        set { userName = value; } 
+                }
+
+                public string Password {
+                        get { return password; }
+                        set { password = value; } 
+                }
+
+                public string ClientId {
+                        get { return clientId; }
+                        set { clientId = value; } 
+                }
+
+                // Implementation methods
+
+                protected ConnectionInfo CreateConnectionInfo(string userName, string password)
{
+                        ConnectionInfo answer = new ConnectionInfo();
+                        ConnectionId connectionId = new ConnectionId();
+                        connectionId.Value = CreateNewConnectionID();
+                        answer.ConnectionId = connectionId;
+                        answer.UserName = userName;
+                        answer.Password = password;
+                        return answer; 
+                }
+
+                protected string CreateNewConnectionID() {
+                        return Guid.NewGuid().ToString(); 
+                }
+
+                protected Transport CreateTransport() {
+                        // TODO
+                        return null; 
+                } 
+        } 
+}

Propchange: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/ConnectionFactory.cs
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/AbstractCommandMarshaller.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/AbstractCommandMarshaller.cs?rev=367642&r1=367641&r2=367642&view=diff
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/AbstractCommandMarshaller.cs
(original)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/AbstractCommandMarshaller.cs
Tue Jan 10 07:28:53 2006
@@ -28,6 +28,18 @@
                         // empty body to allow generated code to call base method
                 }
 
+                protected virtual BrokerError ReadBrokerError(BinaryReader dataIn) {
+                        BrokerError answer = new BrokerError();
+                        answer.ExceptionClass = dataIn.ReadString();
+                        answer.StackTrace = dataIn.ReadString();
+                        return answer;
+                }
+
+                protected virtual void WriteBrokerError(BrokerError command, BinaryWriter
dataOut) {
+                        dataOut.Write(command.ExceptionClass);
+                        dataOut.Write(command.StackTrace);
+                }
+
                 protected virtual ActiveMQDestination ReadDestination(BinaryReader dataIn)
{
                         return (ActiveMQDestination) CommandMarshallerRegistry.ReadCommand(dataIn);

                 }

Added: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/BrokerError.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/BrokerError.cs?rev=367642&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/BrokerError.cs (added)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/BrokerError.cs Tue Jan
10 07:28:53 2006
@@ -0,0 +1,22 @@
+using System;
+using OpenWire.Client.Core;
+
+namespace OpenWire.Client.Core {
+        /// <summary>
+        /// Represents an exception on the broker
+        /// </summary>
+        public class BrokerError : AbstractCommand {
+                private string exceptionClass;
+                private string stackTrace;
+
+                public string ExceptionClass {
+                        get { return exceptionClass; }
+                        set { exceptionClass = value; } 
+                }
+
+                public string StackTrace {
+                        get { return stackTrace; }
+                        set { stackTrace = value; } 
+                } 
+        } 
+}

Propchange: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/Core/BrokerError.cs
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IConnectionFactory.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IConnectionFactory.cs?rev=367642&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IConnectionFactory.cs (added)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IConnectionFactory.cs Tue
Jan 10 07:28:53 2006
@@ -0,0 +1,21 @@
+using System;
+using OpenWire.Client.Commands;
+
+namespace OpenWire.Client {
+
+        /// <summary>
+        /// A Factory of IConnection objects
+        /// </summary>
+        public interface IConnectionFactory {
+
+                /// <summary>
+                /// Creates a new connection
+                /// </summary>
+                IConnection CreateConnection();
+
+                /// <summary>
+                /// Creates a new connection with the given user name and password
+                /// </summary>
+                IConnection CreateConnection(string userName, string password);
+        } 
+}

Propchange: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IConnectionFactory.cs
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ConnectionErrorMarshaller.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ConnectionErrorMarshaller.cs?rev=367642&r1=367641&r2=367642&view=diff
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ConnectionErrorMarshaller.cs
(original)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ConnectionErrorMarshaller.cs
Tue Jan 10 07:28:53 2006
@@ -30,7 +30,7 @@
             base.BuildCommand(command, dataIn);
 
             ConnectionError info = (ConnectionError) command;
-            info.Exception = ReadBytes(dataIn);
+            info.Exception = ReadBrokerError(dataIn);
             info.ConnectionId = (ConnectionId) CommandMarshallerRegistry.ConnectionIdMarshaller.ReadCommand(dataIn);
 
         }
@@ -39,7 +39,7 @@
             base.WriteCommand(command, dataOut);
 
             ConnectionError info = (ConnectionError) command;
-            WriteBytes(info.Exception, dataOut);
+            WriteBrokerError(info.Exception, dataOut);
             CommandMarshallerRegistry.ConnectionIdMarshaller.WriteCommand(info.ConnectionId,
dataOut);
 
         }

Modified: incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ExceptionResponseMarshaller.cs
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ExceptionResponseMarshaller.cs?rev=367642&r1=367641&r2=367642&view=diff
==============================================================================
--- incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ExceptionResponseMarshaller.cs
(original)
+++ incubator/activemq/trunk/openwire-dotnet/src/OpenWire.Client/IO/ExceptionResponseMarshaller.cs
Tue Jan 10 07:28:53 2006
@@ -30,7 +30,7 @@
             base.BuildCommand(command, dataIn);
 
             ExceptionResponse info = (ExceptionResponse) command;
-            info.Exception = ReadBytes(dataIn);
+            info.Exception = ReadBrokerError(dataIn);
 
         }
 
@@ -38,7 +38,7 @@
             base.WriteCommand(command, dataOut);
 
             ExceptionResponse info = (ExceptionResponse) command;
-            WriteBytes(info.Exception, dataOut);
+            WriteBrokerError(info.Exception, dataOut);
 
         }
     }



Mime
View raw message