public BayeuxClient(string url, IList <ClientTransport> transports) { _handshakeListener = new HandshakeTransportListener(this); _connectListener = new ConnectTransportListener(this); _disconnectListener = new DisconnectTransportListener(this); _publishListener = new PublishTransportListener(this); if (transports == null || transports.Count == 0) { throw new ArgumentException("Transport cannot be null"); } foreach (var t in transports) { _transportRegistry.Add(t); } foreach (var transportName in _transportRegistry.KnownTransports) { var clientTransport = _transportRegistry.GetTransport(transportName); if (!(clientTransport is HttpClientTransport)) { continue; } var httpTransport = (HttpClientTransport)clientTransport; httpTransport.Url = url; } _bayeuxClientState = new DisconnectedState(this, null); }
public BayeuxClient(string url, params ClientTransport[] transports) { //logger = Log.getLogger(GetType().FullName + "@" + this.GetHashCode()); //Console.WriteLine(GetType().FullName + "@" + this.GetHashCode()); handshakeListener = new HandshakeTransportListener(this); connectListener = new ConnectTransportListener(this); disconnectListener = new DisconnectTransportListener(this); publishListener = new PublishTransportListener(this); if (transports == null || transports.Length == 0 || transports[0] == null) { throw new ArgumentNullException(nameof(transports)); } foreach (var t in transports) { transportRegistry.Add(t); } foreach (var transportName in transportRegistry.KnownTransports) { var clientTransport = transportRegistry.GetTransport(transportName); if (clientTransport is HttpClientTransport httpTransport) { httpTransport.Url = url; httpTransport.SetCookieCollection(cookieCollection); } } bayeuxClientState = new DisconnectedState(this, null); }
protected bool sendConnect() { LogHelper.Log($"BayeauxClient: sendConnect()..."); BayeuxClientState bayeuxClientState = this.bayeuxClientState; if (isHandshook(bayeuxClientState)) { IMutableMessage message = newMessage(); message.Channel = Channel_Fields.META_CONNECT; message[Message_Fields.CONNECTION_TYPE_FIELD] = bayeuxClientState.transport.Name; if (bayeuxClientState.type == State.CONNECTING || bayeuxClientState.type == State.UNCONNECTED) { // First connect after handshake or after failure, add advice message.getAdvice(true)["timeout"] = 0; } bayeuxClientState.send(connectListener, message); LogHelper.Log($"BayeauxClient: sendConnect() returning true."); return(true); } LogHelper.Log($"BayeauxClient: sendConnect() returning false."); return(false); }
public BayeuxClient(String url, IList <ClientTransport> transports) { //logger = Log.getLogger(GetType().FullName + "@" + this.GetHashCode()); //Console.WriteLine(GetType().FullName + "@" + this.GetHashCode()); handshakeListener = new HandshakeTransportListener(this); connectListener = new ConnectTransportListener(this); disconnectListener = new DisconnectTransportListener(this); publishListener = new PublishTransportListener(this); if (transports == null || transports.Count == 0) { throw new ArgumentException("Transport cannot be null"); } foreach (ClientTransport t in transports) { transportRegistry.Add(t); } foreach (String transportName in transportRegistry.KnownTransports) { ClientTransport clientTransport = transportRegistry.getTransport(transportName); if (clientTransport is HttpClientTransport) { HttpClientTransport httpTransport = (HttpClientTransport)clientTransport; httpTransport.setURL(url); httpTransport.setCookieCollection(cookieCollection); } } bayeuxClientState = new DisconnectedState(this, null); }
protected bool sendHandshake() { BayeuxClientState bayeuxClientState = this.bayeuxClientState; if (isHandshaking(bayeuxClientState)) { IMutableMessage message = newMessage(); if (bayeuxClientState.handshakeFields != null) { foreach (KeyValuePair <String, Object> kvp in bayeuxClientState.handshakeFields) { message.Add(kvp.Key, kvp.Value); } } message.Channel = Channel_Fields.META_HANDSHAKE; message[Message_Fields.SUPPORTED_CONNECTION_TYPES_FIELD] = AllowedTransports; message[Message_Fields.VERSION_FIELD] = BayeuxClient.BAYEUX_VERSION; if (message.Id == null) { message.Id = newMessageId(); } //Console.WriteLine("Handshaking with extra fields {0}, transport {1}", Print.Dictionary(bayeuxClientState.handshakeFields), Print.Dictionary(bayeuxClientState.transport as IDictionary<String, Object>)); bayeuxClientState.send(handshakeListener, message); return(true); } return(false); }
public override bool IsUpdateableTo(BayeuxClientState newState) { return(newState.type == State.CONNECTED || newState.type == State.UNCONNECTED || newState.type == State.REHANDSHAKING || newState.type == State.DISCONNECTED); }
public BayeuxClient(String url, IList<ClientTransport> transports) { //logger = Log.getLogger(GetType().FullName + "@" + this.GetHashCode()); //Console.WriteLine(GetType().FullName + "@" + this.GetHashCode()); handshakeListener = new HandshakeTransportListener(this); connectListener = new ConnectTransportListener(this); disconnectListener = new DisconnectTransportListener(this); publishListener = new PublishTransportListener(this); if (transports == null || transports.Count == 0) throw new ArgumentException("Transport cannot be null"); foreach (ClientTransport t in transports) transportRegistry.Add(t); foreach (String transportName in transportRegistry.KnownTransports) { ClientTransport clientTransport = transportRegistry.getTransport(transportName); if (clientTransport is HttpClientTransport) { HttpClientTransport httpTransport = (HttpClientTransport)clientTransport; httpTransport.setURL(url); httpTransport.setCookieCollection(cookieCollection); } } bayeuxClientState = new DisconnectedState(this, null); }
private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { LogHelper.Log($"BayeauxClient: updateBayeuxClientState()..."); stateUpdateInProgressMutex.WaitOne(); ++stateUpdateInProgress; stateUpdateInProgressMutex.ReleaseMutex(); BayeuxClientState newState = null; BayeuxClientState oldState = bayeuxClientState; newState = create(oldState); LogHelper.Log($"BayeauxClient: updateBayeuxClientState() old state: {oldState}, new state: {newState}"); if (newState == null) { throw new SystemException(); } if (!oldState.isUpdateableTo(newState)) { LogHelper.Log($"BayeauxClient: updateBayeuxClientState() State is not updatable from {oldState} to {newState}"); return; } bayeuxClientState = newState; postCreate?.Invoke(); if (oldState.Type != newState.Type) { newState.enter(oldState.Type); } LogHelper.Log($"BayeauxClient: updateBayeuxClientState() executing on {newState}..."); newState.execute(); LogHelper.Log($"BayeauxClient: updateBayeuxClientState() executed on {newState}."); // Notify threads waiting in waitFor() stateUpdateInProgressMutex.WaitOne(); --stateUpdateInProgress; if (stateUpdateInProgress == 0) { stateChanged.Set(); } stateUpdateInProgressMutex.ReleaseMutex(); LogHelper.Log($"BayeauxClient: updateBayeuxClientState() done."); }
protected bool sendMessages(IList <IMutableMessage> messages) { BayeuxClientState bayeuxClientState = this.bayeuxClientState; if (bayeuxClientState.type == State.CONNECTING || isConnected(bayeuxClientState)) { bayeuxClientState.send(publishListener, messages); return(true); } else { failMessages(null, ObjectConverter.ToListOfIMessage(messages)); return(false); } }
protected override void sendBatch() { BayeuxClientState bayeuxClientState = this.bayeuxClientState; if (isHandshaking(bayeuxClientState)) { return; } IList <IMutableMessage> messages = takeMessages(); if (messages.Count > 0) { sendMessages(messages); } }
private void UpdateBayeuxClientState( BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { lock (_stateUpdateInProgressLock) { ++_stateUpdateInProgress; } var oldState = _bayeuxClientState; var newState = create(oldState); if (newState == null) { throw new SystemException(); } if (!oldState.IsUpdateableTo(newState)) { _logger?.LogDebug($"State not updateable : {oldState} -> {newState}"); return; } _bayeuxClientState = newState; postCreate?.Invoke(); if (oldState.Type != newState.Type) { newState.Enter(oldState.Type); } newState.Execute(); // Notify threads waiting in waitFor() lock (_stateUpdateInProgressLock) { --_stateUpdateInProgress; if (_stateUpdateInProgress == 0) { _stateChanged.Set(); } } }
private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { stateUpdateInProgressMutex.WaitOne(); ++stateUpdateInProgress; stateUpdateInProgressMutex.ReleaseMutex(); BayeuxClientState newState = null; BayeuxClientState oldState = bayeuxClientState; newState = create(oldState); if (newState == null) { throw new SystemException(); } if (!oldState.isUpdateableTo(newState)) { Console.WriteLine("State not updateable : {0} -> {1}", oldState, newState); return; } bayeuxClientState = newState; if (postCreate != null) { postCreate(); } if (oldState.Type != newState.Type) { newState.enter(oldState.Type); } newState.execute(); // Notify threads waiting in waitFor() stateUpdateInProgressMutex.WaitOne(); --stateUpdateInProgress; if (stateUpdateInProgress == 0) { stateChanged.Set(); } stateUpdateInProgressMutex.ReleaseMutex(); }
public BayeuxClient(string url, params ClientTransport[] transports) { _handshakeListener = new HandshakeTransportListener(this); _connectListener = new ConnectTransportListener(this); _disconnectListener = new DisconnectTransportListener(this); _publishListener = new PublishTransportListener(this); if (transports == null) { throw new ArgumentNullException(nameof(transports)); } if (transports.Length == 0) { throw new ArgumentException("No transports provided", nameof(transports)); } if (transports.Any(t => t == null)) { throw new ArgumentException("One of the transports was null", nameof(transports)); } foreach (var t in transports) { _transportRegistry.Add(t); } foreach (var transportName in _transportRegistry.KnownTransports) { var clientTransport = _transportRegistry.GetTransport(transportName); if (clientTransport is HttpClientTransport httpTransport) { httpTransport.Url = url; httpTransport.SetCookieCollection(_cookieCollection); } } _bayeuxClientState = new DisconnectedState(this, null); }
private bool IsHandshaking(BayeuxClientState bayeuxClientState) { return(bayeuxClientState.StateType == State.Handshaking || bayeuxClientState.StateType == State.Rehandshaking); }
public override bool IsUpdateableTo(BayeuxClientState newState) { return(newState.type == State.HANDSHAKING); }
public abstract bool IsUpdateableTo(BayeuxClientState newState);
private bool IsDisconnected(BayeuxClientState bayeuxClientState) { return(bayeuxClientState.StateType == State.Disconnecting || bayeuxClientState.StateType == State.Disconnected); }
public override bool isUpdateableTo(BayeuxClientState newState) { return newState.type == State.HANDSHAKING; }
public override bool isUpdateableTo(BayeuxClientState newState) { return newState.type == State.CONNECTED || newState.type == State.UNCONNECTED || newState.type == State.REHANDSHAKING || newState.type == State.DISCONNECTED; }
private bool isDisconnected(BayeuxClientState bayeuxClientState) { return bayeuxClientState.type == State.DISCONNECTING || bayeuxClientState.type == State.DISCONNECTED; }
private bool isConnected(BayeuxClientState bayeuxClientState) { return bayeuxClientState.type == State.CONNECTED; }
private bool IsHandshook(BayeuxClientState bayeuxClientState) { return(bayeuxClientState.StateType == State.Connecting || bayeuxClientState.StateType == State.Connected || bayeuxClientState.StateType == State.Unconnected); }
private bool IsHandshook(BayeuxClientState bayeuxClientState) { return(bayeuxClientState.type == State.CONNECTING || bayeuxClientState.type == State.CONNECTED || bayeuxClientState.type == State.UNCONNECTED); }
private bool IsConnected(BayeuxClientState bayeuxClientState) { return(bayeuxClientState.type == State.CONNECTED); }
private bool isHandshook(BayeuxClientState bayeuxClientState) { return bayeuxClientState.type == State.CONNECTING || bayeuxClientState.type == State.CONNECTED || bayeuxClientState.type == State.UNCONNECTED; }
public override bool IsUpdateableTo(BayeuxClientState newState) { return(newState.type == State.DISCONNECTED); }
public override bool isUpdateableTo(BayeuxClientState newState) { return newState.type == State.DISCONNECTED; }
private bool IsHandshaking(BayeuxClientState bayeuxClientState) { return(bayeuxClientState.type == State.HANDSHAKING || bayeuxClientState.type == State.REHANDSHAKING); }
private bool isHandshaking(BayeuxClientState bayeuxClientState) { return bayeuxClientState.type == State.HANDSHAKING || bayeuxClientState.type == State.REHANDSHAKING; }
private void updateBayeuxClientState(BayeuxClientStateUpdater_createDelegate create, BayeuxClientStateUpdater_postCreateDelegate postCreate) { stateUpdateInProgressMutex.WaitOne(); ++stateUpdateInProgress; stateUpdateInProgressMutex.ReleaseMutex(); BayeuxClientState newState = null; BayeuxClientState oldState = bayeuxClientState; newState = create(oldState); if (newState == null) throw new SystemException(); if (!oldState.isUpdateableTo(newState)) { //Console.WriteLine("State not updateable : {0} -> {1}", oldState, newState); return; } bayeuxClientState = newState; if (postCreate != null) postCreate(); if (oldState.Type != newState.Type) newState.enter(oldState.Type); newState.execute(); // Notify threads waiting in waitFor() stateUpdateInProgressMutex.WaitOne(); --stateUpdateInProgress; if (stateUpdateInProgress == 0) stateChanged.Set(); stateUpdateInProgressMutex.ReleaseMutex(); }
private bool IsConnected(BayeuxClientState bayeuxClientState) { return(bayeuxClientState.StateType == State.Connected); }
private bool IsDisconnected(BayeuxClientState bayeuxClientState) { return(bayeuxClientState.type == State.DISCONNECTING || bayeuxClientState.type == State.DISCONNECTED); }
public abstract bool isUpdateableTo(BayeuxClientState newState);