42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
//using BCG.Utilities;
|
|
|
|
namespace BCG {
|
|
/// <summary>
|
|
/// Every instance of PublisherCore and SubscriberCore will have its
|
|
/// factory. Rather than have once singelton factory, this approach
|
|
/// is preffered since multiple pub/sub core can connect to the same
|
|
/// connection and make it difficultt o manage connections.
|
|
/// </summary>
|
|
public class PubSubServerConnectionFactory : IDisposable {
|
|
private Dictionary<RemoteConnectionInfo, IPubSubServerConnection> _conn_map =
|
|
new Dictionary<RemoteConnectionInfo, IPubSubServerConnection>();
|
|
private readonly bool _is_sub;
|
|
|
|
internal PubSubServerConnectionFactory(bool is_sub) {
|
|
_is_sub = is_sub;
|
|
}
|
|
|
|
public IPubSubServerConnection get_connection(RemoteConnectionInfo server_rci) {
|
|
IPubSubServerConnection rv = null;
|
|
if (!_conn_map.TryGetValue(server_rci, out rv)) {
|
|
rv = _build_connection(server_rci);
|
|
_conn_map.Add(server_rci, rv);
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
private IPubSubServerConnection _build_connection(RemoteConnectionInfo server_rci) {
|
|
return new PubSubServerManagedTCPConnection(server_rci, _is_sub);
|
|
}
|
|
|
|
#region IDisposable Members
|
|
|
|
public void Dispose() { }
|
|
|
|
#endregion
|
|
}
|
|
}
|