Ejemplo n.º 1
0
 private void Close()
 {
     if (null == stub)
     {
         return;
     }
     stub.Dispose();
     doProcess = false;
     stub      = null;
 }
Ejemplo n.º 2
0
 public ServersideClient(IConnectionStub <TMessage, TKey> stub, IThreadManager threadManager, IKeyedSubscriptionManager <TKey, MessageReceivedHandler <TMessage, TKey> > messageHandler, Guid clientId) :
     base(messageHandler, threadManager)
 {
     this.stub = Guard.IsNull(() => stub);
     stub.Write(new TMessage {
         ClientId = clientId
     });
     this.clientId = clientId;
     StartReader();
 }
Ejemplo n.º 3
0
 public override void Connect(EndPoint endPoint)
 {
     if (null == stubBuilder)
     {
         throw new InvalidOperationException("This StubConnection does not support new connections");
     }
     if (IsConnected)
     {
         throw new InvalidOperationException("This connection is already connected");
     }
     stub = stubBuilder.Build(endPoint);
     RunReader();
 }
Ejemplo n.º 4
0
        public void Connect(EndPoint remoteEndPoint)
        {
            if (IsConnected)
            {
                Close();
            }
            stub = connectionBuilder.Build(remoteEndPoint);
            int rx;
            var firstMessage = stub.ReadNext(out rx);

            OnMessageRead(rx);
            clientId = firstMessage.ClientId;
            StartReader();
        }
Ejemplo n.º 5
0
        private void EstablishConnection(IConnectionStub <TMessage, TKey> stub)
        {
            var client = clientBuilder.Build(stub);

            if (null == client)
            {
                return;
            }
            clientLock.EnterWriteLock();
            try
            {
                if (connectedClients.ContainsKey(client.ClientId))
                {
                    client.Close();
                    return;
                }
                connectedClients.Add(client.ClientId, client);
                client.Disconnected += ClientOnDisconnected;
                OnClientConnected(client.ClientId);
            }
            finally { clientLock.ExitWriteLock(); }
        }
Ejemplo n.º 6
0
 public IClient <TMessage, TKey> Build(IConnectionStub <TMessage, TKey> connection)
 {
     return(new ServersideClient <TMessage, TKey>(connection, threadManager, subscriptionManager, Guid.NewGuid()));
 }
Ejemplo n.º 7
0
 public StubConnection(IThreadManager threadManager, IConnectionStub <TMessage, TMessageKey> establishedConnection)
 {
     this.threadManager = Guard.IsNull(() => threadManager);
     stub = establishedConnection;
     RunReader();
 }