ConnectHandle IConsumerConnector.ConnectConsumer <TConsumer>(IConsumePipeConnector consumePipe, IConsumerFactory <TConsumer> consumerFactory, IPipeSpecification <ConsumerConsumeContext <TConsumer> >[] pipeSpecifications) { var handles = new List <ConnectHandle>(); try { foreach (IConsumerMessageConnector connector in _connectors) { ConnectHandle handle = connector.ConnectConsumer(consumePipe, consumerFactory, pipeSpecifications); handles.Add(handle); } return(new MultipleConnectHandle(handles)); } catch (Exception) { foreach (ConnectHandle handle in handles) { handle.Dispose(); } throw; } }
void HandleFault() { var source = new TaskCompletionSource <Fault <TRequest> >(); MessageHandler <Fault <TRequest> > messageHandler = context => { try { Fail(context.Message); source.TrySetResult(context.Message); } catch (Exception ex) { source.TrySetException(ex); Fail(ex); } return(TaskUtil.Completed); }; ConnectHandle connectHandle = _bus.ConnectRequestHandler(_requestId, messageHandler); _connections.Add(typeof(Fault <TRequest>), new RequestHandlerHandle <Fault <TRequest> >(connectHandle, source)); }
Task <T> RequestContext.Handle <T>(MessageHandler <T> handler) { if (_connections.ContainsKey(typeof(T))) { throw new RequestException($"Only one handler of type {TypeMetadataCache<T>.ShortName} can be registered"); } var source = new TaskCompletionSource <T>(); MessageHandler <T> messageHandler = async context => { try { await Task.Factory.StartNew(() => handler(context), context.CancellationToken, TaskCreationOptions.None, _taskScheduler); source.TrySetResult(context.Message); Complete(); } catch (Exception ex) { source.TrySetException(ex); Fail(ex); } }; ConnectHandle connectHandle = _bus.ConnectRequestHandler(_requestId, messageHandler); _connections.Add(typeof(T), new RequestHandlerHandle <T>(connectHandle, source)); return(source.Task); }
public TerminalNode(ITupleSource <T> tupleSource, IndexMap indexMap) { _indexMap = indexMap; _ruleNodes = new ConnectableList <IRuleNode <T> >(); _handle = tupleSource.Connect(this); }
Task <T> RequestContext.Handle <T>(MessageHandler <T> handler) { var source = new TaskCompletionSource <T>(); MessageHandler <T> messageHandler = async context => { try { await Task.Factory.StartNew(() => handler(context), context.CancellationToken, TaskCreationOptions.None, _taskScheduler); source.TrySetResult(context.Message); Complete(); } catch (Exception ex) { source.TrySetException(ex); Fail(ex); } }; ConnectHandle connectHandle = _bus.ConnectRequestHandler(_requestId, messageHandler); _connections.Add(new HandlerHandle <T>(connectHandle, source)); return(source.Task); }
Task <T> RequestContext.Handle <T>() { var source = new TaskCompletionSource <T>(); MessageHandler <T> messageHandler = context => { try { source.TrySetResult(context.Message); Complete(); } catch (Exception ex) { source.TrySetException(ex); Fail(ex); } return(TaskUtil.Completed); }; ConnectHandle connectHandle = _bus.ConnectRequestHandler(_requestId, messageHandler); _connections.Add(new HandlerHandle <T>(connectHandle, source)); return(source.Task); }
public ConnectHandle ConnectSaga <T>(IConsumePipeConnector consumePipe, ISagaRepository <T> sagaRepository, params IPipeSpecification <SagaConsumeContext <T> >[] pipeSpecifications) where T : class, ISaga { var handles = new List <ConnectHandle>(); try { foreach (ISagaMessageConnector connector in _connectors) { ConnectHandle handle = connector.ConnectSaga(consumePipe, sagaRepository, pipeSpecifications); handles.Add(handle); } return(new MultipleConnectHandle(handles)); } catch (Exception) { foreach (ConnectHandle handle in handles) { handle.Dispose(); } throw; } }
/// <summary> /// Subscribes a message handler to the bus, which is disconnected after the message /// is received. /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="filter">A filter that only completes the task if filter is true</param> /// <returns>An awaitable task completed when the message is received</returns> public Task <ConsumeContext <T> > SubscribeHandler <T>(Func <ConsumeContext <T>, bool> filter) where T : class { TaskCompletionSource <ConsumeContext <T> > source = TaskUtil.GetTask <ConsumeContext <T> >(); ConnectHandle handler = null; handler = Bus.ConnectHandler <T>(async context => { if (filter(context)) { handler.Disconnect(); source.SetResult(context); } }); TestCancelledTask.ContinueWith(x => { handler.Disconnect(); source.TrySetCanceled(); }, TaskContinuationOptions.OnlyOnCanceled); return(source.Task); }
public void CloseSocketTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 target.CloseSocket(); Assert.Inconclusive("无法验证不返回值的方法。"); }
public SetPrefetchCountConsumer(IConsumePipeConnector managementPipe, ModelContext modelContext, ISetPrefetchCount filter) { _modelContext = modelContext; _filter = filter; _handle = managementPipe.ConnectInstance(this); }
public virtual async Task Start() { _sent = new TestSendObserver(TestTimeout); _consumed = new BusTestConsumeObserver(TestTimeout); _published = new BusTestPublishObserver(TestTimeout); PreCreateBus?.Invoke(this); _bus = CreateBus(); ConnectObservers(_bus); _busHandle = await _bus.StartAsync().ConfigureAwait(false); BusSendEndpoint = await GetSendEndpoint(_bus.Address).ConfigureAwait(false); InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false); _inputQueueSendObserver = InputQueueSendEndpoint.ConnectSendObserver(_sent); _busConsumeObserver = _bus.ConnectConsumeObserver(_consumed); _busPublishObserver = _bus.ConnectPublishObserver(_published); _busSendObserver = _bus.ConnectSendObserver(_sent); }
public virtual async Task Stop() { try { _receiveEndpointObserver?.Disconnect(); _receiveEndpointObserver = null; _busSendObserver?.Disconnect(); _busSendObserver = null; _inputQueueSendObserver?.Disconnect(); _inputQueueSendObserver = null; _busPublishObserver?.Disconnect(); _busPublishObserver = null; _busConsumeObserver?.Disconnect(); _busConsumeObserver = null; using (var tokenSource = new CancellationTokenSource(TestTimeout)) { await(_busHandle?.StopAsync(tokenSource.Token) ?? TaskUtil.Completed).ConfigureAwait(false); } } catch (Exception ex) { _log.Error("Bus Stop Failed: ", ex); throw; } finally { _busHandle = null; _bus = null; } }
public Observer(IReceiveEndpoint endpoint, CancellationToken cancellationToken) { _cancellationToken = cancellationToken; _ready = TaskUtil.GetTask <ReceiveEndpointReady>(); _handle = endpoint.ConnectReceiveEndpointObserver(this); }
public ReceiveEndpoint(IReceiveTransport receiveTransport, ReceiveEndpointContext context) { _context = context; _receiveTransport = receiveTransport; _handle = receiveTransport.ConnectReceiveTransportObserver(new Observer(this, context.EndpointObservers)); }
public virtual async Task Start(CancellationToken cancellationToken = default) { _received = new BusTestReceiveObserver(TestInactivityTimeout); _receiveInactivityHandle = _received.ConnectInactivityObserver(InactivityObserver); _consumed = new BusTestConsumeObserver(TestTimeout, InactivityToken); _published = new BusTestPublishObserver(TestTimeout, InactivityToken); _sent = new BusTestSendObserver(TestTimeout, InactivityToken); PreCreateBus?.Invoke(this); BusControl = CreateBus(); ConnectObservers(BusControl); _busHandle = await BusControl.StartAsync(cancellationToken).ConfigureAwait(false); BusSendEndpoint = await GetSendEndpoint(BusControl.Address).ConfigureAwait(false); InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false); _inputQueueSendObserver = InputQueueSendEndpoint.ConnectSendObserver(_sent); _busConsumeObserver = BusControl.ConnectConsumeObserver(_consumed); _busPublishObserver = BusControl.ConnectPublishObserver(_published); _busReceiveObserver = BusControl.ConnectReceiveObserver(_received); _busSendObserver = BusControl.ConnectSendObserver(_sent); }
public Task PostStop(IBus bus) { _handle?.Disconnect(); _handle = null; return(TaskUtil.Completed); }
Task <T> RequestContext.Handle <T>() { if (_connections.ContainsKey(typeof(T))) { throw new RequestException($"Only one handler of type {TypeMetadataCache<T>.ShortName} can be registered"); } var source = new TaskCompletionSource <T>(); MessageHandler <T> messageHandler = context => { try { source.TrySetResult(context.Message); Complete(); } catch (Exception ex) { source.TrySetException(ex); Fail(ex); } return(TaskUtil.Completed); }; ConnectHandle connectHandle = _bus.ConnectRequestHandler(_requestId, messageHandler); _connections.Add(typeof(T), new RequestHandlerHandle <T>(connectHandle, source)); return(source.Task); }
public SetModelPrefetchCountProxy(Mediator <ISetPrefetchCount> mediator, ModelContext modelContext, ISetPrefetchCount filter) { _modelContext = modelContext; _filter = filter; _handle = mediator.Connect(this); }
public Observer(IReceiveEndpoint endpoint, CancellationToken cancellationToken) { _cancellationToken = cancellationToken; _ready = new TaskCompletionSource <ReceiveEndpointReady>(); _handle = endpoint.ConnectReceiveEndpointObserver(this); }
public ResponseHandlerConnectHandle(ConnectHandle handle, TaskCompletionSource <ConsumeContext <TResponse> > completed, Task requestTask) { _handle = handle; _completed = completed; _requestTask = requestTask; Task = GetTask(); }
public void DisconnectAtClientEventArgsConstructorTest() { ConnectHandle aceClientHandlerAtClient = ConnectHandle.Zero; // TODO: 初始化为适当的值 ConnectHandleManager aceSocketHandlerManagerAtClient = ConnectHandleManager.Zero; // TODO: 初始化为适当的值 DisconnectAtClientEventArgs target = new DisconnectAtClientEventArgs(aceClientHandlerAtClient, aceSocketHandlerManagerAtClient); Assert.Inconclusive("TODO: 实现用来验证目标的代码"); }
public ReceiveEndpoint(IReceiveTransport receiveTransport, ReceiveEndpointContext context) { _context = context; _receiveTransport = receiveTransport; _started = TaskUtil.GetTask <ReceiveEndpointReady>(); _handle = receiveTransport.ConnectReceiveTransportObserver(new Observer(this, context.EndpointObservers)); }
public void ServerAddressTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 string actual; actual = target.ServerAddress; Assert.Inconclusive("验证此测试方法的正确性。"); }
public void SendToTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 MessageBlock sendMessageBlock = MessageBlock.Zero; // TODO: 初始化为适当的值 target.SendTo(sendMessageBlock); Assert.Inconclusive("无法验证不返回值的方法。"); }
public void IsOnlineTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 bool actual; actual = target.IsOnline; Assert.Inconclusive("验证此测试方法的正确性。"); }
public void FirstTimeTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 long actual; actual = target.FirstTime; Assert.Inconclusive("验证此测试方法的正确性。"); }
public void MessageBlockNumbersTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 long actual; actual = target.MessageBlockNumbers; Assert.Inconclusive("验证此测试方法的正确性。"); }
public void LastMessageBlockTimeTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 long actual; actual = target.LastMessageBlockTime; Assert.Inconclusive("验证此测试方法的正确性。"); }
public void RemoteOnlyIPTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 string actual; actual = target.RemoteOnlyIP; Assert.Inconclusive("验证此测试方法的正确性。"); }
public void RemotePortTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 int actual; actual = target.RemotePort; Assert.Inconclusive("验证此测试方法的正确性。"); }
public void ValueTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 IntPtr expected = new IntPtr(); // TODO: 初始化为适当的值 IntPtr actual; target.Handle = expected; actual = target.Handle; Assert.AreEqual( expected, actual ); Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void SocketHandlerManagerTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 ConnectHandleManager expected = ConnectHandleManager.Zero; // TODO: 初始化为适当的值 ConnectHandleManager actual; target.SocketHandlerManager = expected; actual = target.SocketHandlerManager; Assert.AreEqual( expected, actual ); Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void LastMessageBlockTimeTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 long actual; actual = target.LastMessageBlockTime; Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void SendToTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 MessageBlock sendMessageBlock = MessageBlock.Zero; // TODO: 初始化为适当的值 target.SendTo( sendMessageBlock ); Assert.Inconclusive( "无法验证不返回值的方法。" ); }
public void CloseSocketTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 target.CloseSocket(); Assert.Inconclusive( "无法验证不返回值的方法。" ); }
public void ConnectHandleConstructorTest() { ConnectHandle target = new ConnectHandle(); Assert.Inconclusive( "TODO: 实现用来验证目标的代码" ); }
public void ServerAddressTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 string actual; actual = target.ServerAddress; Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void FirstTimeTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 long actual; actual = target.FirstTime; Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void RemoteOnlyIPTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 string actual; actual = target.RemoteOnlyIP; Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void IsOnlineTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 bool actual; actual = target.IsOnline; Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void RemotePortTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 int actual; actual = target.RemotePort; Assert.Inconclusive( "验证此测试方法的正确性。" ); }
public void MessageBlockNumbersTest() { ConnectHandle target = new ConnectHandle(); // TODO: 初始化为适当的值 long actual; actual = target.MessageBlockNumbers; Assert.Inconclusive( "验证此测试方法的正确性。" ); }