activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1542430 [2/2] - in /activemq/activemq-dotnet/Apache.NMS.MQTT/trunk: ./ src/main/csharp/ src/main/csharp/Commands/ src/main/csharp/Messages/ src/main/csharp/Threads/ src/main/csharp/Transport/ src/main/csharp/Util/
Date Fri, 15 Nov 2013 23:43:14 GMT
Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Topic.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Topic.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Topic.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Topic.cs Fri Nov 15 23:43:13
2013
@@ -0,0 +1,59 @@
+//
+// 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.
+//
+using System;
+
+namespace Apache.NMS.MQTT
+{
+	/// <summary>
+	/// MQTT Topic Destination.  
+	/// </summary>
+	public class Topic : ITopic
+	{
+		string name;
+
+		public Topic(string name)
+		{
+			this.name = name;
+		}
+
+		public string TopicName 
+		{ 
+			get { return this.name; }
+		}
+
+		DestinationType DestinationType 
+		{ 
+			get { return DestinationType.Topic; }
+		}
+		
+		bool IsTopic
+		{ 
+			get { return true; }
+		}
+		
+		bool IsQueue 
+		{ 
+			get { return false; }
+		}
+		
+		bool IsTemporary 
+		{ 
+			get { return false; }
+		}
+	}
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Topic.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs
Fri Nov 15 23:43:13 2013
@@ -0,0 +1,151 @@
+//
+// 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.
+//
+using System;
+
+namespace Apache.NMS.MQTT.Transport
+{
+    public abstract class BaseCommand : Command, ICloneable
+    {
+        private int commandId;
+        private bool responseRequired = false;
+
+        public int CommandId
+        {
+            get { return commandId; }
+            set { this.commandId = value; }
+        }
+
+        public override int GetHashCode()
+        {
+            return (CommandId * 37) + CommandType;
+        }
+
+        public override bool Equals(Object that)
+        {
+            if(that is BaseCommand)
+            {
+                BaseCommand thatCommand = (BaseCommand) that;
+                return this.CommandType == thatCommand.CommandType &&
+                       this.CommandId == thatCommand.CommandId;
+            }
+            return false;
+        }
+
+        public override String ToString()
+        {
+            string answer = CommandName;
+            if(answer.Length == 0)
+            {
+                answer = base.ToString();
+            }
+            return answer + ": id = " + CommandId;
+        }
+
+        public virtual bool ResponseRequired
+        {
+            get { return responseRequired; }
+            set { responseRequired = value; }
+        }
+
+		public virtual bool IsResponse
+		{
+			get { return false; }
+		}
+
+		public virtual bool IsMessageDispatch
+		{
+			get { return false; }
+		}
+
+        public virtual bool IsCONNECT
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsCONNACK
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsDISCONNECT
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsPINGREQ
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsPINGRESP
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsPUBACK
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsPUBLISH
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsPUBREC
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsPUBREL
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsSUBACK
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsSUBSCRIBE
+        {
+			get { return false; }
+        } 
+
+        public virtual bool IsUNSUBACK
+        {
+			get { return false; }
+        }
+
+        public virtual bool IsUNSUBSCRIBE
+        {
+			get { return false; }
+        }
+
+        public virtual Object Clone()
+        {
+            // Since we are a derived class use the base's Clone()
+            // to perform the shallow copy. Since it is shallow it
+            // will include our derived class. Since we are derived,
+            // this method is an override.
+            BaseCommand o = (BaseCommand) base.Clone();
+
+            return o;
+        }
+    }
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/BaseCommand.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs?rev=1542430&r1=1542429&r2=1542430&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Command.cs Fri
Nov 15 23:43:13 2013
@@ -1,83 +1,122 @@
-/*
- * 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.
- */
+//
+// 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.
+//
 using System;
 
 namespace Apache.NMS.MQTT.Transport
 {
     /// <summary>
-    /// An Transport Command Marker Interface
+    /// Represents a generic Command class that is sent or received via a ITransport
+	/// instance.  Commands are marshalled and unmarshalled from binary form.
     /// </summary>
     public interface Command : ICloneable
     {
+		int CommandType
+		{
+			get;
+		}
+
+		string CommandName
+		{
+			get;
+		}
+
         int CommandId
         {
-            get;
-            set;
+			get;
         }
 
         bool ResponseRequired
         {
-            get;
-            set;
+			get;
+        }
+
+		bool IsResponse
+		{
+			get; 
+		}
+
+		bool IsMessageDispatch
+		{
+			get; 
+		}
+
+        bool IsCONNECT
+        {
+			get;
+        }
+
+        bool IsCONNACK
+        {
+			get;
+        }
+
+        bool IsDISCONNECT
+        {
+			get;
+        }
+
+        bool IsPINGREQ
+        {
+			get;
         }
 
-        bool IsDestinationInfo
+        bool IsPINGRESP
         {
-            get;
+			get;
         }
 
-        bool IsKeepAliveInfo
+        bool IsPUBACK
         {
-            get;
+			get;
         }
 
-        bool IsMessage
+        bool IsPUBLISH
         {
-            get;
+			get;
         }
 
-        bool IsMessageAck
+        bool IsPUBREC
         {
-            get;
+			get;
         }
 
-        bool IsMessageDispatch
+        bool IsPUBREL
         {
-            get;
+			get;
         }
 
-        bool IsProducerInfo
+        bool IsSUBACK
         {
-            get;
+			get;
         }
 
-        bool IsResponse
+        bool IsSUBSCRIBE
         {
-            get;
+			get;
         }
 
-        bool IsSessionInfo
+        bool IsUNSUBACK
         {
-            get;
+			get;
         }
 
-        bool IsShutdownInfo
+        bool IsUNSUBSCRIBE
         {
-            get;
+			get;
         }
     }
 }

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/FutureResponse.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/FutureResponse.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/FutureResponse.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/FutureResponse.cs
Fri Nov 15 23:43:13 2013
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Threading;
+using Apache.NMS.Util;
+
+namespace Apache.NMS.MQTT.Transport
+{
+	/// <summary>
+	/// Handles asynchronous responses
+	/// </summary>
+	public class FutureResponse
+	{
+		private TimeSpan maxWait = TimeSpan.FromMilliseconds(Timeout.Infinite);
+		public TimeSpan ResponseTimeout
+		{
+			get { return maxWait; }
+			set { maxWait = value; }
+		}
+
+		private readonly CountDownLatch latch = new CountDownLatch(1);
+		private Response response;
+
+		public Response Response
+		{
+			// Blocks the caller until a value has been set
+			get
+			{
+				lock(latch)
+				{
+					if(null != response)
+					{
+						return response;
+					}
+				}
+
+				try
+				{
+					if(!latch.await(maxWait) && response == null)
+					{
+						throw new RequestTimedOutException(maxWait);
+					}
+				}
+				catch(RequestTimedOutException e)
+				{
+					Tracer.Error("Caught Timeout Exception while waiting on monitor: " + e);
+					throw;
+				}
+				catch(Exception e)
+				{
+					Tracer.Error("Caught Exception while waiting on monitor: " + e);
+				}
+				
+				if(response == null && maxWait.TotalMilliseconds > 0)
+				{
+				}
+
+				lock(latch)
+				{
+					return response;
+				}
+			}
+
+			set
+			{
+				lock(latch)
+				{
+					response = value;
+				}
+
+				latch.countDown();
+			}
+		}
+	}
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/FutureResponse.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/FutureResponse.cs
------------------------------------------------------------------------------
    svn:executable = *

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ITransport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ITransport.cs?rev=1542430&r1=1542429&r2=1542430&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ITransport.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/ITransport.cs
Fri Nov 15 23:43:13 2013
@@ -16,7 +16,6 @@
  */
 
 using System;
-using Apache.NMS.Stomp.Commands;
 
 namespace Apache.NMS.MQTT.Transport
 {
@@ -149,6 +148,36 @@ namespace Apache.NMS.MQTT.Transport
             get;
         }
         
+		/// <summary>
+		/// Returns true if this Transport supports reconnections.
+		/// </summary>
+	    bool IsReconnectSupported
+		{
+			get;
+		}
+
+		/// <summary>
+		/// Returns true if this Transport can accept updated lists of connection Uri's.
+		/// </summary>
+	    bool IsUpdateURIsSupported
+		{
+			get;
+		}
+
+		/// <summary>
+		/// Updates the Uri's that this Transport is aware of and will use to
+		/// connect itself to.  If the rebalance option is true this method will
+		/// terminate any current connection and reconnect to another available
+		/// Uri.
+		/// </summary>
+		/// <param name="rebalance">
+		/// A <see cref="System.Boolean"/>
+		/// </param>
+		/// <param name="updatedURIs">
+		/// A <see cref="Uri"/>
+		/// </param>
+		void UpdateURIs(bool rebalance, Uri[] updatedURIs);
+
 	}
 }
 

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/MQTTTransportFactoryAttribute.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/MQTTTransportFactoryAttribute.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/MQTTTransportFactoryAttribute.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/MQTTTransportFactoryAttribute.cs
Fri Nov 15 23:43:13 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+using System;
+
+using Apache.NMS.MQTT.Util;
+
+namespace Apache.NMS.MQTT.Transport
+{
+    /// <summary>
+    /// Attribute that decorates ITransportFactory implementations to allow
+    /// the TransportFactory to find all the available factories dynamically.
+    /// </summary>
+
+    public class MQTTTransportFactoryAttribute : FactoryAttribute
+    {
+        public MQTTTransportFactoryAttribute(string scheme) : base(scheme)
+        {
+        }
+    }
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/MQTTTransportFactoryAttribute.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs Fri
Nov 15 23:43:13 2013
@@ -0,0 +1,60 @@
+//
+// 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.
+//
+using System;
+
+namespace Apache.NMS.MQTT.Transport
+{
+	/// <summary>
+	/// Response type.
+	/// </summary>
+    public class Response : BaseCommand
+    {
+        int correlationId;
+
+        ///
+        /// <summery>
+        ///  Returns a string containing the information for this DataStructure
+        ///  such as its type and value of its elements.
+        /// </summery>
+        ///
+        public override string ToString()
+        {
+            return GetType().Name + "[ " + 
+                "commandId = " + this.CommandId + ", " + 
+                "responseRequired = " + this.ResponseRequired + ", " + 
+                "CorrelationId = " + CorrelationId + " ]";
+        }
+
+        public int CorrelationId
+        {
+            get { return correlationId; }
+            set { this.correlationId = value; }
+        }
+
+        ///
+        /// <summery>
+        ///  Return an answer of true to the isResponse() query.
+        /// </summery>
+        ///
+        public override bool IsResponse
+        {
+            get { return true; }
+        }
+
+    };
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/Response.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/TransportFactory.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/TransportFactory.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/TransportFactory.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/TransportFactory.cs
Fri Nov 15 23:43:13 2013
@@ -0,0 +1,152 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Reflection;
+using System.Collections.Generic;
+using Apache.NMS.MQTT.Util;
+
+namespace Apache.NMS.MQTT.Transport
+{
+    public class TransportFactory
+    {
+        public static event ExceptionListener OnException;
+
+        private static readonly FactoryFinder<MQTTTransportFactoryAttribute, ITransportFactory>
FACTORY_FINDER =
+            new FactoryFinder<ActiveMQTransportFactoryAttribute, ITransportFactory>();
+
+        private readonly static object TRANSPORT_FACTORY_TYPES_LOCK = new object();
+        private readonly static IDictionary<String, Type> TRANSPORT_FACTORY_TYPES =
new Dictionary<String, Type>();
+
+        public static void HandleException(Exception ex)
+        {
+            if(TransportFactory.OnException != null)
+            {
+                TransportFactory.OnException(ex);
+            }
+        }
+
+        public void RegisterTransportFactory(string scheme, Type factoryType)
+        {
+            lock (TRANSPORT_FACTORY_TYPES_LOCK)
+            {
+                TRANSPORT_FACTORY_TYPES[scheme] = factoryType;
+            }
+        }
+
+        /// <summary>
+        /// Creates a normal transport.
+        /// </summary>
+        /// <param name="location"></param>
+        /// <returns>the transport</returns>
+        public static ITransport CreateTransport(Uri location)
+        {
+            ITransportFactory tf = TransportFactory.CreateTransportFactory(location);
+            return tf.CreateTransport(location);
+        }
+
+        public static ITransport CompositeConnect(Uri location)
+        {
+            ITransportFactory tf = TransportFactory.CreateTransportFactory(location);
+            return tf.CompositeConnect(location);
+        }
+
+        /// <summary>
+        /// Create a transport factory for the scheme.  If we do not support the transport
protocol,
+        /// an NMSConnectionException will be thrown.
+        /// </summary>
+        /// <param name="location"></param>
+        /// <returns></returns>
+        private static ITransportFactory CreateTransportFactory(Uri location)
+        {
+            string scheme = location.Scheme;
+
+            if(string.IsNullOrEmpty(scheme))
+            {
+                throw new NMSConnectionException(String.Format("Transport scheme invalid:
[{0}]", location.ToString()));
+            }
+
+            ITransportFactory factory = null;
+
+            try
+            {
+                factory = NewInstance(scheme.ToLower());
+            }
+            catch(NMSConnectionException)
+            {
+                throw;
+            }
+            catch(Exception e)
+            {
+                throw new NMSConnectionException("Error creating transport.", e);
+            }
+
+            if(null == factory)
+            {
+                throw new NMSConnectionException("Unable to create a transport.");
+            }
+
+            return factory;
+        }
+
+        private static ITransportFactory NewInstance(string scheme)
+        {
+            try
+            {
+                Type factoryType = FindTransportFactory(scheme);
+
+                if(factoryType == null)
+                {
+                    throw new Exception("NewInstance failed to find a match for id = " +
scheme);
+                }
+
+                return (ITransportFactory) Activator.CreateInstance(factoryType);
+            }
+            catch(Exception ex)
+            {
+                Tracer.WarnFormat("NewInstance failed to create an ITransportFactory with
error: {0}", ex.Message);
+                throw;
+            }
+        }
+
+        private static Type FindTransportFactory(string scheme)
+        {
+            lock (TRANSPORT_FACTORY_TYPES_LOCK)
+            {
+                if(TRANSPORT_FACTORY_TYPES.ContainsKey(scheme))
+                {
+                    return TRANSPORT_FACTORY_TYPES[scheme];
+                }
+            }
+
+            try
+            {
+                Type factoryType = FACTORY_FINDER.FindFactoryType(scheme);
+
+                lock (TRANSPORT_FACTORY_TYPES_LOCK)
+                {
+                    TRANSPORT_FACTORY_TYPES[scheme] = factoryType;
+                }
+                return factoryType;
+            }
+            catch
+            {
+                throw new NMSConnectionException("Failed to find Factory for Transport type:
" + scheme);
+            }
+        }
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Transport/TransportFactory.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryAttribute.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryAttribute.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryAttribute.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryAttribute.cs
Fri Nov 15 23:43:13 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+using System;
+
+namespace Apache.NMS.MQTT.Util
+{
+    [AttributeUsage(AttributeTargets.Class)]
+    public class FactoryAttribute : Attribute
+    {
+        private string factoryIdentifier;
+        private string description;
+
+        public FactoryAttribute(string factoryIdentifier)
+        {
+            this.factoryIdentifier = factoryIdentifier;
+        }
+
+        public string FactoryIdentifier
+        {
+            get { return this.factoryIdentifier; }
+        }
+
+        public string Description
+        {
+            get { return this.description; }
+            set { this.description = value; }
+        }
+    }
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryAttribute.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryFinder.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryFinder.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryFinder.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryFinder.cs Fri
Nov 15 23:43:13 2013
@@ -0,0 +1,125 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Reflection;
+using System.Collections.Generic;
+
+namespace Apache.NMS.MQTT.Util
+{
+    public class FactoryFinder<AttributeType, FactoryType> where AttributeType : FactoryAttribute
+    {
+        private static IDictionary<string, bool> DEFAULT_EXCLUDES;
+
+        static FactoryFinder()
+        {
+            DEFAULT_EXCLUDES = new Dictionary<string, bool>();
+
+            DEFAULT_EXCLUDES.Add("mscorlib", true);
+            DEFAULT_EXCLUDES.Add("System", true);
+            DEFAULT_EXCLUDES.Add("Mono", true);
+            DEFAULT_EXCLUDES.Add("Microsoft", true);
+            DEFAULT_EXCLUDES.Add("nunit", true);
+        }
+
+        public Type FindFactoryType(string factoryId)
+        {
+            try
+            {
+                // Look in this assembly first as its most likely to be the source, if we
+                // don't find it here then we expand out to all the currently loaded
+                // assemblies in the current AppDomain.  We could also start searching
+                // through all referenced assemblies in all the currently loaded ones but
+                // that could get out of hand so try this first.
+                Type result = this.SearchAssembly(Assembly.GetExecutingAssembly(), factoryId);
+
+                if(result == null)
+                {
+                    Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
+
+                    foreach(Assembly assembly in assemblies)
+                    {
+                        if(!IsExcluded(assembly))
+                        {
+                            result = SearchAssembly(assembly, factoryId);
+
+                            if(result != null)
+                            {
+                                break;
+                            }
+                        }
+                    }
+                }
+
+                return result;
+            }
+            catch
+            {
+                return null;
+            }
+        }
+
+        private bool IsExcluded(Assembly assembly)
+        {
+            if(assembly.Equals(Assembly.GetExecutingAssembly()))
+            {
+                return true;
+            }
+
+            string name = assembly.GetName().Name;
+
+            foreach(string key in DEFAULT_EXCLUDES.Keys)
+            {
+                if(name.StartsWith(key))
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        private Type SearchAssembly(Assembly assembly, string factoryId)
+        {
+            Tracer.DebugFormat("Searching Assembly: {0} for factory of the id: {1}",
+                               assembly.GetName().Name, factoryId);
+
+            Type[] types = assembly.GetTypes();
+
+            foreach(Type type in types)
+            {
+                object[] attributes = type.GetCustomAttributes(false);
+                foreach(Attribute attribute in attributes)
+                {
+                    if(attribute is AttributeType)
+                    {
+                        FactoryAttribute factoryAttribute = (FactoryAttribute)attribute;
+                        if(factoryAttribute.FactoryIdentifier.Equals(factoryId))
+                        {
+                            Tracer.DebugFormat("Found the Factory of type {0} for id: {1}",
+                                               type.ToString(), factoryId);
+                            return type;
+                        }
+                    }
+                }
+            }
+
+            return null;
+        }
+    }
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FactoryFinder.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FifoMessageDispatchChannel.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FifoMessageDispatchChannel.cs?rev=1542430&r1=1542429&r2=1542430&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FifoMessageDispatchChannel.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/FifoMessageDispatchChannel.cs
Fri Nov 15 23:43:13 2013
@@ -18,7 +18,7 @@
 using System;
 using System.Collections.Generic;
 using System.Threading;
-using Apache.NMS.MQTT.Commands;
+using Apache.NMS.MQTT.Messages;
 
 namespace Apache.NMS.MQTT.Util
 {

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/IdGenerator.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/IdGenerator.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/IdGenerator.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/IdGenerator.cs Fri
Nov 15 23:43:13 2013
@@ -0,0 +1,193 @@
+/*
+ * 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.
+ */
+
+using System;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+
+namespace Apache.NMS.MQTT.Util
+{
+    public class IdGenerator
+    {
+        private static readonly String UNIQUE_STUB;
+        private static int instanceCount;
+        private static readonly String hostName;
+        private readonly String seed;
+        private long sequence;
+    
+        static IdGenerator()
+        {
+            String stub = "-1-" + DateTime.Now.Ticks;
+            hostName = "localhost";
+
+            try
+            {
+                hostName = Dns.GetHostName();
+                IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0);
+                Socket tempSocket = new Socket(endPoint.AddressFamily, SocketType.Stream,
ProtocolType.Tcp);
+                tempSocket.Bind(endPoint);
+                stub = "-" + ((IPEndPoint)tempSocket.LocalEndPoint).Port + "-" + DateTime.Now.Ticks
+ "-";
+                Thread.Sleep(100);
+                tempSocket.Close();
+            }
+            catch(Exception ioe)
+            {
+                Tracer.Warn("could not generate unique stub: " + ioe.Message);
+            }
+
+            UNIQUE_STUB = stub;
+        }
+    
+        /**
+         * Construct an IdGenerator
+         */
+        public IdGenerator(String prefix)
+        {
+            lock(UNIQUE_STUB)
+            {
+                this.seed = prefix + UNIQUE_STUB + (instanceCount++) + ":";
+            }
+        }
+
+        public IdGenerator() : this("ID:" + hostName)
+        {
+        }
+    
+        /// <summary>
+        /// As we have to find the hostname as a side-affect of generating a unique
+        /// stub, we allow it's easy retrevial here
+        /// </summary>
+        public static String HostName
+        {
+            get { return hostName; }
+        }
+
+        /// <summary>
+        /// Generate a Unique Id
+        /// </summary>
+        /// <returns>
+        /// A <see cref="String"/>
+        /// </returns>
+        public String GenerateId()
+        {
+            lock(UNIQUE_STUB)
+            {
+                return this.seed + (this.sequence++);
+            }
+        }
+
+        /// <summary>
+        /// Generate a unique ID - that is friendly for a URL or file system
+        /// </summary>
+        /// <returns>
+        /// A <see cref="String"/>
+        /// </returns>
+        public String GenerateSanitizedId()
+        {
+            String result = GenerateId();
+            result = result.Replace(':', '-');
+            result = result.Replace('_', '-');
+            result = result.Replace('.', '-');
+            return result;
+        }
+    
+        /// <summary>
+        /// From a generated id - return the seed (i.e. minus the count)
+        /// </summary>
+        /// <param name="id">
+        /// A <see cref="String"/>
+        /// </param>
+        /// <returns>
+        /// A <see cref="String"/>
+        /// </returns>
+        public static String GetSeedFromId(String id)
+        {
+            String result = id;
+
+            if(id != null)
+            {
+                int index = id.LastIndexOf(':');
+                if(index > 0 && (index + 1) < id.Length)
+                {
+                    result = id.Substring(0, index + 1);
+                }
+            }
+
+            return result;
+        }
+    
+        /// <summary>
+        /// From a generated id - return the generator count
+        /// </summary>
+        /// <param name="id">
+        /// A <see cref="String"/>
+        /// </param>
+        /// <returns>
+        /// A <see cref="System.Int64"/>
+        /// </returns>
+        public static long GetSequenceFromId(String id)
+        {
+            long result = -1;
+            if(id != null)
+            {
+                int index = id.LastIndexOf(':');
+    
+                if(index > 0 && (index + 1) < id.Length)
+                {
+                    String numStr = id.Substring(index + 1, id.Length);
+                    result = Int64.Parse(numStr);
+                }
+            }
+            return result;
+        }
+
+        /// <summary>
+        /// Does a proper compare on the ids
+        /// </summary>
+        /// <param name="id1">
+        /// A <see cref="String"/>
+        /// </param>
+        /// <param name="id2">
+        /// A <see cref="String"/>
+        /// </param>
+        /// <returns>
+        /// A <see cref="System.Int32"/>
+        /// </returns>
+        public static int Compare(String id1, String id2)
+        {
+            int result = -1;
+
+            String seed1 = IdGenerator.GetSeedFromId(id1);
+            String seed2 = IdGenerator.GetSeedFromId(id2);
+
+            if(seed1 != null && seed2 != null)
+            {
+                result = seed1.CompareTo(seed2);
+
+                if(result == 0)
+                {
+                    long count1 = IdGenerator.GetSequenceFromId(id1);
+                    long count2 = IdGenerator.GetSequenceFromId(id2);
+                    result = (int)(count1 - count2);
+                }
+            }
+
+            return result;
+        }
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/IdGenerator.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTDestination.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTDestination.cs?rev=1542430&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTDestination.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTDestination.cs
Fri Nov 15 23:43:13 2013
@@ -0,0 +1,33 @@
+//
+// 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.
+//
+using System;
+
+namespace Apache.NMS.MQTT.Util
+{
+	public class MQTTDestination
+	{
+		private MQTTDestination()
+		{
+		}
+
+		public static IDestination Transform(IDestination destination)
+		{
+			return null;
+		}
+	}
+}
+

Propchange: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTDestination.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTMessageTransformation.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTMessageTransformation.cs?rev=1542430&r1=1542429&r2=1542430&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTMessageTransformation.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MQTTMessageTransformation.cs
Fri Nov 15 23:43:13 2013
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+using System;
 using Apache.NMS.Util;
 using Apache.NMS.MQTT.Commands;
 

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MessageDispatchChannel.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MessageDispatchChannel.cs?rev=1542430&r1=1542429&r2=1542430&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MessageDispatchChannel.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/src/main/csharp/Util/MessageDispatchChannel.cs
Fri Nov 15 23:43:13 2013
@@ -16,7 +16,7 @@
  */
 
 using System;
-using Apache.NMS.MQTT.Commands;
+using Apache.NMS.MQTT.Messages;
 
 namespace Apache.NMS.MQTT.Util
 {

Modified: activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj?rev=1542430&r1=1542429&r2=1542430&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.MQTT/trunk/vs2008-mqtt.csproj Fri Nov 15 23:43:13
2013
@@ -76,6 +76,19 @@
     <Compile Include="src\main\csharp\Messages\BytesMessage.cs" />
     <Compile Include="src\main\csharp\Messages\MQTTMessage.cs" />
     <Compile Include="src\main\csharp\Transport\Command.cs" />
+    <Compile Include="src\main\csharp\Topic.cs" />
+    <Compile Include="src\main\csharp\Transport\BaseCommand.cs" />
+    <Compile Include="src\main\csharp\Transport\FutureResponse.cs" />
+    <Compile Include="src\main\csharp\Transport\Response.cs" />
+    <Compile Include="src\main\csharp\Threads\TimerEx.cs" />
+    <Compile Include="src\main\csharp\Threads\TimerTask.cs" />
+    <Compile Include="src\main\csharp\Util\FactoryAttribute.cs" />
+    <Compile Include="src\main\csharp\Util\FactoryFinder.cs" />
+    <Compile Include="src\main\csharp\Util\IdGenerator.cs" />
+    <Compile Include="src\main\csharp\ConnectionFailedException.cs" />
+    <Compile Include="src\main\csharp\Util\MQTTDestination.cs" />
+    <Compile Include="src\main\csharp\Transport\TransportFactory.cs" />
+    <Compile Include="src\main\csharp\Transport\MQTTTransportFactoryAttribute.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="keyfile\" />



Mime
View raw message