Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BayeuxClientState"/> class
        /// with the specified <see cref="BayeuxClientStates"/> type.
        /// </summary>
        protected BayeuxClientState(
            BayeuxClient session,
            BayeuxClientStates type,
            IDictionary <string, object> handshakeFields,
            IDictionary <string, object> advice,
            ClientTransport transport,
            string clientId,
            long backOff)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (type == BayeuxClientStates.None)
            {
                throw new ArgumentOutOfRangeException("type");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }

            _session = session;

            _type            = type;
            _handshakeFields = handshakeFields;
            _advice          = advice;
            _transport       = transport;
            _clientId        = clientId;
            _backOff         = backOff;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Always reset the subscriptions when a handshake has been requested.
        /// </summary>
        public override void Enter(BayeuxClientStates oldState)
        {
            // DEBUG
            Trace.TraceInformation("Subscriptions will be cleaned when old-state '{0}' -enter-> Handshaking state", oldState.ToString());

            this.Session.ResetSubscriptions();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Callback invoked when the state changed from the given <paramref name="oldState"/>
 /// to this state (and only when the two states are different).
 /// </summary>
 /// <param name="oldState">The previous state.</param>
 /// <seealso cref="Execute()"/>
 public virtual void Enter(BayeuxClientStates oldState)
 {
 }
Ejemplo n.º 4
0
		//private static readonly object _syncRoot = new object();

		/// <summary>
		/// Waits for this <see cref="BayeuxClient"/> to reach the given state(s) within the given time.
		/// </summary>
		/// <param name="waitMilliseconds">The time to wait to reach the given state(s).</param>
		/// <param name="states">The primary and alternative states to reach.</param>
		/// <returns>True if one of the state(s) has been reached within the given time, false otherwise.</returns>
		public virtual bool WaitFor(int waitMilliseconds, BayeuxClientStates states)
		{
			if (states == BayeuxClientStates.None)
				throw new ArgumentNullException("states");

			DateTime stop = DateTime.Now.AddMilliseconds(waitMilliseconds);
			long duration;
			BayeuxClientState currState;

			//lock (_syncRoot)
			//{
			try
			{
				while (((currState = _bayeuxClientState).Type & states) == 0
					&& (duration = unchecked((long)(stop - DateTime.Now).TotalMilliseconds)) > 0
					&& _stateUpdated.WaitOne(unchecked((int)duration), false))
				{
					// This check is needed to avoid that we return from WaitFor() too early,
					// when the state has been set, but its effects (like notifying listeners)
					// are not completed yet (COMETD-212).
					// Transient states (like CONNECTING or DISCONNECTING) may "miss" the
					// wake up in this way:
					// * T1 goes in wait - releases lock
					// * T2 finishes update to CONNECTING - notifies lock
					// * T3 starts a state update to CONNECTED - releases lock
					// * T1 wakes up, takes lock, but sees update in progress, waits - releases lock
					// * T3 finishes update to CONNECTED - notifies lock
					// * T1 wakes up, takes lock, sees status == CONNECTED - CONNECTING has been "missed"
					// To avoid this, we use BayeuxClientStates.Implies()
					/*if (_stateUpdaters == 0)
					{
					currState = _bayeuxClientState;
					if ((currState.Type & states) > 0) return true;
					}*/
				}
			}
			catch (ObjectDisposedException) { }
			catch (ThreadInterruptedException/*AbandonedMutexException*/)
			{
				Thread.CurrentThread.Interrupt();
			}
			//}

			currState = _bayeuxClientState;
			return ((currState.Type & states) > 0);
		}
Ejemplo n.º 5
0
		/// <summary>
		/// Reset the subscriptions if this is not a failure from a requested handshake.
		/// Subscriptions may be queued after requested handshakes.
		/// </summary>
		public override void Enter(BayeuxClientStates oldState)
		{
			if ((oldState & BayeuxClientStates.Handshaking) == 0)
			{
				// DEBUG
				Trace.TraceInformation("Subscriptions will be cleaned when old-state '{0}' -enter-> ReHandshaking state", oldState.ToString());

				this.Session.ResetSubscriptions();
			}
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Callback invoked when the state changed from the given <paramref name="oldState"/>
		/// to this state (and only when the two states are different).
		/// </summary>
		/// <param name="oldState">The previous state.</param>
		/// <seealso cref="Execute()"/>
		public virtual void Enter(BayeuxClientStates oldState)
		{
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BayeuxClientState"/> class
		/// with the specified <see cref="BayeuxClientStates"/> type.
		/// </summary>
		protected BayeuxClientState(
			BayeuxClient session,
			BayeuxClientStates type,
			IDictionary<string, object> handshakeFields,
			IDictionary<string, object> advice,
			ClientTransport transport,
			string clientId,
			long backOff)
		{
			if (session == null)
				throw new ArgumentNullException("session");
			if (type == BayeuxClientStates.None)
				throw new ArgumentOutOfRangeException("type");
			if (transport == null)
				throw new ArgumentNullException("transport");

			_session = session;

			_type = type;
			_handshakeFields = handshakeFields;
			_advice = advice;
			_transport = transport;
			_clientId = clientId;
			_backOff = backOff;
		}