Ejemplo n.º 1
0
        public void GetAndSet_returns_old_value()
        {
            var value = new object();
            var obj = new AtomicReference<object>(value);

            var actual = obj.GetAndSet(new object());

            Assert.AreEqual(value, actual);
        }
Ejemplo n.º 2
0
        public void GetAndSet_sets_new_value()
        {
            var obj = new AtomicReference<object>();
            var value = new object();

            obj.GetAndSet(value);

            Assert.AreEqual(value, obj.Value);
        }
        public void HandleTransportFailure(Exception e)
        {
            ITransport transport = connectedTransport.GetAndSet(null);

            if (transport != null)
            {
                transport.Command   = new CommandHandler(disposedOnCommand);
                transport.Exception = new ExceptionHandler(disposedOnException);
                try
                {
                    transport.Stop();
                }
                catch (Exception ex)
                {
                    ex.GetType();       // Ignore errors but this lets us see the error during debugging
                }

                lock (reconnectMutex)
                {
                    bool reconnectOk = false;
                    if (started)
                    {
                        Tracer.WarnFormat("Transport failed to {0}, attempting to automatically reconnect due to: {1}", ConnectedTransportURI.ToString(), e.Message);
                        reconnectOk = true;
                    }

                    initialized = false;
                    failedConnectTransportURI = ConnectedTransportURI;
                    ConnectedTransportURI     = null;
                    connected = false;
                    if (reconnectOk)
                    {
                        reconnectTask.Wakeup();
                    }
                }

                if (this.Interrupted != null)
                {
                    this.Interrupted(transport);
                }
            }
        }
Ejemplo n.º 4
0
        void UnregisterLinkedTokens()
        {
            var registrations = linkedTokens.GetAndSet(null);

            if (registrations == null)
            {
                return;
            }
            foreach (var linked in registrations)
            {
                linked.Dispose();
            }
        }
Ejemplo n.º 5
0
        public void TestSendAndReceiveNoOriginalContentType()
        {
            var binder = GetBinder();

            var delimiter                 = GetDestinationNameDelimiter();
            var bindingsOptions           = new RabbitBindingsOptions();
            var producerOptions           = GetProducerOptions("input", bindingsOptions);
            var producerBindingProperties = CreateProducerBindingOptions(producerOptions);

            var moduleOutputChannel = CreateBindableChannel("output", producerBindingProperties);

            var consumerProperties     = GetConsumerOptions("output", bindingsOptions);
            var inputBindingProperties = CreateConsumerBindingOptions(consumerProperties);
            var moduleInputChannel     = CreateBindableChannel("input", inputBindingProperties);

            var producerBinding = binder.BindProducer($"bar{delimiter}0", moduleOutputChannel, producerBindingProperties.Producer);
            var consumerBinding = binder.BindConsumer($"bar{delimiter}0", "testSendAndReceiveNoOriginalContentType", moduleInputChannel, consumerProperties);

            BinderBindUnbindLatency();
            var message = MessageBuilder.WithPayload("foo").SetHeader("contentType", MimeTypeUtils.TEXT_PLAIN).Build();

            moduleOutputChannel.Send(message);
            var latch             = new CountdownEvent(1);
            var inboundMessageRef = new AtomicReference <IMessage>();

            moduleInputChannel.Subscribe(new TestMessageHandler()
            {
                OnHandleMessage = (message) =>
                {
                    inboundMessageRef.GetAndSet(message);
                    latch.Signal();
                }
            });

            moduleOutputChannel.Send(message);

            Assert.True(latch.Wait(TimeSpan.FromSeconds(5)), "Failed to receive message");
            Assert.NotNull(inboundMessageRef.Value);
            Assert.Equal("foo", ((byte[])inboundMessageRef.Value.Payload).GetString());
            Assert.Equal("text/plain", inboundMessageRef.Value.Headers.ContentType());

            producerBinding.Unbind();
            consumerBinding.Unbind();
        }
