public ServerNode(INetProvider externalNetProvider, INetProvider internalNetProvider, INodeCoordinator coordinator, IMessageFactory factory, IOperationDispatcher protocol, IActorRepository repository, Func <S2CPeer> clientPeerFactory) { _coordinator = coordinator; Repository = repository; Dispatcher = protocol; DefaultActorCoordinator = typeof(IsisActorCoordinator); ExternalNet = new NetNode <S2CPeer>(externalNetProvider, factory, protocol, peerFactory: () => { S2CPeer peer = clientPeerFactory(); peer.Node = this; return(peer); }); InternalNet = new NetNode <S2SPeer>(internalNetProvider, factory, protocol, peerFactory: () => new S2SPeer { Node = this }); foreach (ActorDescription actorDesc in repository.ActorDescriptions) { Type coordinatorType = actorDesc.Attribute.Coordinator ?? DefaultActorCoordinator; var actorCoord = (IActorCoordinator)Activator.CreateInstance(coordinatorType); actorCoord.Init(this, actorDesc.PrimaryContract.TypeId); _actorCoordinatorsByPrimaryContractId.Add(actorDesc.PrimaryContract.TypeId, actorCoord); } Fiber = new ServerFiber(); }
public AppendToStreamAsyncHandler(IEventSerializer eventSerializer, ICosmosDBClient cosmosClient, ICosmosDBConfigurations cosmosDBConfigurations, IOperationDispatcher operationDispatcher) { _eventSerializer = eventSerializer ?? throw new ArgumentNullException(nameof(eventSerializer)); _cosmosClient = cosmosClient ?? throw new ArgumentNullException(nameof(cosmosClient)); _cosmosDBConfigurations = cosmosDBConfigurations ?? throw new ArgumentNullException(nameof(cosmosDBConfigurations)); _operationDispatcher = operationDispatcher ?? throw new ArgumentNullException(nameof(operationDispatcher)); }
/// <summary> /// Creates instance of remote connection with given channel. /// </summary> /// <param name="channel">Communication channel used by connection.</param> /// <param name="dispatcher">Operation dispatcher used to handle incoming operation requests from remote end.</param> /// <param name="config">Connection configuration.</param> public RemoteConnection(IDuplexChannel channel, IOperationDispatcher dispatcher, IConnectionConfig config) { OperationDispatcher = dispatcher; Channel = channel; _scheduler = config.TaskScheduler; RemoteExecutor = config.RemoteExecutorFactory.CreateRemoteExecutor(channel, dispatcher.MessageDispatcher); Channel.Received += OnMessageReceived; Channel.Closed += OnChannelClose; }
public CosmosDBConnection(IEventSerializer eventSerializer, ICosmosDBClient cosmosClient, ICosmosDBConfigurations cosmosDBConfigurations, IOperationDispatcher operationDispatcher) { _eventSerializer = eventSerializer ?? throw new ArgumentNullException(nameof(eventSerializer)); _cosmosClient = cosmosClient ?? throw new ArgumentNullException(nameof(cosmosClient)); _cosmosDBConfigurations = cosmosDBConfigurations ?? throw new ArgumentNullException(nameof(cosmosDBConfigurations)); _operationDispatcher = operationDispatcher ?? throw new ArgumentNullException(nameof(operationDispatcher)); RegisterHandlers(); }
public void SetUp() { Configurator.Configure(); _connectionListener = new LidgrenServerConnectionListener(_applicationId, _listenAddress, _port, new BinaryMessageSerializer(), new UnencryptedCryptoProviderResolver()); _dispatcher = new OperationDispatcher(); _dispatcher.RegisterHandler <ICalculator>(new Calculator()); _dispatcher.RegisterHandler <IGreeter>(new Greeter()); _server = new GenericServerEndpoint(_connectionListener, new ServerConfig(), () => _dispatcher); _server.Start(); }
public ClientNode(INetProvider net, IMessageFactory msgFactory, IOperationDispatcher protocol, bool manualUpdate = false) : base(net, msgFactory, protocol, manualUpdate) { if (SynchronizationContext.Current != null) { Fiber = new ClientFiber(TaskScheduler.FromCurrentSynchronizationContext(), manualUpdate); } else { Fiber = new ClientFiber(manualUpdate); } }
public void BaseSetUp() { MessageDispatcher = MockRepository.GenerateMock <IMessageDispatcher>(); OperationDispatcher = MockRepository.GenerateMock <IOperationDispatcher>(); RemoteExecutorFactory = MockRepository.GenerateMock <IRemoteExecutorFactory>(); Channel = MockRepository.GenerateMock <TChannel>(); RemoteExecutor = MockRepository.GenerateMock <IRemoteExecutor>(); Scheduler = MockRepository.GenerateMock <ITaskScheduler>(); Scheduler.Stub(s => s.Execute(Arg <Action> .Is.Anything)).WhenCalled(a => ((Action)a.Arguments[0]).Invoke()); OperationDispatcher.Stub(d => d.MessageDispatcher).Return(MessageDispatcher); RemoteExecutorFactory.Stub(f => f.CreateRemoteExecutor(Arg <IDuplexChannel> .Is.Anything, Arg <IMessageDispatcher> .Is.Anything)).Return(RemoteExecutor); Subject = CreateSubject(); }
public NetContractHandler(IOperationDispatcher dispatcher, uint contractId, object implementer) { Implementer = implementer; ServiceTypeId = contractId; Type implementerType = implementer.GetType(); NetContractDescription desc = dispatcher.GetContract(contractId); InterfaceMapping mapping = implementerType.GetInterfaceMap(desc.ContractType); foreach (NetOperationDescription operation in desc.Operations) { var handlerAttr = mapping.TargetMethods.First(m => m.Name == operation.Name).GetAttribute <NetOperationHandlerAttribute>(); _handlerAttributes.Add(operation.RequestMessageId, handlerAttr ?? new NetOperationHandlerAttribute()); } }
public NetNode(INetProvider net, IMessageFactory msgFactory, IOperationDispatcher protocol, Func <TNetPeer> peerFactory = null) { Net = net; MsgFactory = msgFactory; Dispatcher = protocol; if (peerFactory != null) { PeerFactory = peerFactory; } else { PeerFactory = () => (TNetPeer)Activator.CreateInstance(typeof(TNetPeer)); } }
public void SetUp() { _connectionListener = MockRepository.GenerateMock <IServerConnectionListener>(); _remoteExecutorFactory = MockRepository.GenerateMock <IRemoteExecutorFactory>(); _taskScheduler = MockRepository.GenerateMock <ITaskScheduler>(); _config = MockRepository.GenerateMock <IServerConfig>(); _config.Stub(c => c.MaxConnections).Return(10); _config.Stub(c => c.RemoteExecutorFactory).Return(_remoteExecutorFactory); _config.Stub(c => c.TaskScheduler).Return(_taskScheduler); _operationDispatcher = MockRepository.GenerateMock <IOperationDispatcher>(); _operationDispatcher.Stub(d => d.MessageDispatcher).Return(MockRepository.GenerateMock <IMessageDispatcher>()); _broadcastChannel = MockRepository.GenerateMock <IBroadcastChannel>(); _connectionListener.Stub(l => l.BroadcastChannel).Return(_broadcastChannel); _broadcastExecutor = MockRepository.GenerateMock <IBroadcastRemoteExecutor>(); _remoteExecutorFactory.Stub(f => f.CreateBroadcastRemoteExecutor(_broadcastChannel)).Return(_broadcastExecutor); _subject = new GenericServerEndpoint(_connectionListener, _config, () => _operationDispatcher); }
private IServerEndpoint CreateServer(ILidgrenCryptoProviderResolver providerResolver) { DefaultConfig.MessageSerializer = new BinaryMessageSerializer(); DefaultConfig.MessageFactory = new DefaultMessageFactory(); DefaultConfig.RemoteExecutorFactory = new RemoteExecutorFactory(); DefaultConfig.TaskScheduler = new AsyncTaskScheduler(); TransportLayerResolver.Register(new LidgrenProvider(providerResolver)); _connectionListener = new LidgrenServerConnectionListener(_applicationId, _listenAddress, _port, new BinaryMessageSerializer(), providerResolver); _dispatcher = new OperationDispatcher(); _dispatcher.RegisterHandler <ICalculator>(new Calculator()); _dispatcher.RegisterHandler <IGreeter>(new Greeter()); IServerEndpoint server = new GenericServerEndpoint(_connectionListener, new ServerConfig(), () => _dispatcher); server.Start(); return(server); }
public ActorRepository(IOperationDispatcher dispatcher, IEnumerable<Actor> actorPrototypes) { Dispatcher = dispatcher; foreach (var entity in actorPrototypes) { Type type = entity.GetType(); var attr = type.GetAttribute<ActorAttribute>(); var contracts = new List<NetContractDescription>(); foreach (Type netContractType in entity.GetType().GetInterfaces()) { uint typeId; if(dispatcher.TryGetContractId(netContractType, out typeId)) contracts.Add(Dispatcher.GetContract(typeId)); } var actorDescription = new ActorDescription(type, contracts, attr); _descriptionsByTypeId.Add(actorDescription.PrimaryContract.TypeId, actorDescription); Log.Info("Registered {0}", type, actorDescription); } }
public void ValidateIpEndPointProvision() { connectionListener = new LidgrenServerConnectionListener(applicationId, ListenAddress, Port, new BinaryMessageSerializer(), new UnencryptedCryptoProviderResolver()); dispatcher = new OperationDispatcher(); IPEndPoint senderEndPoint = null; IPEndPoint clientEndPoint = null; dispatcher.RegisterHandler <IEndPointProvisioner>(new EndPointProvisioner { OnStuff = e => senderEndPoint = e }); server = new GenericServerEndpoint(connectionListener, new ServerConfig(), () => dispatcher); server.Start(); using (ClientConnection client = CreateClientConnection()) { client.Open(); clientEndPoint = client.GetClientEndpoint(); client.RemoteExecutor.Create <IEndPointProvisioner>().DoStuff(null); } server.Dispose(); Assert.AreEqual(clientEndPoint, senderEndPoint); }
public ActorRepository(IOperationDispatcher dispatcher, IEnumerable <Actor> actorPrototypes) { Dispatcher = dispatcher; foreach (var entity in actorPrototypes) { Type type = entity.GetType(); var attr = type.GetAttribute <ActorAttribute>(); var contracts = new List <NetContractDescription>(); foreach (Type netContractType in entity.GetType().GetInterfaces()) { uint typeId; if (dispatcher.TryGetContractId(netContractType, out typeId)) { contracts.Add(Dispatcher.GetContract(typeId)); } } var actorDescription = new ActorDescription(type, contracts, attr); _descriptionsByTypeId.Add(actorDescription.PrimaryContract.TypeId, actorDescription); Log.Info("Registered {0}", type, actorDescription); } }
/// <summary> /// Creates stateless server endpoint. /// </summary> /// <param name="uri">Listener uri used to create server connection listener.</param> /// <param name="dispatcher">Operation dispatcher that would be used for all connections.</param> /// <param name="config">Server configuration.</param> public StatelessServerEndpoint(string uri, IOperationDispatcher dispatcher, IServerConfig config) : base(uri, config) { _dispatcher = dispatcher; }
/// <summary> /// Creates client connection instance with channel constructed from connectionUri, given connection configuration and operation dispatcher. /// </summary> /// <param name="connectionUri">Connection uri used to create channel.</param> /// <param name="dispatcher">Operation dispatcher used to handle incoming operation requests from remote end.</param> /// <param name="config">Connection configuration.</param> public DurableClientConnection(string connectionUri, IOperationDispatcher dispatcher, IConnectionConfig config) : base(connectionUri, dispatcher, config) { }
/// <summary> /// Executes <paramref name="request"/> and returns its response. /// </summary> /// <typeparam name="TInput">Type of request.</typeparam> /// <typeparam name="TOutput">Type of response.</typeparam> /// <param name="request">Request data.</param> /// <returns>Response to <paramref name="request"/>.</returns> public static Task <TOutput> Execute <TInput, TOutput>(this IOperationDispatcher mediator, TInput request) where TInput : IOperation <TOutput> { Ensure.NotNull(mediator, "mediator"); return(mediator.ExecuteAsync <TInput, TOutput>(request)); }
/// <summary> /// Creates client connection instance with given channel, connection configuration and operation dispatcher. /// </summary> /// <param name="channel">Communication channel used by connection.</param> /// <param name="dispatcher">Operation dispatcher used to handle incoming operation requests from remote end.</param> /// <param name="config">Connection configuration.</param> public DurableClientConnection(IClientChannel channel, IOperationDispatcher dispatcher, IConnectionConfig config) : base(channel, dispatcher, config) { }
/// <summary> /// Creates client connection instance with channel constructed from connectionUri, given operation dispatcher and default connection configuration (<see cref="DefaultConfig"/>). /// </summary> /// <param name="connectionUri">Connection uri used to create channel.</param> /// <param name="dispatcher">Operation dispatcher used to handle incoming operation requests from remote end.</param> public DurableClientConnection(string connectionUri, IOperationDispatcher dispatcher) : base(connectionUri, dispatcher, new ConnectionConfig()) { }
public void SetUp() { _messageDispatcher = MockRepository.GenerateMock <IMessageDispatcher>(); _subject = new TestableOperationDispatcher(_messageDispatcher); }
/// <summary> /// Creates client connection instance with channel constructed from connectionUri, given connection configuration and operation dispatcher. /// </summary> /// <param name="clientId">Identifier used to share client channels.</param> /// <param name="connectionUri">Connection uri used to create channel.</param> /// <param name="dispatcher">Operation dispatcher used to handle incoming operation requests from remote end.</param> /// <param name="config">Connection configuration.</param> public ClientConnection(string connectionUri, string clientId, IOperationDispatcher dispatcher, IConnectionConfig config) : base(clientId, connectionUri, dispatcher, config) { }
/// <summary> /// Creates instance of remote connection with channel constructed from connectionUri. /// </summary> /// <param name="clientId">Identifier used to share client channels.</param> /// <param name="connectionUri">Connection uri used to create channel.</param> /// <param name="dispatcher">Operation dispatcher used to handle incoming operation requests from remote end.</param> /// <param name="config">Connection configuration.</param> public RemoteConnection(string clientId, string connectionUri, IOperationDispatcher dispatcher, IConnectionConfig config) : this(TransportLayerResolver.CreateClientChannelFor(clientId, new Uri(connectionUri)), dispatcher, config) { }
/// <summary> /// Creates stateless server endpoint with default server configuration (<see cref="DefaultConfig"/>). /// </summary> /// <param name="listener">Server connection listener used to listen for incoming connections.</param> /// <param name="dispatcher">Operation dispatcher that would be used for all connections.</param> public StatelessServerEndpoint(IServerConnectionListener listener, IOperationDispatcher dispatcher) : this(listener, dispatcher, new ServerConfig()) { }
/// <summary> /// Creates stateless server endpoint with default server configuration (<see cref="DefaultConfig"/>). /// </summary> /// <param name="uri">Listener uri used to create server connection listener.</param> /// <param name="dispatcher">Operation dispatcher that would be used for all connections.</param> public StatelessServerEndpoint(string uri, IOperationDispatcher dispatcher) : this(uri, dispatcher, new ServerConfig()) { }
/// <summary> /// Builds the stateless communication listener from the service manifest's endpoint. /// </summary> /// <param name="context">ServiceFabric's context</param> /// <param name="endPointListenerName">Name of endpoint in service manifest</param> /// <param name="dispatcher">Operation dispatcher that would be used for all connections.</param> public StatelessCommunicationListener(ServiceContext context, string endPointListenerName, IOperationDispatcher dispatcher) : this(context.GetEndpoint(endPointListenerName), dispatcher) { }
/// <summary> /// Creates stateless server endpoint. /// </summary> /// <param name="listener">Server connection listener used to listen for incoming connections.</param> /// <param name="dispatcher">Operation dispatcher that would be used for all connections.</param> /// <param name="config">Server configuration.</param> public StatelessServerEndpoint(IServerConnectionListener listener, IOperationDispatcher dispatcher, IServerConfig config) : base(listener, config) { _dispatcher = dispatcher; }
private static ClientConnection CreateClientConnection(string clientId, ushort port, IOperationDispatcher dispatcher) { return(new ClientConnection($"net://{Host}:{port}/{AppId}", clientId, dispatcher)); }
/// <summary> /// Hosts on the given uri. /// </summary> /// <param name="uri"></param> /// <param name="dispatcher">Operation dispatcher that would be used for all connections.</param> public StatelessCommunicationListener(string uri, IOperationDispatcher dispatcher) : base(uri, dispatcher) { Uri = uri; }