public MessageBusWriteStream(IProducer producer, string endPoint, string sequenceId, IConfiguration configuration)
 {
     _producer = producer;
     _endPoint = endPoint;
     _sequenceId = sequenceId;
     _configuration = configuration;
     _packetSize = producer.MaximumMessageSize;
     _packetsSent = 0;
 }
        public Manager(IProducer<Action> workProducer, int threadCount)
        {
            _workComplete = new ManualResetEvent(false);
            _producer = workProducer;

            _workers = new Thread[threadCount];
            _threadCount = threadCount;

            for (int i = 0; i < _workers.Length; i++)
            {
                _workers[i] = new Thread(GetWork) { Name = ("Worker " + i) };
            }
        }
Exemplo n.º 3
0
        public Coordinator(CommandProcessorContext context, 
                           IProducer[] producers, 
                           int totalTasks,
                           AutoResetEvent doneEvent)
        {
            Ensure.NotNull(context, "context");
            Ensure.NotNull(producers, "producers");
            Ensure.NotNull(doneEvent, "doneEvent");

            _context = context;
            _producers = producers;
            _totalTasks = totalTasks;
            _doneEvent = doneEvent;
        }
Exemplo n.º 4
0
        async void connectButton_Click(object sender, EventArgs e)
        {
            connectButton.Enabled = false;
            disconnectButton.Enabled = true;

            var hostname = hostnameTextBox.Text;
            var port = Convert.ToInt32(portTextBox.Text);
            var connectionString = string.Format("{0}:{1}", hostname, port);

            var c = BeanstalkConnection.ConnectConsumerAsync(connectionString);
            var p = BeanstalkConnection.ConnectProducerAsync(connectionString);
            await Task.WhenAll(c, p);
            consumer = c.Result;
            producer = p.Result;
        }
