public Buffer(int size, ISubscriberPort <T> stage1, IPublisherPort <T[]> output) { _size = size; _output = output; _buffer = new T[size]; stage1.Subscribe(OnReceive); }
/// <summary> /// Subscribe to a port but only consume the last msg per interval /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="receive"></param> /// <param name="interval"></param> /// <returns></returns> public static IDisposable SubscribeToLast <T>(this IFiber fiber, ISubscriberPort <T> port, Action <T> receive, TimeSpan interval) { return(new LastSubscriber <T>(port, fiber, interval, receive)); }
/// <summary>Method that subscribe to a periodic batch. </summary> /// <typeparam name="T"> Generic type parameter. </typeparam> /// <param name="port"> The port to act on. </param> /// <param name="fiber"> The fiber. </param> /// <param name="receive"> The receive. </param> /// <param name="interval"> The interval. </param> /// <returns> . </returns> public static IDisposable SubscribeToBatch <T>(this ISubscriberPort <T> port, IFiber fiber, Action <T[]> receive, TimeSpan interval) { return(new BatchSubscriber <T>(port, fiber, interval, receive)); }
/// <summary> /// Quick way to connect a Subscriber port to a Publisher port. Useful connecting channels and Agents /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="receive"></param> /// <returns></returns> public static IDisposable Connect <T>(this ISubscriberPort <T> port, IPublisherPort <T> receive) { var stub = StubFiber.StartNew(); port.Subscribe(stub, receive.Publish); return(stub); }
/// <summary> /// Subscribe to a periodic batch, maintaining the last item by key /// </summary> /// <typeparam name="TKey"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="keyResolver"></param> /// <param name="receive"></param> /// <param name="interval"></param> /// <returns></returns> public static IDisposable SubscribeToKeyedBatch <TKey, T>(this IFiber fiber, ISubscriberPort <T> port, Converter <T, TKey> keyResolver, Action <IDictionary <TKey, T> > receive, TimeSpan interval) { return(new KeyedBatchSubscriber <TKey, T>(port, fiber, interval, keyResolver, receive)); }
public LastSubscriber(ISubscriberPort <T> channel, IFiber fiber, TimeSpan interval, Action <T> target) : base(channel, fiber, interval) { _target = target; }
public BatchSubscriber(ISubscriberPort <T> channel, IFiber fiber, TimeSpan interval, Action <T[]> receive) : base(channel, fiber, interval) { _receive = receive; }
public KeyedBatchSubscriber(ISubscriberPort <T> channel, IFiber fiber, TimeSpan interval, Converter <T, TKey> keyResolver, Action <IDictionary <TKey, T> > target) : base(channel, fiber, interval) { _keyResolver = keyResolver; _target = target; }
public SnapshotRequest(IFiber fiber, ISubscriberPort <T> updatesPort, Action <T> receive, Action <TSnapshot> receiveSnapshot) { _fiber = fiber; _updatesPort = updatesPort; _receive = receive; _receiveSnapshot = receiveSnapshot; _fiber.Add(this); }
public ConcurrentComponent(IProcessor <TIn, TOut> processor, ISubscriberPort <TIn> input, IPublisherPort <TOut> output, IPublisherPort <Exception> error, FiberType type = FiberType.Pool) : base(new ExceptionHandlingExecutor(error.Publish), type) { processor.Exception += error.Publish; processor.Output += output.Publish; processor.Initialize(this); input.Subscribe(Fiber, processor.Process); }
public AsyncSnapshotRequest(IAsyncFiber fiber, ISubscriberPort <T> updatesPort, Func <T, Task> receive, Func <TSnapshot, Task> receiveSnapshot) { _fiber = fiber; _updatesPort = updatesPort; _receive = receive; _receiveSnapshot = receiveSnapshot; _fiber.Add(this); }
public AsyncComponent(IAsyncProcessor <TIn, TOut> processor, ISubscriberPort <TIn> input, IPublisherPort <TOut> output, IPublisherPort <Exception> error) { _processor = processor; _output = output; _error = error; processor.Exception += error.Publish; processor.Output += output.Publish; processor.Initialize(Fiber); input.Subscribe(Fiber, processor.Process); }
/// <summary> /// Subscribe with a message predicate to filter messages /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="receive"></param> /// <param name="filter"></param> /// <returns></returns> public static IDisposable Subscribe <T>(this ISubscriberPort <T> port, IFiber fiber, Action <T> receive, Predicate <T> filter) { Action <T> filteredReceiver = x => { if (filter(x)) { fiber.Enqueue(() => receive(x)); } }; //we use a stub fiber to force the filtering onto the publisher thread. return(port.Subscribe(StubFiber.StartNew(), filteredReceiver)); }
/// <summary> /// Subscribe with a message predicate to filter messages /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="receive"></param> /// <param name="filter"></param> /// <returns></returns> public static IDisposable Subscribe <T>(this IFiber fiber, ISubscriberPort <T> port, Action <T> receive, Predicate <T> filter) { void FilteredReceiver(T x) { if (filter(x)) { fiber.Enqueue(() => receive(x)); } } IDisposable sub = port.Subscribe(FilteredReceiver); return(new Unsubscriber(sub, fiber)); }
/// <summary> /// Subscribe with a message predicate to filter messages /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="receive"></param> /// <param name="filter"></param> /// <returns></returns> public static IDisposable Subscribe <T>(this IAsyncFiber fiber, ISubscriberPort <T> port, Func <T, Task> receive, Predicate <T> filter) { void FilteredReceiver(T x) { if (filter(x)) { fiber.Enqueue(() => receive(x)); } } //we use a stub fiber to force the filtering onto the publisher thread. IDisposable sub = port.Subscribe(FilteredReceiver); return(new Unsubscriber(sub, fiber)); }
/// <summary> /// Subscribe with a message predicate to filter messages /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="receive"></param> /// <param name="filter"></param> /// <returns></returns> public static IDisposable Subscribe <T>(this IFiber fiber, ISubscriberPort <T> port, Action <T> receive, Predicate <T> filter) { void FilteredReceiver(T x) { if (filter(x)) { fiber.Enqueue(() => receive(x)); } } //we use a stub fiber to force the filtering onto the publisher thread. var stub = StubFiber.StartNew(); port.Subscribe(stub, FilteredReceiver); return(stub); }
public CompositeStage(IPublisherPort <TIn> input, ISubscriberPort <TOut> output, IDisposable disposables) { _input = input; _output = output; _disposables = disposables; }
/// <summary> /// Quick way to connect a Subscriber port to a Publisher port. Useful connecting channels and Agents /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="receive"></param> /// <returns></returns> public static IDisposable Connect <T>(this ISubscriberPort <T> port, IFiber fiber, IPublisherPort <T> receive) { return(port.Subscribe(StubFiber.StartNew(), x => receive.Publish(x))); }
/// <summary>Method that subscribe to a periodic batch. </summary> /// <typeparam name="T"> Generic type parameter. </typeparam> /// <param name="port"> The port to act on. </param> /// <param name="fiber"> The fiber. </param> /// <param name="receive"> The receive. </param> /// <param name="interval"> The interval. </param> /// <returns> . </returns> public static IDisposable SubscribeToBatch <T>(this IAsyncFiber fiber, ISubscriberPort <T> port, Func <T[], Task> receive, TimeSpan interval) => new AsyncBatchSubscriber <T>(port, fiber, interval, receive);
/// <summary> /// Subscribe to a periodic batch, maintaining the last item by key /// </summary> /// <typeparam name="TKey"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="keyResolver"></param> /// <param name="receive"></param> /// <param name="interval"></param> /// <returns></returns> public static IDisposable SubscribeToKeyedBatch <TKey, T>(this IAsyncFiber fiber, ISubscriberPort <T> port, Converter <T, TKey> keyResolver, Func <IDictionary <TKey, T>, Task> receive, TimeSpan interval) => new AsyncKeyedBatchSubscriber <TKey, T>(port, fiber, interval, keyResolver, receive);
public AsyncLastSubscriber(ISubscriberPort <T> channel, IAsyncFiber fiber, TimeSpan interval, Func <T, Task> target) : base(channel, fiber, interval) =>
/// <summary> /// Subscribe to a channel from the fiber. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fiber"></param> /// <param name="channel"></param> /// <param name="handler"></param> /// <returns></returns> public static IDisposable Subscribe <T>(this IAsyncFiber fiber, ISubscriberPort <T> channel, Func <T, Task> handler) => channel.Subscribe(fiber, handler);
protected AsyncBatchSubscriberBase(ISubscriberPort <T> channel, IAsyncFiber fiber, TimeSpan interval) { _sub = channel.Subscribe(fiber, OnMessageAsync); Fiber = fiber; Interval = interval; }
public RoundRobinFanOut(ISubscriberPort <T> port) => port.Subscribe(OnReceive);
public void SetUpSubscribe(ISubscriberPort <T> port) => port.Subscribe(_fiber, OnReceive);
/// <summary> /// Quick way to connect a Subscriber port to a Publisher port. Useful connecting channels and Agents /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="receive"></param> /// <returns></returns> public static IDisposable Connect <T>(this ISubscriberPort <T> port, IPublisherPort <T> receive) => port.Subscribe(receive.Publish);
/// <summary> /// Subscribe to a port but only consume the last msg per interval /// </summary> /// <typeparam name="T"></typeparam> /// <param name="port"></param> /// <param name="fiber"></param> /// <param name="receive"></param> /// <param name="interval"></param> /// <returns></returns> public static IDisposable SubscribeToLast <T>(this ISubscriberPort <T> port, IAsyncFiber fiber, Func <T, Task> receive, TimeSpan interval) => new AsyncLastSubscriber <T>(port, fiber, interval, receive);
/// <summary> /// Subscribe to a channel from the fiber. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fiber"></param> /// <param name="channel"></param> /// <param name="handler"></param> /// <returns></returns> public static IDisposable Subscribe <T>(this IFiber fiber, ISubscriberPort <T> channel, Action <T> handler) { return(channel.Subscribe(fiber, handler)); }
public AsyncBatchSubscriber(ISubscriberPort <T> channel, IAsyncFiber fiber, TimeSpan interval, Func <T[], Task> receive) : base(channel, fiber, interval) =>