Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate Acceptor (use IAcceptor instead); add some doc/TODO comment…

…s for not implemented functions
  • Loading branch information...
commit edf1e2859f5c5258ab74deb36148923ef8f2b5bf 1 parent d402b38
@gbirchmeier gbirchmeier authored
View
2  Examples/SimpleAcceptor/Program.cs
@@ -24,7 +24,7 @@ static void Main(string[] args)
Application app = new SimpleAcceptorApp();
MessageStoreFactory storeFactory = new FileStoreFactory(settings);
LogFactory logFactory = new FileLogFactory(settings);
- Acceptor acceptor = new ThreadedSocketAcceptor(app, storeFactory, settings, logFactory);
+ IAcceptor acceptor = new ThreadedSocketAcceptor(app, storeFactory, settings, logFactory);
acceptor.Start();
Console.WriteLine("press <enter> to quit");
View
111 QuickFIX.NET/Acceptor.cs → QuickFIX.NET/IAcceptor.cs 100755 → 100644
@@ -1,51 +1,60 @@
-using System.Net;
-using System.Collections.Generic;
-
-namespace QuickFix
-{
- /// <summary>
- /// Accepts connections from FIX clients and manages the associated sessions.
- /// </summary>
- public interface Acceptor
- {
- /// <summary>
- /// Start accepting connections
- /// </summary>
- void Start();
-
- /// <summary>
- /// Close exising connections and stop accepting new ones
- /// </summary>
- void Stop();
-
- /// <summary>
- /// Close exising connections and stop accepting new ones
- /// </summary>
- /// <param name="force">If true, do not wait for existing Sessions to logout</param>
- void Stop(bool force);
-
- /// <summary>
- /// Check whether any sessions are logged on
- /// </summary>
- /// <returns>true if any session is logged on, else false</returns>
- bool IsLoggedOn();
-
- /// <summary>
- /// Get the SessionIDs managed by this Acceptor
- /// </summary>
- /// <returns>the SessionIDs managed by this Acceptor</returns>
- HashSet<SessionID> GetSessionIDs();
-
- /// <summary>
- /// Get the Sessions managed by this Acceptor
- /// </summary>
- /// <returns>the Sessions managed by this Acceptor</returns>
- HashSet<Session> GetSessions();
-
- /// <summary>
- /// Get accepted socket end points
- /// </summary>
- /// <returns>a map of SessionIDs to EndPoints</returns>
- Dictionary<SessionID,IPEndPoint> GetAcceptorAddresses();
- }
-}
+using System.Net;
+using System.Collections.Generic;
+
+namespace QuickFix
+{
+ /// <summary>
+ /// Accepts connections from FIX clients and manages the associated sessions.
+ /// </summary>
+ public interface IAcceptor
+ {
+ /// <summary>
+ /// Start accepting connections
+ /// </summary>
+ void Start();
+
+ /// <summary>
+ /// Close exising connections and stop accepting new ones
+ /// </summary>
+ void Stop();
+
+ /// <summary>
+ /// Close exising connections and stop accepting new ones
+ /// </summary>
+ /// <param name="force">If true, do not wait for existing Sessions to logout</param>
+ void Stop(bool force);
+
+ /// <summary>
+ /// Check whether any sessions are logged on
+ /// </summary>
+ /// <returns>true if any session is logged on, else false</returns>
+ bool IsLoggedOn();
+
+ /// <summary>
+ /// Get the SessionIDs managed by this Acceptor
+ /// </summary>
+ /// <returns>the SessionIDs managed by this Acceptor</returns>
+ HashSet<SessionID> GetSessionIDs();
+
+ /// <summary>
+ /// Get the Sessions managed by this Acceptor
+ /// </summary>
+ /// <returns>the Sessions managed by this Acceptor</returns>
+ HashSet<Session> GetSessions();
+
+ /// <summary>
+ /// Get accepted socket end points
+ /// </summary>
+ /// <returns>a map of SessionIDs to EndPoints</returns>
+ Dictionary<SessionID,IPEndPoint> GetAcceptorAddresses();
+ }
+
+ /// <summary>
+ /// Deprecated due to violation of naming convention; will be removed in next major release.
+ /// It is replaced by IAcceptor, from which it directly derives.
+ /// </summary>
+ [System.Obsolete("Use IAcceptor instead")]
+ public interface Acceptor : IAcceptor
+ {
+ }
+}
View
4 QuickFIX.NET/QuickFix.csproj
@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
+ <ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D67079DA-6C49-48B2-93AB-1C3E879F5A0B}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -45,7 +45,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
- <Compile Include="Acceptor.cs" />
+ <Compile Include="IAcceptor.cs" />
<Compile Include="Application.cs" />
<Compile Include="Applications\FIX4Application.cs" />
<Compile Include="Applications\FIX5Application.cs" />
View
594 QuickFIX.NET/ThreadedSocketAcceptor.cs
@@ -1,289 +1,305 @@
-using System.Collections.Generic;
-using System.Threading;
-using System.Net;
-
-namespace QuickFix
-{
- /// <summary>
- /// Acceptor implementation - with threads
- /// Creates a ThreadedSocketReactor for every listening endpoint.
- /// </summary>
- public class ThreadedSocketAcceptor : Acceptor
- {
- class AcceptorSocketDescriptor
- {
- #region Properties
-
- public ThreadedSocketReactor SocketReactor
- {
- get { return socketReactor_; }
- }
-
- public IPEndPoint Address
- {
- get { return socketEndPoint_; }
- }
-
- #endregion
-
- #region Private Members
-
- private ThreadedSocketReactor socketReactor_;
- private IPEndPoint socketEndPoint_;
- private Dictionary<SessionID, Session> acceptedSessions_ = new Dictionary<SessionID, Session>();
-
- #endregion
-
- public AcceptorSocketDescriptor(IPEndPoint socketEndPoint, SocketSettings socketSettings)
- {
- socketEndPoint_ = socketEndPoint;
- socketReactor_ = new ThreadedSocketReactor(socketEndPoint_, socketSettings);
- }
-
- public void AcceptSession(Session session)
- {
- acceptedSessions_[session.SessionID] = session;
- }
-
- public Dictionary<SessionID, Session> GetAcceptedSessions()
- {
- return new Dictionary<SessionID,Session>(acceptedSessions_);
- }
- }
-
- private SessionSettings settings_;
- private SessionFactory sessionFactory_;
- private Dictionary<SessionID, Session> sessions_ = new Dictionary<SessionID, Session>();
- private Dictionary<IPEndPoint, AcceptorSocketDescriptor> socketDescriptorForAddress_ = new Dictionary<IPEndPoint, AcceptorSocketDescriptor>();
- private bool isStarted_ = false;
- private object sync_ = new object();
-
- #region Constructors
-
- public ThreadedSocketAcceptor(Application application, MessageStoreFactory storeFactory, SessionSettings settings)
- : this(new SessionFactory(application, storeFactory), settings)
- { }
-
- public ThreadedSocketAcceptor(Application application, MessageStoreFactory storeFactory, SessionSettings settings, LogFactory logFactory)
- : this(new SessionFactory(application, storeFactory, logFactory), settings)
- { }
-
- public ThreadedSocketAcceptor(SessionFactory sessionFactory, SessionSettings settings)
- {
- settings_ = settings;
- sessionFactory_ = sessionFactory;
-
- try
- {
- CreateSessions(settings_);
- }
- catch (System.Exception e)
- {
- throw new ConfigError(e.Message, e);
- }
- }
-
- #endregion
-
- #region Private Methods
-
- private void CreateSessions(SessionSettings settings)
- {
- foreach(SessionID sessionID in settings.GetSessions())
- {
- QuickFix.Dictionary dict = settings.Get(sessionID);
- string connectionType = dict.GetString(SessionSettings.CONNECTION_TYPE);
-
- if("acceptor".Equals(connectionType))
- {
- AcceptorSocketDescriptor descriptor = GetAcceptorSocketDescriptor(settings, sessionID);
- Session session = sessionFactory_.Create(sessionID, dict);
- descriptor.AcceptSession(session);
- sessions_[sessionID] = session;
- }
- }
-
- if(0 == socketDescriptorForAddress_.Count)
- throw new ConfigError("No acceptor sessions found in SessionSettings.");
- }
-
- private AcceptorSocketDescriptor GetAcceptorSocketDescriptor(SessionSettings settings, SessionID sessionID)
- {
- QuickFix.Dictionary dict = settings_.Get(sessionID);
- int port = System.Convert.ToInt32(dict.GetLong(SessionSettings.SOCKET_ACCEPT_PORT));
- SocketSettings socketSettings = new SocketSettings();
-
- IPEndPoint socketEndPoint;
- if (dict.Has(SessionSettings.SOCKET_ACCEPT_HOST))
- {
- string host = dict.GetString(SessionSettings.SOCKET_ACCEPT_HOST);
- IPAddress[] addrs = Dns.GetHostAddresses(host);
- socketEndPoint = new IPEndPoint(addrs[0], port);
- }
- else
- {
- socketEndPoint = new IPEndPoint(IPAddress.Any, port);
- }
-
- if (dict.Has(SessionSettings.SOCKET_NODELAY))
- {
- socketSettings.SocketNodelay = dict.GetBool(SessionSettings.SOCKET_NODELAY);
- }
-
- AcceptorSocketDescriptor descriptor;
- if (!socketDescriptorForAddress_.TryGetValue(socketEndPoint, out descriptor))
- {
- descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings);
- socketDescriptorForAddress_[socketEndPoint] = descriptor;
- }
-
- return descriptor;
- }
-
- private void StartAcceptingConnections()
- {
- lock (sync_)
- {
- /// FIXME StartSessionTimer();
- foreach (AcceptorSocketDescriptor socketDescriptor in socketDescriptorForAddress_.Values)
- {
- socketDescriptor.SocketReactor.Start();
- /// FIXME log_.Info("Listening for connections on " + socketDescriptor.getAddress());
- }
- }
- }
-
- private void StopAcceptingConnections()
- {
- lock (sync_)
- {
- foreach (AcceptorSocketDescriptor socketDescriptor in socketDescriptorForAddress_.Values)
- {
- socketDescriptor.SocketReactor.Shutdown();
- /// FIXME log_.Info("No longer accepting connections on " + socketDescriptor.getAddress());
- }
- }
- }
-
- private void LogoutAllSessions(bool force)
- {
- foreach(Session session in sessions_.Values)
- {
- try
- {
- session.Logout();
- }
- catch(System.Exception e)
- {
- /// FIXME logError(session.getSessionID(), "Error during logout", e);
- System.Console.WriteLine("Error during logout of Session " + session.SessionID + ": " + e.Message);
- }
- }
-
- if (force && IsLoggedOn())
- {
- foreach (Session session in sessions_.Values)
- {
- try
- {
- if (session.IsLoggedOn)
- session.Disconnect("Forcibly disconnecting session");
- }
- catch(System.Exception e)
- {
- /// FIXME logError(session.getSessionID(), "Error during disconnect", e);
- System.Console.WriteLine("Error during disconnect of Session " + session.SessionID + ": " + e.Message);
- }
- }
- }
-
- if (!force)
- WaitForLogout();
- }
-
- /// <summary>
- /// FIXME
- /// </summary>
- private void WaitForLogout()
- {
- System.Console.WriteLine("TODO - ThreadedSocketAcceptor.WaitForLogout not implemented!");
- /*
- int start = System.Environment.TickCount;
- HashSet<Session> sessions = new HashSet<Session>(sessions_.Values);
- while(sessions.Count > 0)
- {
- Thread.Sleep(100);
-
- int elapsed = System.Environment.TickCount - start;
- Iterator<Session> sessionItr = loggedOnSessions.iterator();
- while (sessionItr.hasNext())
- {
- Session session = sessionItr.next();
- if (elapsed >= session.getLogoutTimeout() * 1000L)
- {
- session.disconnect("Logout timeout, force disconnect", false);
- sessionItr.remove();
- }
- }
- // Be sure we don't look forever
- if (elapsed > 60000)
- {
- log.warn("Stopping session logout wait after 1 minute");
- break;
- }
- }
- */
- }
-
- #endregion
-
- #region Acceptor Members
-
- public void Start()
- {
- lock(sync_)
- {
- if (!isStarted_)
- {
- StartAcceptingConnections();
- isStarted_ = true;
- }
- }
- }
-
- public void Stop()
- {
- Stop(false);
- }
-
- public void Stop(bool force)
- {
- StopAcceptingConnections();
- LogoutAllSessions(force);
- /// FIXME StopSessionTimer();
- /// FIXME Session.UnregisterSessions(GetSessions());
- }
-
- public bool IsLoggedOn()
- {
- throw new System.NotImplementedException();
- }
-
- public HashSet<SessionID> GetSessionIDs()
- {
- throw new System.NotImplementedException();
- }
-
- public HashSet<Session> GetSessions()
- {
- throw new System.NotImplementedException();
- }
-
- public Dictionary<SessionID, IPEndPoint> GetAcceptorAddresses()
- {
- throw new System.NotImplementedException();
- }
-
- #endregion
- }
-}
+using System.Collections.Generic;
+using System.Threading;
+using System.Net;
+
+namespace QuickFix
+{
+ /// <summary>
+ /// Acceptor implementation - with threads
+ /// Creates a ThreadedSocketReactor for every listening endpoint.
+ /// </summary>
+ public class ThreadedSocketAcceptor : IAcceptor
+ {
+ class AcceptorSocketDescriptor
+ {
+ #region Properties
+
+ public ThreadedSocketReactor SocketReactor
+ {
+ get { return socketReactor_; }
+ }
+
+ public IPEndPoint Address
+ {
+ get { return socketEndPoint_; }
+ }
+
+ #endregion
+
+ #region Private Members
+
+ private ThreadedSocketReactor socketReactor_;
+ private IPEndPoint socketEndPoint_;
+ private Dictionary<SessionID, Session> acceptedSessions_ = new Dictionary<SessionID, Session>();
+
+ #endregion
+
+ public AcceptorSocketDescriptor(IPEndPoint socketEndPoint, SocketSettings socketSettings)
+ {
+ socketEndPoint_ = socketEndPoint;
+ socketReactor_ = new ThreadedSocketReactor(socketEndPoint_, socketSettings);
+ }
+
+ public void AcceptSession(Session session)
+ {
+ acceptedSessions_[session.SessionID] = session;
+ }
+
+ public Dictionary<SessionID, Session> GetAcceptedSessions()
+ {
+ return new Dictionary<SessionID,Session>(acceptedSessions_);
+ }
+ }
+
+ private SessionSettings settings_;
+ private SessionFactory sessionFactory_;
+ private Dictionary<SessionID, Session> sessions_ = new Dictionary<SessionID, Session>();
+ private Dictionary<IPEndPoint, AcceptorSocketDescriptor> socketDescriptorForAddress_ = new Dictionary<IPEndPoint, AcceptorSocketDescriptor>();
+ private bool isStarted_ = false;
+ private object sync_ = new object();
+
+ #region Constructors
+
+ public ThreadedSocketAcceptor(Application application, MessageStoreFactory storeFactory, SessionSettings settings)
+ : this(new SessionFactory(application, storeFactory), settings)
+ { }
+
+ public ThreadedSocketAcceptor(Application application, MessageStoreFactory storeFactory, SessionSettings settings, LogFactory logFactory)
+ : this(new SessionFactory(application, storeFactory, logFactory), settings)
+ { }
+
+ public ThreadedSocketAcceptor(SessionFactory sessionFactory, SessionSettings settings)
+ {
+ settings_ = settings;
+ sessionFactory_ = sessionFactory;
+
+ try
+ {
+ CreateSessions(settings_);
+ }
+ catch (System.Exception e)
+ {
+ throw new ConfigError(e.Message, e);
+ }
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private void CreateSessions(SessionSettings settings)
+ {
+ foreach(SessionID sessionID in settings.GetSessions())
+ {
+ QuickFix.Dictionary dict = settings.Get(sessionID);
+ string connectionType = dict.GetString(SessionSettings.CONNECTION_TYPE);
+
+ if("acceptor".Equals(connectionType))
+ {
+ AcceptorSocketDescriptor descriptor = GetAcceptorSocketDescriptor(settings, sessionID);
+ Session session = sessionFactory_.Create(sessionID, dict);
+ descriptor.AcceptSession(session);
+ sessions_[sessionID] = session;
+ }
+ }
+
+ if(0 == socketDescriptorForAddress_.Count)
+ throw new ConfigError("No acceptor sessions found in SessionSettings.");
+ }
+
+ private AcceptorSocketDescriptor GetAcceptorSocketDescriptor(SessionSettings settings, SessionID sessionID)
+ {
+ QuickFix.Dictionary dict = settings_.Get(sessionID);
+ int port = System.Convert.ToInt32(dict.GetLong(SessionSettings.SOCKET_ACCEPT_PORT));
+ SocketSettings socketSettings = new SocketSettings();
+
+ IPEndPoint socketEndPoint;
+ if (dict.Has(SessionSettings.SOCKET_ACCEPT_HOST))
+ {
+ string host = dict.GetString(SessionSettings.SOCKET_ACCEPT_HOST);
+ IPAddress[] addrs = Dns.GetHostAddresses(host);
+ socketEndPoint = new IPEndPoint(addrs[0], port);
+ }
+ else
+ {
+ socketEndPoint = new IPEndPoint(IPAddress.Any, port);
+ }
+
+ if (dict.Has(SessionSettings.SOCKET_NODELAY))
+ {
+ socketSettings.SocketNodelay = dict.GetBool(SessionSettings.SOCKET_NODELAY);
+ }
+
+ AcceptorSocketDescriptor descriptor;
+ if (!socketDescriptorForAddress_.TryGetValue(socketEndPoint, out descriptor))
+ {
+ descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings);
+ socketDescriptorForAddress_[socketEndPoint] = descriptor;
+ }
+
+ return descriptor;
+ }
+
+ private void StartAcceptingConnections()
+ {
+ lock (sync_)
+ {
+ /// FIXME StartSessionTimer();
+ foreach (AcceptorSocketDescriptor socketDescriptor in socketDescriptorForAddress_.Values)
+ {
+ socketDescriptor.SocketReactor.Start();
+ /// FIXME log_.Info("Listening for connections on " + socketDescriptor.getAddress());
+ }
+ }
+ }
+
+ private void StopAcceptingConnections()
+ {
+ lock (sync_)
+ {
+ foreach (AcceptorSocketDescriptor socketDescriptor in socketDescriptorForAddress_.Values)
+ {
+ socketDescriptor.SocketReactor.Shutdown();
+ /// FIXME log_.Info("No longer accepting connections on " + socketDescriptor.getAddress());
+ }
+ }
+ }
+
+ private void LogoutAllSessions(bool force)
+ {
+ foreach(Session session in sessions_.Values)
+ {
+ try
+ {
+ session.Logout();
+ }
+ catch(System.Exception e)
+ {
+ /// FIXME logError(session.getSessionID(), "Error during logout", e);
+ System.Console.WriteLine("Error during logout of Session " + session.SessionID + ": " + e.Message);
+ }
+ }
+
+ if (force && IsLoggedOn())
+ {
+ foreach (Session session in sessions_.Values)
+ {
+ try
+ {
+ if (session.IsLoggedOn)
+ session.Disconnect("Forcibly disconnecting session");
+ }
+ catch(System.Exception e)
+ {
+ /// FIXME logError(session.getSessionID(), "Error during disconnect", e);
+ System.Console.WriteLine("Error during disconnect of Session " + session.SessionID + ": " + e.Message);
+ }
+ }
+ }
+
+ if (!force)
+ WaitForLogout();
+ }
+
+ /// <summary>
+ /// FIXME
+ /// </summary>
+ private void WaitForLogout()
+ {
+ System.Console.WriteLine("TODO - ThreadedSocketAcceptor.WaitForLogout not implemented!");
+ /*
+ int start = System.Environment.TickCount;
+ HashSet<Session> sessions = new HashSet<Session>(sessions_.Values);
+ while(sessions.Count > 0)
+ {
+ Thread.Sleep(100);
+
+ int elapsed = System.Environment.TickCount - start;
+ Iterator<Session> sessionItr = loggedOnSessions.iterator();
+ while (sessionItr.hasNext())
+ {
+ Session session = sessionItr.next();
+ if (elapsed >= session.getLogoutTimeout() * 1000L)
+ {
+ session.disconnect("Logout timeout, force disconnect", false);
+ sessionItr.remove();
+ }
+ }
+ // Be sure we don't look forever
+ if (elapsed > 60000)
+ {
+ log.warn("Stopping session logout wait after 1 minute");
+ break;
+ }
+ }
+ */
+ }
+
+ #endregion
+
+ #region Acceptor Members
+
+ public void Start()
+ {
+ lock(sync_)
+ {
+ if (!isStarted_)
+ {
+ StartAcceptingConnections();
+ isStarted_ = true;
+ }
+ }
+ }
+
+ public void Stop()
+ {
+ Stop(false);
+ }
+
+ public void Stop(bool force)
+ {
+ StopAcceptingConnections();
+ LogoutAllSessions(force);
+ /// FIXME StopSessionTimer();
+ /// FIXME Session.UnregisterSessions(GetSessions());
+ }
+
+ /// <summary>
+ /// TODO: not yet implemented
+ /// </summary>
+ /// <returns></returns>
+ public bool IsLoggedOn()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ /// <summary>
+ /// TODO: not yet implemented
+ /// </summary>
+ /// <returns></returns>
+ public HashSet<SessionID> GetSessionIDs()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ /// <summary>
+ /// TODO: not yet implemented
+ /// </summary>
+ /// <returns></returns>
+ public HashSet<Session> GetSessions()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ /// <summary>
+ /// TODO: not yet implemented
+ /// </summary>
+ /// <returns></returns>
+ public Dictionary<SessionID, IPEndPoint> GetAcceptorAddresses()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ #endregion
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.