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); }
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); } } }
void UnregisterLinkedTokens() { var registrations = linkedTokens.GetAndSet(null); if (registrations == null) { return; } foreach (var linked in registrations) { linked.Dispose(); } }
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(); }
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(); }
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; } } }
public override Task <bool> Acquire(Action <Exception> leaseLostCallback) { currentCallBack.GetAndSet(leaseLostCallback); return(Acquire()); }
public void SetNextAcquireResult(Task <bool> next) => nextAcquireResult.GetAndSet(next);
internal void SetActorLease(IActorRef client) { leaseActor.GetAndSet(client); }
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(); } }
/** * Set the value to show for this monitor. */ public void setValue(String value) { info.GetAndSet(value); }
public void SetActorLease(IActorRef client) { leaseActor.GetAndSet(client); }