/// <summary>
        /// Opens a WebSocket connection without binding a session (see the flag isEarlyWSOpenEnabled).
        /// If a connection is already open, the connection is closed and a new connection is opened. </summary>
        /// <param name="serverAddress"> server address </param>
        /// <param name="streamListener"> stream connection listener </param>
        public virtual ListenableFuture openWS(Protocol protocol, string serverAddress, StreamListener streamListener)
        {
            if (wsTransport != null)
            {
                // close old connection
                wsTransport.close();
            }
            wsTransport = new WebSocket(sessionThread, options, serverAddress, streamListener, new MyConnectionListener(this));

            Debug.Assert(wsTransport.State.Equals(WebSocket.InternalState.CONNECTING));
            openWsFuture = new ListenableFuture();
            /* abort connection if opening takes too long */
            WebSocket        _wsTransport  = wsTransport;
            ListenableFuture _openWsFuture = openWsFuture;

            if (log.IsDebugEnabled)
            {
                log.Debug("Status timeout in " + options.CurrentConnectTimeout + " [currentConnectTimeoutWS]");
            }
            sessionThread.schedule(new Task(() =>
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Timeout event [currentConnectTimeoutWS]");
                }
                if ((_wsTransport.State.Equals(InternalState.CONNECTING)) || (_wsTransport.State.Equals(InternalState.UNEXPECTED_ERROR)))
                {
                    sessionLog.Debug("WS connection: aborted");
                    _openWsFuture.reject();
                    _wsTransport.close();
                    options.increaseConnectTimeout();
                }
            }), options.CurrentConnectTimeout);
            return(openWsFuture);
        }
コード例 #2
0
            internal async virtual void openWS()
            {
                string cLink = (string.ReferenceEquals(controlLink, null) ? outerInstance.PushServerAddress : controlLink);

                Debug.Assert(openWsFuture == null || openWsFuture.getState() == ListenableFuture.State.ABORTED);

                openWsFuture = outerInstance.protocol.openWebSocketConnection(cLink).onFulfilled(new MyRunnableConnectOK(this)).onRejected(new MyRunnableError(this));
            }