Ejemplo n.º 6
0
        public void TestSendAndReceive()
        {
            var ccf             = GetResource();
            var bindingsOptions = new RabbitBindingsOptions();
            var binder          = GetBinder(bindingsOptions);
            var delimiter       = GetDestinationNameDelimiter();

            var producerOptions         = GetProducerOptions("input", bindingsOptions);
            var consumerProperties      = GetConsumerOptions("output", bindingsOptions);
            var outputBindingProperties = CreateProducerBindingOptions(producerOptions);
            var moduleOutputChannel     = CreateBindableChannel("output", GetDefaultBindingOptions());

            var inputBindingProperties = CreateConsumerBindingOptions(consumerProperties);
            var moduleInputChannel     = CreateBindableChannel("input", GetDefaultBindingOptions());

            var producerBinding = binder.BindProducer($"foo{delimiter}0", moduleOutputChannel, producerOptions);
            var consumerBinding = binder.BindConsumer($"foo{delimiter}0", "testSendAndReceive", moduleInputChannel, consumerProperties);
            var message         = MessageBuilder.WithPayload("foo").SetHeader(MessageHeaders.CONTENT_TYPE, MimeType.ToMimeType("text/plain")).Build();

            var latch             = new CountdownEvent(1);
            var inboundMessageRef = new AtomicReference <IMessage>();

            moduleInputChannel.Subscribe(new TestMessageHandler()
            {
                OnHandleMessage = (message) =>
                {
                    inboundMessageRef.GetAndSet(message);
                    latch.Signal();
                }
            });
            moduleOutputChannel.Send(message);

            Assert.True(latch.Wait(TimeSpan.FromSeconds(5)), "Failed to receive message");

            var actual = inboundMessageRef.Value;

            Assert.Equal("foo".GetBytes(), actual.Payload);
            Assert.Equal("text/plain", actual.Headers.ContentType());
            producerBinding.Unbind();
            consumerBinding.Unbind();
        }
Ejemplo n.º 7
0
        private void Rebuild(object state)
        {
            //TODO: cheaper waiting
            if (!_currentTokenSource.Value.IsCancellationRequested)
            {
                //Nothing to do
                return;
            }
            lock (_currentLock)
            {
                if (IsDisposed)
                {
                    return;
                }
                var newToken = new CancellationTokenSource();
                var oldToken = _currentTokenSource.GetAndSet(newToken);
                if (!oldToken.IsCancellationRequested)
                {
                    //Nothing to do
                    return;
                }

                var old = _current;
                Monitor.PulseAll(_currentLock);

                Dispose(old);

                try
                {
                    T newObject = Build(newToken.Token);
                    _current          = newObject;
                    _currentException = null;
                }
                catch (Exception e)
                {
                    _current          = null;
                    _currentException = e;
                }
            }
        }
Ejemplo n.º 8
0
 public override Task <bool> Acquire(Action <Exception> leaseLostCallback)
 {
     currentCallBack.GetAndSet(leaseLostCallback);
     return(Acquire());
 }
Ejemplo n.º 9
0
 public void SetNextAcquireResult(Task <bool> next) => nextAcquireResult.GetAndSet(next);
Ejemplo n.º 10
0
 internal void SetActorLease(IActorRef client)
 {
     leaseActor.GetAndSet(client);
 }
Ejemplo n.º 11
0
        public void Shutdown()
        {
            RequestBatch <BatchReturnType, RequestResponseType, RequestArgumentType> currentBatch = batch.GetAndSet(null);

            if (currentBatch != null)
            {
                currentBatch.Shutdown();
            }

            if (timerListenerReference.Value != null)
            {
                // if the timer was started we'll clear it so it stops ticking
                timerListenerReference.Value.Dispose();
            }
        }
Ejemplo n.º 12
0
 /**
  * Set the value to show for this monitor.
  */
 public void setValue(String value)
 {
     info.GetAndSet(value);
 }
Ejemplo n.º 13
0
 public void SetActorLease(IActorRef client)
 {
     leaseActor.GetAndSet(client);
 }