public PulsarSender(DotPulsarEndpoint endpoint, CancellationToken cancellationToken) { _endpoint = endpoint; _cancellationToken = cancellationToken; _publisher = endpoint.PulsarClient.CreateProducer(endpoint.ProducerOptions); _protocol = new DotPulsarTransportProtocol(); }
private TransportProtocol() { this.container = new Dictionary <string, TransportProtocolContainer>(); Assembly assembly = Assembly.GetExecutingAssembly(); IEnumerable <Type> types = assembly.GetTypes().Where(c => c.GetInterface(typeof(ITransportProtocol).Name) != null && c.GetCustomAttributes(typeof(ATransportProtocol), false).Length == 1); foreach (Type type in types) { ATransportProtocol attribute = (ATransportProtocol)(type.GetCustomAttributes(typeof(ATransportProtocol), false)[0]); FieldInfo instanceField = type.GetField("instance", BindingFlags.NonPublic | BindingFlags.Static); if (instanceField != null) { TransportProtocolContainer protocolContainer = null; if (!this.container.ContainsKey(attribute.Name)) { protocolContainer = new TransportProtocolContainer(); this.container.Add(attribute.Name, protocolContainer); } else { protocolContainer = this.container[attribute.Name]; } ITransportProtocol protocol = (ITransportProtocol)instanceField.GetValue(null); foreach (byte version in attribute.Versions) { //Log.Add("ver: " + version); protocolContainer.Add(version, protocol); } } } }
public ConfluentKafkaListener(KafkaEndpoint endpoint, ITransportLogger logger, CancellationToken cancellation) { _endpoint = endpoint; _logger = logger; _cancellation = cancellation; _protocol = new KafkaTransportProtocol(); _consumer = new ConsumerBuilder <byte[], byte[]>(endpoint.ConsumerConfig).Build(); }
public DotPulsarListener(DotPulsarEndpoint endpoint, ITransportLogger logger, CancellationToken cancellation) { _endpoint = endpoint; _logger = logger; _cancellation = cancellation; _protocol = new DotPulsarTransportProtocol(); _consumer = endpoint.PulsarClient.CreateConsumer(endpoint.ConsumerOptions); }
/// <summary> /// Constructor of the class that effectively valorize its attributes. /// </summary> /// <param name="peerAddress">URI address of the peer</param> /// <param name="peerScore">Score of the peer (the less it is the better is the peer</param> /// <param name="peerQueueNotEmpty"> /// AutoResetEvent used to communicate to the Peer Queue that the queue is not empty. /// </param> public PeerQueueElement(string peerAddress, float peerScore, ref AutoResetEvent peerQueueNotEmpty) { this.PeerAddress = peerAddress; this.PeerScore = peerScore; this.State = PeerState.FREE; this.peerQueueNotEmpty = peerQueueNotEmpty; this.channel = ChannelFactory <ITransportProtocol> .CreateChannel( new NetUdpBinding(), new EndpointAddress(peerAddress) ); }
public AzureServiceBusListener(AzureServiceBusEndpoint endpoint, AzureServiceBusTransport transport, ITransportLogger logger, CancellationToken cancellation) { _endpoint = endpoint; _transport = transport; _logger = logger; _cancellation = cancellation; _protocol = endpoint.Protocol; Address = endpoint.Uri; }
public ConfluentKafkaSender(KafkaEndpoint endpoint) { if (endpoint?.ProducerConfig == null) { throw new ArgumentNullException(nameof(KafkaEndpoint.ProducerConfig)); } _endpoint = endpoint; _publisher = new ProducerBuilder <byte[], byte[]>(endpoint.ProducerConfig) .SetErrorHandler((producer, error) => { if (error.IsFatal) { throw new KafkaSenderException(error); } }) .Build(); _protocol = new KafkaTransportProtocol(); }
public Client( IServiceProvider serviceProvider, MessageCenter messageCenter, ITransportProtocol transportProtocol, TransportManager transportManager, ClientOptions clientOptions, IEnumerable <IMiddleware> middleware, ILogger logger) { ServiceProvider = serviceProvider; _messageCenter = messageCenter; _messageCenter.OnMessage += OnMessage; _transportProtocol = transportProtocol; _transportProtocol.OnConnected += OnConnect; _transportProtocol.OnDisconnected += OnDisconnect; _transportManager = transportManager; RemoteEndPoint = clientOptions.RemoteEndPoint; _middleware = middleware; _logger = logger.ForContext <Client>(); }
/// <summary> /// Listener thread /// </summary> public SyslogListenerThread(EndpointConfiguration config) { this.m_configuration = config; if (this.m_configuration == null) { throw new InvalidOperationException("Missing endpoint configuration"); } this.m_protocol = TransportUtil.Current.CreateTransport(config.Address.Scheme); this.m_protocol.MessageReceived += new EventHandler <SyslogMessageReceivedEventArgs>(m_protocol_MessageReceived); this.m_protocol.InvalidMessageReceived += new EventHandler <SyslogMessageReceivedEventArgs>(m_protocol_InvalidMessageReceived); foreach (var act in this.m_configuration.Action) { var handler = Activator.CreateInstance(act) as ISyslogAction; if (this.m_action == null) { throw new InvalidOperationException("Action does not implement ISyslogAction interface"); } this.m_action.Add(handler); } }
/// <summary> /// Method used to request the download of a chunk from the network. When it is invoked from /// a remote peer it gets the chunk from the file and calls back the ReturnChunk method /// of the requestor. /// </summary> /// <param name="chkrq">Message used to pass information about the Chunk requested</param> public void GetChunk(ChunkRequest chkrq) { log.Info("Received request to send chunk!"); servingBuffer++; TrackModel track = new TrackModel(); RepositoryResponse resp = trackRepository.GetByKey <TrackModel.Track>(chkrq.RID, track); log.Debug("Searching track " + track + " in repository"); if (resp >= 0) { log.Debug("Track found! Extracting chunk."); byte[] data; using (FileStream fs = new FileStream(track.Filepath, FileMode.Open, FileAccess.Read, FileShare.Read)) { int limit = (System.Convert.ToInt32(fs.Length) > (chunkLength * 1024 * (chkrq.CID + 1))) ? chunkLength * 1024 * (chkrq.CID + 1) : (System.Convert.ToInt32(fs.Length)); int begin = chkrq.CID * chunkLength * 1024; data = new byte[limit - begin]; Console.WriteLine("Reading chunk " + chkrq.CID + " (" + (chkrq.CID * chunkLength * 1024) + " => " + limit + ")"); fs.Seek(begin, SeekOrigin.Begin); fs.Read(data, 0, (limit - begin)); fs.Close(); } ChunkResponse chkrs = new ChunkResponse(servingBuffer, chkrq.RID, chkrq.CID, data, myAddress); if (chkrq.SenderAddress != myAddress) { ITransportProtocol svc = ChannelFactory <ITransportProtocol> .CreateChannel( new NetUdpBinding(), new EndpointAddress(chkrq.SenderAddress) ); svc.ReturnChunk(chkrs); } else { this.ReturnChunk(chkrs); } log.Debug("Chunk sent to " + chkrq.SenderAddress); } servingBuffer--; }
public TorrentClient( ILogger <TorrentClient> logger, PeerId localPeerId, IMainLoop mainLoop, ITransportProtocol transport, ITrackerClientFactory trackerClientFactory, IApplicationProtocolPeerInitiator peerInitiator, IServiceProvider services) { _logger = logger; _downloads = new Dictionary <Sha1Hash, TorrentDownload>(); _mainLoop = mainLoop; _mainLoop.Start(); _trackerClientFactory = trackerClientFactory; _services = services; _updateStatisticsTimer = new Timer(UpdateStatistics, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); _peerInitiator = peerInitiator; LocalPeerId = localPeerId; Transport = transport; transport.AcceptConnectionHandler += _peerInitiator.AcceptIncomingConnection; Transport.Start(); }
/// <summary> /// Static ctor, construct protocol types /// </summary> static TransportUtil() { // Get all assemblies which have a transport protocol var asm = typeof(TransportUtil).Assembly; try { foreach (var typ in Array.FindAll(asm.GetTypes(), t => t.GetInterface(typeof(ITransportProtocol).FullName) != null)) { ConstructorInfo ci = typ.GetConstructor(Type.EmptyTypes); if (ci == null) { throw new InvalidOperationException(String.Format("Cannot find parameterless constructor for type '{0}'", typ.AssemblyQualifiedName)); } ITransportProtocol tp = ci.Invoke(null) as ITransportProtocol; s_prots.Add(tp.ProtocolName, typ); } } catch (Exception e) { new Tracer(Hl7Constants.TraceSourceName).TraceEvent(EventLevel.Error, e.ToString()); } }
public AzureServiceBusSender(AzureServiceBusEndpoint endpoint, AzureServiceBusTransport transport) { _protocol = endpoint.Protocol; _endpoint = endpoint; _transport = transport; // The variance here should be in constructing the sending & buffer blocks if (_endpoint.TopicName.IsEmpty()) { _sender = _transport.TokenProvider != null ? new MessageSender(_transport.ConnectionString, _endpoint.QueueName, _transport.TokenProvider, _transport.TransportType, _transport.RetryPolicy) : new MessageSender(_transport.ConnectionString, _endpoint.QueueName, _transport.RetryPolicy); } else { _sender = _transport.TokenProvider != null ? new TopicClient(_transport.ConnectionString, _endpoint.TopicName, _transport.TokenProvider, _transport.TransportType, _transport.RetryPolicy) : new TopicClient(_transport.ConnectionString, _endpoint.TopicName, _transport.RetryPolicy); } }
/// <summary> /// Override the header protocol for outgoing messages at this location. This is mostly /// useful for integrating Jasper with non-Jasper applications /// </summary> /// <param name="protocol"></param> /// <returns></returns> public AzureServiceBusListenerConfiguration Protocol(ITransportProtocol <Message> protocol) { endpoint.Protocol = protocol; return(this); }
public void Add(byte version, ITransportProtocol protocol) { this.container.Add(version, protocol); }
/// <summary> /// Constructs the new service handler /// </summary> public ServiceHandler(Hl7ServiceDefinition serviceDefinition) { this.m_serviceDefinition = serviceDefinition; this.m_transport = TransportUtil.CreateTransport(this.m_serviceDefinition.Address.Scheme); this.m_transport.MessageReceived += new EventHandler <Hl7MessageReceivedEventArgs>(m_transport_MessageReceived); }
/// <summary> /// Constructor of the class that effectively valorize its attributes. /// </summary> /// <param name="peerAddress">URI address of the peer</param> /// <param name="peerScore">Score of the peer (the less it is the better is the peer</param> /// <param name="peerQueueNotEmpty"> /// AutoResetEvent used to communicate to the Peer Queue that the queue is not empty. /// </param> public PeerQueueElement(string peerAddress, float peerScore, ref AutoResetEvent peerQueueNotEmpty) { this.PeerAddress = peerAddress; this.PeerScore = peerScore; this.State = PeerState.FREE; this.peerQueueNotEmpty = peerQueueNotEmpty; this.channel = ChannelFactory<ITransportProtocol>.CreateChannel( new NetUdpBinding(), new EndpointAddress(peerAddress) ); }