コード例 #3
0
        public virtual QuorumCall <AsyncLogger, Void> DoRollback()
        {
            IDictionary <AsyncLogger, ListenableFuture <Void> > calls = Maps.NewHashMap();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <Void> future = logger.DoRollback();
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #4
0
        public virtual QuorumCall <AsyncLogger, Void> DiscardSegments(long startTxId)
        {
            IDictionary <AsyncLogger, ListenableFuture <Void> > calls = Maps.NewHashMap();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <Void> future = logger.DiscardSegments(startTxId);
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #5
0
        internal virtual QuorumCall <AsyncLogger, Void> Format(NamespaceInfo nsInfo)
        {
            IDictionary <AsyncLogger, ListenableFuture <Void> > calls = Maps.NewHashMap();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <Void> future = logger.Format(nsInfo);
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #6
0
        public virtual QuorumCall <AsyncLogger, long> GetJournalCTime()
        {
            IDictionary <AsyncLogger, ListenableFuture <long> > calls = Maps.NewHashMap();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <long> future = logger.GetJournalCTime();
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #7
0
        internal virtual QuorumCall <AsyncLogger, Void> AcceptRecovery(QJournalProtocolProtos.SegmentStateProto
                                                                       log, Uri fromURL)
        {
            IDictionary <AsyncLogger, ListenableFuture <Void> > calls = Maps.NewHashMap();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <Void> future = logger.AcceptRecovery(log, fromURL);
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #8
0
        public virtual QuorumCall <AsyncLogger, bool> CanRollBack(StorageInfo storage, StorageInfo
                                                                  prevStorage, int targetLayoutVersion)
        {
            IDictionary <AsyncLogger, ListenableFuture <bool> > calls = Maps.NewHashMap();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <bool> future = logger.CanRollBack(storage, prevStorage, targetLayoutVersion
                                                                    );
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #9
0
        public virtual QuorumCall <AsyncLogger, Void> SendEdits(long segmentTxId, long firstTxnId
                                                                , int numTxns, byte[] data)
        {
            IDictionary <AsyncLogger, ListenableFuture <Void> > calls = Maps.NewHashMap();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <Void> future = logger.SendEdits(segmentTxId, firstTxnId, numTxns
                                                                  , data);
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #10
0
        public virtual QuorumCall <AsyncLogger, RemoteEditLogManifest> GetEditLogManifest(
            long fromTxnId, bool inProgressOk)
        {
            IDictionary <AsyncLogger, ListenableFuture <RemoteEditLogManifest> > calls = Maps.NewHashMap
                                                                                             ();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <RemoteEditLogManifest> future = logger.GetEditLogManifest(fromTxnId
                                                                                            , inProgressOk);
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #11
0
            internal virtual ListenableFuture sendBind(string bindCause)
            {
                switch (state)
                {
                case com.lightstreamer.client.session.SessionWS.WsState.WS_NOT_CONNECTED:
                    next(WsState.WS_CONNECTING, "sendBind");
                    openWS();
                    return(outerInstance.bindSessionExecution(bindCause));

                case com.lightstreamer.client.session.SessionWS.WsState.WS_BROKEN:
                    next(WsState.WS_BROKEN, "sendBind");
                    outerInstance.handler.streamSenseSwitch(outerInstance.handlerPhase, "ws.error", outerInstance.phase, outerInstance.recoveryBean.Recovery);
                    return(ListenableFuture.rejected());

                default:
                    Debug.Assert(state == WsState.WS_CONNECTED || state == WsState.WS_CONNECTING);
                    next(state, "sendBind");
                    return(outerInstance.bbindSessionExecution(bindCause));
                }
            }
コード例 #12
0
        public override ListenableFuture <Void> SendEdits(long segmentTxId, long firstTxnId
                                                          , int numTxns, byte[] data)
        {
            try
            {
                ReserveQueueSpace(data.Length);
            }
            catch (LoggerTooFarBehindException e)
            {
                return(Futures.ImmediateFailedFuture(e));
            }
            // When this batch is acked, we use its submission time in order
            // to calculate how far we are lagging.
            long submitNanos            = Runtime.NanoTime();
            ListenableFuture <Void> ret = null;

            try
            {
                ret = singleThreadExecutor.Submit(new _Callable_378(this, segmentTxId, firstTxnId
                                                                    , numTxns, data, submitNanos));
            }
            finally
            {
                if (ret == null)
                {
                    // it didn't successfully get submitted,
                    // so adjust the queue size back down.
                    UnreserveQueueSpace(data.Length);
                }
                else
                {
                    // It was submitted to the queue, so adjust the length
                    // once the call completes, regardless of whether it
                    // succeeds or fails.
                    Futures.AddCallback(ret, new _FutureCallback_428(this, data));
                }
            }
            return(ret);
        }
コード例 #13
0
                                     > PrepareRecovery(long segmentTxId)
        {
            IDictionary <AsyncLogger, ListenableFuture <QJournalProtocolProtos.PrepareRecoveryResponseProto
                                                        > > calls = Maps.NewHashMap();

            foreach (AsyncLogger logger in loggers)
            {
                ListenableFuture <QJournalProtocolProtos.PrepareRecoveryResponseProto> future = logger
                                                                                                .PrepareRecovery(segmentTxId);
                calls[logger] = future;
            }
            return(QuorumCall.Create(calls));
        }
コード例 #14
0
        internal static Stubber FutureThrows(Exception t)
        {
            ListenableFuture <object> ret = Futures.ImmediateFailedFuture(t);

            return(Org.Mockito.Mockito.DoReturn(ret));
        }
コード例 #15
0
        internal static Stubber FutureReturns <V>(V value)
        {
            ListenableFuture <V> ret = Futures.ImmediateFuture(value);

            return(Org.Mockito.Mockito.DoReturn(ret));
        }
コード例 #16
0
 public virtual void OnSuccess(LocatedFileStatusFetcher.ProcessInitialInputPathCallable.Result
                               result)
 {
     try
     {
         if (result.errors != null)
         {
             this._enclosing.RegisterInvalidInputError(result.errors);
         }
         if (result.matchedFileStatuses != null)
         {
             foreach (FileStatus matched in result.matchedFileStatuses)
             {
                 this._enclosing.runningTasks.IncrementAndGet();
                 ListenableFuture <LocatedFileStatusFetcher.ProcessInputDirCallable.Result> future =
                     this._enclosing.exec.Submit(new LocatedFileStatusFetcher.ProcessInputDirCallable
                                                     (result.fs, matched, this._enclosing.recursive, this._enclosing.inputFilter));
                 Futures.AddCallback(future, this._enclosing.processInputDirCallback);
             }
         }
         this._enclosing.DecrementRunningAndCheckCompletion();
     }
     catch (Exception t)
     {
         // Exception within the callback
         this._enclosing.RegisterError(t);
     }
 }
        public virtual RequestHandle bindSession(BindSessionRequest request, StreamListener reqListener, long tcpConnectTimeout, long tcpReadTimeout, ListenableFuture requestFuture)
        {
            RequestHandle handle = transport.sendRequest(protocol, request, reqListener, options.HttpExtraHeadersOnSessionCreationOnly ? null : options.HttpExtraHeaders, options.Proxy, tcpConnectTimeout, tcpReadTimeout);

            requestFuture.fulfill();
            return(handle);
        }
コード例 #18
0
 public override ListenableFuture openWebSocketConnection(string serverAddress)
 {
     // should never be called (the actual implementation is in TextProtocolWS)
     Debug.Assert(false);
     return(ListenableFuture.rejected());
 }
        /// <summary>
        /// {@inheritDoc}
        /// If the socket is not open, calls <seealso cref="#openSocket(String, StreamListener)"/>.
        /// </summary>
        public virtual RequestHandle bindSession(BindSessionRequest request, StreamListener reqListener, long tcpConnectTimeout, long tcpReadTimeout, ListenableFuture bindFuture)
        {
            if (wsTransport == null)
            {
                // no transport: this case can happen when transport is polling
                bindRequest = new PendingBind(request, reqListener, bindFuture);
                openWS(protocol, request.TargetServer, reqListener);
            }
            else
            {
                // there is a transport, so openSocket was already called: the state is CONNECTED or CONNECTING
                WebSocket.InternalState state = wsTransport.State;
                switch (state)
                {
                case WebSocket.InternalState.CONNECTED:
                    sendBindRequest(request, reqListener, bindFuture);
                    break;

                case WebSocket.InternalState.CONNECTING:
                    // buffer the request, which will be flushed when the client state is CONNECTED
                    Debug.Assert(bindRequest == null);
                    bindRequest = new PendingBind(request, reqListener, bindFuture);
                    break;

                case WebSocket.InternalState.BROKEN:
                    // discard bind request: must be sent in HTTP
                    break;

                default:
                    // Debug.Assert(false, state);
                    sessionLog.Warn("Unexpected bind request in state " + state);
                    break;
                }
            }
            // this request handle close the stream connection
            return(new RequestHandleAnonymousInnerClass(this));
        }
コード例 #20
0
 public virtual void OnSuccess(LocatedFileStatusFetcher.ProcessInputDirCallable.Result
                               result)
 {
     try
     {
         if (result.locatedFileStatuses.Count != 0)
         {
             this._enclosing.resultQueue.AddItem(result.locatedFileStatuses);
         }
         if (result.dirsNeedingRecursiveCalls.Count != 0)
         {
             foreach (FileStatus fileStatus in result.dirsNeedingRecursiveCalls)
             {
                 this._enclosing.runningTasks.IncrementAndGet();
                 ListenableFuture <LocatedFileStatusFetcher.ProcessInputDirCallable.Result> future =
                     this._enclosing.exec.Submit(new LocatedFileStatusFetcher.ProcessInputDirCallable
                                                     (result.fs, fileStatus, this._enclosing.recursive, this._enclosing.inputFilter));
                 Futures.AddCallback(future, this._enclosing.processInputDirCallback);
             }
         }
         this._enclosing.DecrementRunningAndCheckCompletion();
     }
     catch (Exception t)
     {
         // Error within the callback itself.
         this._enclosing.RegisterError(t);
     }
 }
 private void sendBindRequest(LightstreamerRequest request, RequestListener reqListener, ListenableFuture bindFuture)
 {
     wsTransport.sendRequest(protocol, request, new ListenerWrapper(this, reqListener), null, null, 0, 0);
     bindFuture.fulfill();
 }
コード例 #22
0
 /// <summary>Start executing and return FileStatuses based on the parameters specified
 ///     </summary>
 /// <returns>fetched file statuses</returns>
 /// <exception cref="System.Exception"/>
 /// <exception cref="System.IO.IOException"/>
 public virtual IEnumerable <FileStatus> GetFileStatuses()
 {
     // Increment to make sure a race between the first thread completing and the
     // rest being scheduled does not lead to a termination.
     runningTasks.IncrementAndGet();
     foreach (Path p in inputDirs)
     {
         runningTasks.IncrementAndGet();
         ListenableFuture <LocatedFileStatusFetcher.ProcessInitialInputPathCallable.Result>
         future = exec.Submit(new LocatedFileStatusFetcher.ProcessInitialInputPathCallable
                                  (p, conf, inputFilter));
         Futures.AddCallback(future, processInitialInputPathCallback);
     }
     runningTasks.DecrementAndGet();
     Lock.Lock();
     try
     {
         while (runningTasks.Get() != 0 && unknownError == null)
         {
             condition.Await();
         }
     }
     finally
     {
         Lock.Unlock();
     }
     this.exec.ShutdownNow();
     if (this.unknownError != null)
     {
         if (this.unknownError is Error)
         {
             throw (Error)this.unknownError;
         }
         else
         {
             if (this.unknownError is RuntimeException)
             {
                 throw (RuntimeException)this.unknownError;
             }
             else
             {
                 if (this.unknownError is IOException)
                 {
                     throw (IOException)this.unknownError;
                 }
                 else
                 {
                     if (this.unknownError is Exception)
                     {
                         throw (Exception)this.unknownError;
                     }
                     else
                     {
                         throw new IOException(this.unknownError);
                     }
                 }
             }
         }
     }
     if (this.invalidInputErrors.Count != 0)
     {
         if (this.newApi)
         {
             throw new InvalidInputException(invalidInputErrors);
         }
         else
         {
             throw new InvalidInputException(invalidInputErrors);
         }
     }
     return(Iterables.Concat(resultQueue));
 }
 public PendingBind(LightstreamerRequest request, RequestListener reqListener, ListenableFuture bindFuture) : base(request, reqListener, null)
 {
     this.bindFuture = bindFuture;
 }