Example #1
0
 public virtual void stop()
 {
     lock (MONITOR)
     {
         isInterrupted = true;
         if (isWaiting.compareAndSet(true, false))
         {
             Monitor.PulseAll(MONITOR);
         }
     }
 }
Example #2
0
        /**
         * Post a state change. If the manager is already in that state the change
         * is ignored. Otherwise the change is queued for listeners.
         *
         * @param newConnectionState new state
         * @return true if the state actually changed, false if it was already at that state
         */
        public bool addStateChange(ConnectionState newConnectionState)
        {
            lock (_setStateChangedLock)
            {
                if (state.Get() != STARTED)
                {
                    return(false);
                }

                ConnectionState previousState = currentConnectionState;
                if (previousState == newConnectionState)
                {
                    return(false);
                }
                currentConnectionState = newConnectionState;

                ConnectionState localState        = newConnectionState;
                bool            isNegativeMessage = ((newConnectionState == ConnectionState.LOST) || (newConnectionState == ConnectionState.SUSPENDED) || (newConnectionState == ConnectionState.READ_ONLY));
                if (!isNegativeMessage && initialConnectMessageSent.compareAndSet(false, true))
                {
                    localState = ConnectionState.CONNECTED;
                }

                postState(localState);

                return(true);
            }
        }
Example #3
0
        private void Close()
        {
            if (_closed.compareAndSet(false, true))
            {
                try
                {
                    _output.Dispose();
                }
                catch (Exception t)
                {
                    _log.error(string.Format("Unable to close pack output of bolt session '{0}'.", Id()), t);
                }

                try
                {
                    _machine.close();
                }
                catch (Exception t)
                {
                    _log.error(string.Format("Unable to close state machine of bolt session '{0}'.", Id()), t);
                }
                finally
                {
                    NotifyDestroyed();
                }
            }
        }
Example #4
0
        internal void logError(String reason, Exception e)
        {
            if ((reason == null) || (reason.Length == 0))
            {
                reason = "n/a";
            }

            if (e is KeeperException.ConnectionLossException)
            {
                if (LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL || logAsErrorConnectionErrors.compareAndSet(true, false))
                {
                    log.Error(reason, e);
                }
                else
                {
                    log.Debug(reason, e);
                }
            }
            if (!(e is KeeperException))
            {
                log.Error(reason, e);
            }

            String localReason = reason;

            unhandledErrorListeners.forEach(new Function <IUnhandledErrorListener, Void>()
            {
Example #5
0
 public virtual void executeInvokeCallback()
 {
     if (callbackListener != null)
     {
         if (executeCallbackOnlyOnce.compareAndSet(false, true))
         {
             callbackListener.onResponse(this);
         }
     }
 }
Example #6
0
 private void internalEnsure()
 {
     lock (_ensureLock)
     {
         if (ensureNeeded.compareAndSet(true, false))
         {
             client.createContainers(path);
         }
     }
 }
 /// <seealso cref= AsyncContext#sendResponse(java.lang.Object) </seealso>
 public virtual void sendResponse(object responseObject)
 {
     if (isResponseSentAlready.compareAndSet(false, true))
     {
         processor.sendResponseIfNecessary(ctx, cmd.Type, processor.CommandFactory.createResponse(responseObject, cmd));
     }
     else
     {
         throw new System.InvalidOperationException("Should not send rpc response repeatedly!");
     }
 }
Example #8
0
        public override void Stop()
        {
            if (_shouldClose.compareAndSet(false, true))
            {
                _machine.markForTermination();

                // Enqueue an empty job for close to be handled linearly
                // This is for already executing connections
                EnqueueInternal(ignore =>
                {
                });
            }
        }
Example #9
0
    /// <summary>
    /// Enable and initialise the remote nodes. </summary>
    /// <param name="nodeAddresses"> Addresses of remote nodes </param>
    public virtual void initialise(IList <string> nodeAddresses)
    {
        lock (@lock)
        {
            if (enabled.compareAndSet(false, true))
            {
                startScheduler(nodeAddresses.Count + 1);
            }
            else
            {
                scheduler.CorePoolSize = nodeAddresses.Count + 1;
            }

            IList <string> newNodeAddresses = new List <string>(nodeAddresses);

            for (IEnumerator <RemoteNodeProcessor> iterator = processors.GetEnumerator(); iterator.MoveNext();)
            {
                RemoteNodeProcessor processor = iterator.Current;

                if (!newNodeAddresses.Remove(processor.NodeAddress))
                {
                    processor.shutdown();
                    //JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                    iterator.remove();
                }
            }

            foreach (string nodeAddress in newNodeAddresses)
            {
                RemoteNodeProcessor processor = new RemoteNodeProcessor(playerManager, nodeAddress, scheduler, httpInterfaceManager, abandonedTrackManager);

                scheduler.submit(processor);
                processors.Add(processor);
            }

            activeProcessors = new List <RemoteNodeProcessor>(processors);
        }
    }
Example #10
0
 public override void Execute(ThreadStart runnable)
 {
     if (_latch.compareAndSet(false, true))
     {
         _jobScheduler.schedule(_group, () =>
         {
             try
             {
                 runnable.run();
             }
             finally
             {
                 _latch.set(false);
             }
         });
     }
 }
Example #11
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public void renderFrame(final com.twilio.video.I420Frame i420Frame)
        public override void renderFrame(I420Frame i420Frame)
        {
            // Capture bitmap and post to main thread
            if (snapshotRequsted.compareAndSet(true, false))
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final android.graphics.Bitmap bitmap = captureBitmap(i420Frame);
                Bitmap bitmap = captureBitmap(i420Frame);
                handler.post(() =>
                {
                    // Update the bitmap of image view
                    imageView.ImageBitmap = bitmap;

                    // Frames must be released after rendering to free the native memory
                    i420Frame.release();
                });
            }
            else
            {
                i420Frame.release();
            }
        }
 /// <summary>
 /// Close the connection.
 /// </summary>
 public virtual void close()
 {
     if (closed.compareAndSet(false, true))
     {
         try
         {
             if (Channel != null)
             {
                 var task = Channel.CloseAsync();
                 task.ContinueWith((t) =>
                 {
                     if (logger.IsEnabled(LogLevel.Information))
                     {
                         logger.LogInformation($"Close the connection to remote address={((IPEndPoint)Channel?.RemoteAddress)?.ToString()}, result={t.IsCompletedSuccessfully}, cause={t.Exception}");
                     }
                 });
             }
         }
         catch (Exception e)
         {
             logger.LogWarning("Exception caught when closing connection {}", ((IPEndPoint)Channel?.RemoteAddress)?.ToString(), e);
         }
     }
 }
Example #13
0
 public override bool CheckAndClearStale()
 {
     return(_stale.compareAndSet(true, false));
 }
Example #14
0
        public void testRetryStatic()
        {
            CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts,
                                                                       DefaultSessionTimeout,
                                                                       DefaultConnectionTimeout,
                                                                       null,
                                                                       new RetryOneTime(1));
            SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.RETRY);

            retryLoop.start();
            try
            {
                client.start();
                AtomicBoolean secondWasDone = new AtomicBoolean(false);
                AtomicBoolean firstTime     = new AtomicBoolean(true);
                SessionFailRetryLoop.callWithRetry
                (
                    client,
                    SessionFailRetryLoop.Mode.RETRY,
                    CallableUtils.FromFunc <object>(() =>
                {
                    RetryLoop.callWithRetry(
                        client,
                        CallableUtils.FromFunc <object>(() =>
                    {
                        Task <Stat> existsTask;
                        if (firstTime.compareAndSet(true, false))
                        {
                            existsTask = client.getZooKeeper().existsAsync("/foo/bar", false);
                            existsTask.Wait();
                            Assert.Null(existsTask.Result);
                            KillSession.kill(client.getZooKeeper(), ZkDefaultHosts, DefaultSessionTimeout);
                            client.getZooKeeper();
                            client.blockUntilConnectedOrTimedOut();
                        }
                        existsTask = client.getZooKeeper().existsAsync("/foo/bar", false);
                        existsTask.Wait();
                        Assert.Null(existsTask.Result);
                        return(null);
                    }
                                                        ));

                    RetryLoop.callWithRetry
                    (
                        client,
                        CallableUtils.FromFunc <object>(() =>
                    {
                        Assert.False(firstTime.get());
                        Task <Stat> existsTask = client.getZooKeeper().existsAsync("/foo/bar", false);
                        existsTask.Wait();
                        Assert.Null(existsTask.Result);
                        secondWasDone.set(true);
                        return(null);
                    }
                                                        ));
                    return(null);
                }
                                                    ));

                Assert.True(secondWasDone.get());
            }
            finally
            {
                retryLoop.Dispose();
                CloseableUtils.closeQuietly(client);
            }
        }
