public static async Task Visit(InboundMessageRouter router, MessageDto message, PeerContext peer) { var e = eventPool.TakeObject(); e.Message = message; e.Sender = peer; if (!await router.TryRouteAsync(e).ConfigureAwait(false)) { logger.Trace($"Failed to route inbound message of body type {e.Body?.GetType().Name ?? "[null]"}"); } e.Message = null; eventPool.ReturnObject(e); }
public InboundMessageDispatcher(Identity identity, PeerTable peerTable, InboundMessageRouter inboundMessageRouter) { this.identity = identity; this.peerTable = peerTable; this.inboundMessageRouter = inboundMessageRouter; }
public static Task Visit(InboundMessageRouter router, MessageDto message, PeerContext peer) { return(visitorFactory.Get(message.Body.GetType())(router, message, peer)); }
public async Task <IRyuContainer> CreateAsync(IReadOnlySet <ITransportFactory> transportFactories, Guid?forceId = null) { var container = root.CreateChildContainer(); var proxyGenerator = container.GetOrDefault <ProxyGenerator>() ?? new ProxyGenerator(); var shutdownCancellationTokenSource = new CancellationTokenSource(); // Auditing Subsystem var auditService = new AuditService(shutdownCancellationTokenSource.Token); auditService.Initialize(); // management tier containers var mobContextContainer = new MobContextContainer(); var mobContextFactory = new MobContextFactory(auditService); var mobOperations = new MobOperations(mobContextFactory, mobContextContainer); // Other Courier Stuff var identity = Identity.Create(forceId); var routingTable = new RoutingTable(); var peerDiscoveryEventBus = new AsyncBus <PeerDiscoveryEvent>(); var peerTable = new PeerTable(container, (table, peerId) => new PeerContext(table, peerId, peerDiscoveryEventBus)); var inboundMessageRouter = new InboundMessageRouter(); var inboundMessageDispatcher = new InboundMessageDispatcher(identity, peerTable, inboundMessageRouter); var transports = new ConcurrentSet <ITransport>(); foreach (var transportFactory in transportFactories) { var transport = await transportFactory.CreateAsync(mobOperations, identity, routingTable, peerTable, inboundMessageDispatcher, auditService).ConfigureAwait(false); transports.TryAdd(transport); } var messenger = new Messenger(identity, transports, routingTable); container.Set(identity); container.Set(routingTable); container.Set(peerTable); container.Set(inboundMessageRouter); container.Set(messenger); //---------------------------------------------------------------------------------------- // Service Tier - Service Discovery, Remote Method Invocation //---------------------------------------------------------------------------------------- var localServiceRegistry = new LocalServiceRegistry(identity, messenger); var remoteServiceInvoker = new RemoteServiceInvoker(identity, messenger); var remoteServiceProxyContainer = new RemoteServiceProxyContainer(proxyGenerator, remoteServiceInvoker); inboundMessageRouter.RegisterHandler <RmiRequestDto>(localServiceRegistry.HandleInvocationRequestAsync); inboundMessageRouter.RegisterHandler <RmiResponseDto>(remoteServiceInvoker.HandleInvocationResponse); container.Set(localServiceRegistry); container.Set(remoteServiceProxyContainer); //---------------------------------------------------------------------------------------- // Management Tier - DMI - Services //---------------------------------------------------------------------------------------- var managementObjectService = new ManagementObjectService(mobContextContainer, mobOperations); localServiceRegistry.RegisterService <IManagementObjectService>(managementObjectService); container.Set(mobOperations); container.Set(managementObjectService); var facade = new CourierFacade(transports, container); container.Set(facade); return(container); }