Exemplo n.º 5
0
        public Coordinator(CommandProcessorContext context, 
                           IProducer[] producers, 
                           int totalEvents,
                           AutoResetEvent createdEvent, 
                           AutoResetEvent doneEvent)
        {
            Ensure.NotNull(context, "context");
            Ensure.NotNull(producers, "producers");
            Ensure.NotNull(createdEvent, "createdEvent");
            Ensure.NotNull(doneEvent, "doneEvent");

            _context = context;
            _producers = producers;
            _totalEvents = totalEvents;
            _createdEvent = createdEvent;
            _doneEvent = doneEvent;

            _eventsForWriting = new ConcurrentVerificationEventQueue();
            _eventsForVerification = new ConcurrentVerificationEventQueue();
        }
		public Consumer(IProducer producer)
		{
			this.producer = producer;
		}
 public CreateProductRequestHandler(IProductRepository repository, IProducer producer)
 {
     _repository = repository;
     _producer   = producer;
 }
 public TracingProducer(ITracer tracer, IProducer <TKey, TValue> producer)
 {
     _tracer   = tracer;
     _producer = producer;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Returns the metadata associated with the specified stream, if the stream is persisted to a store.
 /// </summary>
 /// <typeparam name="T">The type of stream messages.</typeparam>
 /// <param name="source">The stream to retrieve metadata about.</param>
 /// <param name="metadata">Upon return, this parameter contains the metadata associated with the stream, or null if the stream is not persisted.</param>
 /// <returns>True if the stream is persisted to a store, false otherwise.</returns>
 public static bool TryGetMetadata <T>(IProducer <T> source, out PsiStreamMetadata metadata)
 {
     return(Store.TryGetMetadata(source.Out.Pipeline, source.Out.Name, out metadata));
 }
Exemplo n.º 10
0
 public DependingProducer(object id, CustomProducer producer)
 {
     Key = id;
     Producer = producer;
 }
Exemplo n.º 11
0
 protected ArrayDataField(DataHolderDefinition dataHolder, string name,
     IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent, int length, IProducer arrProducer)
     : base(dataHolder, name, accessor, mappedMember, parent)
 {
     m_length = length;
     m_arrProducer = arrProducer;
 }
Exemplo n.º 12
0
 public PublishMessageToKafka(IProducer <int, string> kafkaProducer)
 {
     _kafkaProducer = kafkaProducer;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Convert a stream to an <see cref="IObservable{T}"/>.
 /// </summary>
 /// <typeparam name="T">Type of messages for the source stream.</typeparam>
 /// <param name="stream">The source stream.</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>Observable with elements from the source stream.</returns>
 public static IObservable <T> ToObservable <T>(this IProducer <T> stream, DeliveryPolicy deliveryPolicy = null)
 {
     return(new StreamObservable <T>(stream, deliveryPolicy));
 }
Exemplo n.º 14
0
 public KafkaProducer(IKafkaConfig kafkaConfig)
 {
     Producer = new Producer <TKey, TValue>(kafkaConfig.ProducerConfig);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Connnects a stream producer to a stream consumer. As a result, all messages in the stream will be routed to the consumer for processing.
 /// </summary>
 /// <remarks>
 /// This is an internal-only method which provides the option to allow connections between producers and consumers in running pipelines.
 /// </remarks>
 /// <typeparam name="TIn">The type of messages in the stream.</typeparam>
 /// <typeparam name="TC">The type of consumer.</typeparam>
 /// <param name="source">The source stream to subscribe to.</param>
 /// <param name="consumer">The consumer (subscriber).</param>
 /// <param name="allowWhileRunning">An optional flag to allow connections in running pipelines.</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>Consumer.</returns>
 internal static TC PipeTo <TIn, TC>(this IProducer <TIn> source, TC consumer, bool allowWhileRunning, DeliveryPolicy deliveryPolicy = null)
     where TC : IConsumer <TIn>
 {
     source.Out.Subscribe(consumer.In, allowWhileRunning, deliveryPolicy ?? source.Out.Pipeline.DeliveryPolicy);
     return(consumer);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Connnects a stream producer to a stream consumer. As a result, all messages in the stream will be routed to the consumer for processing.
 /// </summary>
 /// <typeparam name="TIn">The type of messages in the stream.</typeparam>
 /// <typeparam name="TC">The type of consumer.</typeparam>
 /// <param name="source">The source stream to subscribe to.</param>
 /// <param name="consumer">The consumer (subscriber).</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>Consumer (subscriber).</returns>
 public static TC PipeTo <TIn, TC>(this IProducer <TIn> source, TC consumer, DeliveryPolicy deliveryPolicy = null)
     where TC : IConsumer <TIn>
 {
     return(PipeTo(source, consumer, false, deliveryPolicy));
 }
Exemplo n.º 17
0
 public NetStreamProducer(string topic, IProducer <TKey, TMessage> producer, bool enableMessageTypeHeader = true)
 {
     _topic    = topic;
     _producer = producer;
     _enableMessageTypeHeader = enableMessageTypeHeader;
 }
 public Manager(IProducer<Action> workProducer)
     : this(workProducer, Environment.ProcessorCount)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// Converts stream of enumerables of T to a stream of arrays of T,
 /// </summary>
 /// <typeparam name="T">The type of enumerable elements.</typeparam>
 /// <typeparam name="EnumerableT">The type of enumerable.</typeparam>
 /// <param name="source">The stream of enumerables of T.</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>A stream of the converted array of T.</returns>
 public static IProducer <T[]> ToArray <T, EnumerableT>(this IProducer <EnumerableT> source, DeliveryPolicy deliveryPolicy = null)
     where EnumerableT : IEnumerable <T>
 {
     return(source.Select(s => s.ToArray(), deliveryPolicy));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Converts stream of dictionarys of TKey and TValue to a stream of collections of TValue
 /// </summary>
 /// <typeparam name="TKey">The type of dictionary keys.</typeparam>
 /// <typeparam name="TValue">The type of dictionary values.</typeparam>
 /// <param name="source">The stream of dictionarys of TKey and TValue.</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>A stream of the converted collections of TValue.</returns>
 public static IProducer <Dictionary <TKey, TValue> .ValueCollection> Values <TKey, TValue>(this IProducer <Dictionary <TKey, TValue> > source, DeliveryPolicy deliveryPolicy = null)
 {
     return(source.Select(s => s.Values, deliveryPolicy));
 }
Exemplo n.º 21
0
 protected NestedDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, parent)
 {
     m_Producer = producer;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Converts stream of dictionarys of 2d points to a stream of list of named points
 /// </summary>
 /// <typeparam name="TKey">The type of dictionary keys.</typeparam>
 /// <param name="source">The stream of dictionarys of 2d points.</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>A stream of the converted list of named points.</returns>
 public static IProducer <List <Tuple <Point, string> > > ToScatterPoints2D <TKey>(this IProducer <Dictionary <TKey, Point2D> > source, DeliveryPolicy deliveryPolicy = null)
 {
     return(source.Select(d => d.Select(kvp => Tuple.Create(new Point(kvp.Value.X, kvp.Value.Y), kvp.Key.ToString())).ToList(), deliveryPolicy));
 }
Exemplo n.º 23
0
 public NestedSimpleDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
                              MemberInfo mappedMember, IProducer producer, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, producer, parent)
 {
 }
Exemplo n.º 24
0
 /// <summary>
 /// Converts stream of dictionarys of rectangles to a stream of list of named rectangles
 /// </summary>
 /// <typeparam name="TKey">The type of dictionary keys.</typeparam>
 /// <param name="source">The stream of dictionarys of rectangles.</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>A stream of the converted list of named rectangles.</returns>
 public static IProducer <List <Tuple <System.Drawing.Rectangle, string> > > ToScatterRectangle <TKey>(this IProducer <Dictionary <TKey, System.Drawing.Rectangle> > source, DeliveryPolicy deliveryPolicy = null)
 {
     return(source.Select(d => d.Select(kvp => Tuple.Create(kvp.Value, kvp.Key.ToString())).ToList(), deliveryPolicy));
 }
Exemplo n.º 25
0
 /// <summary>
 /// Constructs a new market definition. The market definition represents additional market data which can be used for more advanced use cases
 /// </summary>
 /// <param name="marketDescription">The associated market descriptor</param>
 /// <param name="marketCacheProvider">The market cache provider used to retrieve name templates</param>
 /// <param name="sportId">The associated event sport identifier</param>
 /// <param name="producer">The producer which generated the market</param>
 /// <param name="specifiers">The associated market specifiers</param>
 internal MarketDefinition(IMarketDescription marketDescription, IMarketCacheProvider marketCacheProvider, URN sportId, IProducer producer, IReadOnlyDictionary <string, string> specifiers)
 {
     _marketDescription   = marketDescription;
     _sportId             = sportId;
     _producer            = producer;
     _specifiers          = specifiers;
     _marketCacheProvider = marketCacheProvider;
 }
Exemplo n.º 26
0
 public SequentialMergerBuilder AddInput(IProducer input)
 {
     Merger.ProcessList.Add(input);
     return(this);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Writes the specified stream to a multi-stream store.
 /// </summary>
 /// <typeparam name="TIn">The type of messages in the stream.</typeparam>
 /// <param name="source">The source stream to write.</param>
 /// <param name="name">The name of the persisted stream.</param>
 /// <param name="writer">The store writer, created by e.g. <see cref="Store.Create(Pipeline, string, string, bool, KnownSerializers)"/>.</param>
 /// <param name="largeMessages">Indicates whether the stream contains large messages (typically >4k). If true, the messages will be written to the large message file.</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>The input stream.</returns>
 public static IProducer <TIn> Write <TIn>(this IProducer <TIn> source, string name, Exporter writer, bool largeMessages = false, DeliveryPolicy deliveryPolicy = null)
 {
     writer.Write(source.Out, name, largeMessages, deliveryPolicy);
     return(source);
 }
 public TestProducer(IProducer producer) => _producer = producer;
Exemplo n.º 29
0
 public ProducerWithLogging(IProducer producer)
 {
     this.producer = producer;
 }
Exemplo n.º 30
0
 /// <summary>
 /// Converts the source image to a different pixel format
 /// </summary>
 /// <param name="source">The source stream.</param>
 /// <param name="pixelFormat">The pixel format to convert to</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>The resulting stream.</returns>
 public static IProducer <Shared <Image> > Convert(this IProducer <Shared <Image> > source, PixelFormat pixelFormat, DeliveryPolicy deliveryPolicy = null)
 {
     return(source.PipeTo(new ToPixelFormat(source.Out.Pipeline, pixelFormat), deliveryPolicy));
 }
 private static void Runner(IProducer<Action> producer, int threadCount)
 {
     var pm = new Manager(producer, threadCount);
     pm.Start();
     pm.Join();
 }
Exemplo n.º 32
0
 /// <summary>
 /// Converts an image to a different pixel format using the specified transformer
 /// </summary>
 /// <param name="source">Source image to compress</param>
 /// <param name="transformer">Method for converting an image sample</param>
 /// <param name="pixelFormat">Pixel format to use for converted image</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <returns>Returns a producer that generates the transformed images</returns>
 public static IProducer <Shared <Image> > Transform(this IProducer <Shared <Image> > source, TransformDelegate transformer, PixelFormat pixelFormat, DeliveryPolicy deliveryPolicy = null)
 {
     return(source.PipeTo(new ImageTransformer(source.Out.Pipeline, transformer, pixelFormat), deliveryPolicy));
 }
 async Task ConnectAsync()
 {
     cons = await BeanstalkConnection.ConnectConsumerAsync(connectionString);
     prod = await BeanstalkConnection.ConnectProducerAsync(connectionString);
 }
Exemplo n.º 34
0
 public ServiceImplWithDependency(IProducer <int> producer)
 {
 }
Exemplo n.º 35
0
 /// <summary>
 /// Writes the specified stream to a Annotation store.
 /// </summary>
 /// <typeparam name="TIn">The type of messages in the stream</typeparam>
 /// <param name="source">The source stream to write</param>
 /// <param name="name">The name of the persisted stream.</param>
 /// <param name="writer">The store writer, created by e.g. <see cref="Create(Pipeline, string, string, AnnotatedEventDefinition, bool)"/></param>
 /// <param name="policy">An optional delivery policy</param>
 /// <returns>The input stream</returns>
 public static IProducer <TIn> Write <TIn>(this IProducer <TIn> source, string name, AnnotationExporter writer, DeliveryPolicy policy = null)
 {
     writer.Write(source.Out, name, policy);
     return(source);
 }
Exemplo n.º 36
0
 internal KafkaProducer(IProducer <string, string> innerKafkaProducer)
 {
     _innerKafkaProducer = innerKafkaProducer;
 }
Exemplo n.º 37
0
 public Consumer(IProducer producer)
 {
     _producer = producer;
 }
 public KafkaSender(IProducer <Null, byte[]> producer, string deviceId, RunnerConfiguration config, string topic)
     : base(deviceId, config)
 {
     this.producer = producer;
     this.topic    = topic;
 }
Exemplo n.º 39
0
 public NestedArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
     MemberInfo mappedMember,
     IProducer producer, IProducer arrayProducer, int length, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, parent, length, arrayProducer)
 {
     m_Producer = producer;
     m_ArrayAccessors = new NestedArrayAccessor[m_length];
     for (var i = 0; i < m_length; i++)
     {
         m_ArrayAccessors[i] = new NestedArrayAccessor(this, i);
     }
 }
 public void Dispose()
 {
     Close();
     _producer = null;
 }
Exemplo n.º 41
0
 public NestedSimpleDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
     MemberInfo mappedMember, IProducer producer, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, producer, parent)
 {
 }
Exemplo n.º 42
0
 public DependingProducer(object id, Type type)
 {
     Key = id;
     Producer = new DefaultProducer(type);
 }
Exemplo n.º 43
0
 /// <summary>
 /// Computes the linear velocity of a coordinate system.
 /// </summary>
 /// <param name="source">The source stream of coordinate systems.</param>
 /// <param name="deliveryPolicy">An optional delivery policy parameter.</param>
 /// <param name="name">An optional name for the stream operator.</param>
 /// <returns>A stream containing the linear velocity of the specified point.</returns>
 public static IProducer <LinearVelocity3D?> GetLinearVelocity3D(this IProducer <CoordinateSystem> source, DeliveryPolicy <CoordinateSystem> deliveryPolicy = null, string name = nameof(GetLinearVelocity3D))
 => source.GetLinearVelocity3D(cs => cs?.Origin, deliveryPolicy, name);
 public ObservingDataController(IProducer producer, IConsumer consumer)
 {
     _producer = producer;
     _consumer = consumer;
 }
Exemplo n.º 45
0
 public KafkaProducer(IEnumerable <KeyValuePair <string, string> > configuration)
 {
     _innerKafkaProducer = new ProducerBuilder <string, string>(configuration).Build();
 }
Exemplo n.º 46
0
 public TaskCreator(InternalTopologyBuilder builder, IStreamConfig configuration, string threadId, IKafkaSupplier kafkaSupplier, IProducer <byte[], byte[]> producer)
     : base()
 {
     this.builder       = builder;
     this.configuration = configuration;
     this.threadId      = threadId;
     this.kafkaSupplier = kafkaSupplier;
     this.producer      = producer;
 }
Exemplo n.º 47
0
 public DependingProducer(object id, Func<object> creator)
 {
     Key = id;
     Producer = new CustomProducer(creator);
 }
Exemplo n.º 48
0
 public KafkaClient(string bootstrapServers)
 {
     ConfigureProducer(bootstrapServers);
     _producer = new ProducerBuilder <string, string>(_producerConfig).Build();
     ConfigureConsumer(bootstrapServers);
 }
Exemplo n.º 49
0
        public DataHolderDefinition(string name, Type type, string dependingField, DataHolderAttribute attribute)
        {
            m_name = name;
            m_DependingFieldName = dependingField;
            m_Attribute = attribute;
            m_Type = type;

            var dependingProducerTypes = type.GetCustomAttributes<DependingProducer>();
            if (dependingProducerTypes.Length == 0)
            {
                m_dependingProducers = null;
            }
            else
            {
                m_dependingProducers = new Dictionary<object, IProducer>();
                foreach (var prodAttr in dependingProducerTypes)
                {
                    var key = prodAttr.Key;
                    //var keyType = key.GetType();
                    //if (keyType.IsEnum)
                    //{
                    //    key = Convert.ChangeType(key, Enum.GetUnderlyingType(keyType));
                    //}
                    //if (key is uint)
                    //{
                    //    key = (int)((uint)key);
                    //}
                    //else if (key is ulong)
                    //{
                    //    key = (long)((ulong)key);
                    //}
                    m_dependingProducers.Add(key, prodAttr.Producer);
                }
            }

            if (type.IsAbstract)
            {
                if (m_dependingProducers == null)
                {
                    throw new DataHolderException(
                        "Cannot define DataHolder because it's Type is abstract and it did not define depending Producers: {0}",
                        type.FullName);
                }
                if (m_DependingFieldName == null)
                {
                    throw new DataHolderException(
                        "Cannot define DataHolder because it's Type is abstract and it did not define the DependsOnField in the DataHolderAttribute: {0}",
                        type.FullName);
                }
            }
            else
            {
                m_defaultProducer = new DefaultProducer(type);
            }

            try
            {
                GetDataFields(type, Fields, null);
                if (type.IsAbstract && m_DependingField == null)
                {
                    throw new DataHolderException(
                        "Cannot define DataHolder because it's DependsOnField (\"{0}\"), as defined in the DataHolderAttribute, does not exist: {1}",
                        m_DependingFieldName, type.FullName);
                }
            }
            catch (Exception e)
            {
                throw new DataHolderException(e, "Unable to create DataHolderDefinition for: " + name);
            }
        }
Exemplo n.º 50
0
        public void Initialize()
        {
            // Initializes the mock RequestListener
            ProducerListenerImpl producerListener = new ProducerListenerImpl(
                (_, __) => { },
                (_, __, ___) => { },
                (_, __, ___) => { },
                (_, __, ___, ____) => { },
                (_, __, ___) => { },
                (_) => { return(false); });

            _requestListener = new RequestListenerImpl(
                producerListener,
                (imageRequest, callerContext, requestId, isPrefetch) =>
            {
                _onRequestStartInvocation = true;
                _internalImageRequest     = imageRequest;
                _internalCallerContext    = callerContext;
                _internalRequestId        = requestId;
                _internalIsPrefetch       = isPrefetch;
            },
                (imageRequest, requestId, isPrefetch) =>
            {
                _onRequestSuccessInvocation = true;
                _internalImageRequest       = imageRequest;
                _internalRequestId          = requestId;
                _internalIsPrefetch         = isPrefetch;
            },
                (imageRequest, requestId, exception, isPrefetch) =>
            {
                _onRequestFailureInvocation = true;
                _internalImageRequest       = imageRequest;
                _internalRequestId          = requestId;
                _internalException          = exception;
                _internalIsPrefetch         = isPrefetch;
            },
                (requestId) =>
            {
                _onRequestCancellationInvocation = true;
                _internalRequestId = requestId;
            });
            _result1 = new object();
            _result2 = new object();
            _result3 = new object();

            _dataSubscriber1 = new MockDataSubscriber <object>();
            _dataSubscriber2 = new MockDataSubscriber <object>();

            _internalIsPrefetch      = true;
            _settableProducerContext = new SettableProducerContext(
                IMAGE_REQUEST,
                REQUEST_ID,
                producerListener,
                CALLER_CONTEXT,
                RequestLevel.FULL_FETCH,
                IS_PREFETCH,
                true,
                Priority.HIGH);
            _producer = new ProducerImpl <object>(
                (consumer, _) =>
            {
                _internalConsumer = consumer;
            });
            _dataSource = ProducerToDataSourceAdapter <object> .Create(
                _producer,
                _settableProducerContext,
                _requestListener);

            Assert.IsTrue(_onRequestStartInvocation);
            Assert.AreSame(_internalImageRequest, IMAGE_REQUEST);
            Assert.AreSame(_internalCallerContext, CALLER_CONTEXT);
            Assert.AreSame(_internalRequestId, REQUEST_ID);
            Assert.IsFalse(_internalIsPrefetch);
            Assert.IsNotNull(_internalConsumer);
            _onRequestStartInvocation = false;

            _dataSource.Subscribe(_dataSubscriber1, CallerThreadExecutor.Instance);
        }