Example #15
0
        public void testExpiredSession()
        {
            // WARN: test requires that this must be address of one ZK host,
            // not a connection string to many nodes
            Barrier expiresBarrier        = new Barrier(2);
            Watcher watcher               = new ExpiredWatcher(expiresBarrier);
            CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts,
                                                                       DefaultSessionTimeout,
                                                                       DefaultConnectionTimeout,
                                                                       watcher,
                                                                       new RetryOneTime(2));

            client.start();
            try
            {
                AtomicBoolean firstTime = new AtomicBoolean(true);
                RetryLoop.callWithRetry(
                    client,
                    CallableUtils.FromFunc <object>(() =>
                {
                    if (firstTime.compareAndSet(true, false))
                    {
                        try
                        {
                            Task <string> createTask = client.getZooKeeper()
                                                       .createAsync("/foo",
                                                                    new byte[0],
                                                                    ZooDefs.Ids.OPEN_ACL_UNSAFE,
                                                                    CreateMode.PERSISTENT);
                            createTask.Wait();
                        }
                        catch (AggregateException e)
                        {
                            if (e.InnerException is KeeperException.NodeExistsException)
                            {
                                // ignore
                            }
                            else
                            {
                                throw e;
                            }
                        }

                        KillSession.kill(client.getZooKeeper(), ZkDefaultHosts, DefaultSessionTimeout * 3);
                        Assert.True(expiresBarrier.SignalAndWait(DefaultSessionTimeout));
                    }
                    ZooKeeper zooKeeper = client.getZooKeeper();
                    client.blockUntilConnectedOrTimedOut();
                    Task <Stat> task = zooKeeper.existsAsync("/foo", false);
                    task.Wait();
                    Stat stat = task.Result;
                    Assert.NotNull(stat);
                    Assert.Greater(stat.getCzxid(), 0);
                    return(null);
                })
                    );
            }
            finally
            {
                client.Dispose();
            }
        }
Example #16
0
 /**
  * Start compiling
  */
 public bool startCompiling()
 {
     return(_isCompiling.compareAndSet(false, true));
 }