Пример #1
0
        public override Host Build()
        {
            if (ServiceBuilders.Count > 1)
                throw new HostConfigurationException("A shelf can only have one service configured");

            ServiceBuilder builder = ServiceBuilders.Single();

            _log.DebugFormat("[Shelf:{0}] Building Service: {1}", Description.Name, builder.Name);

            var controllerFactory = new ServiceControllerFactory();
            ActorFactory<IServiceController> factory = controllerFactory.CreateFactory(inbox =>
                {
                    var publish = new PublishChannel(_channel, inbox);

                    IServiceController service = builder.Build(inbox, publish);

                    return service;
                });

            ActorRef instance = factory.GetActor();

            _channel.Connect(x => x.AddChannel(instance));

            // this creates the state machine instance in the shelf and tells the servicecontroller
            // to create the service
            instance.Send(new CreateService(Description.Name));

            return new ShelfHost(instance);
        }
Пример #2
0
        public override Host Build()
        {
            if (ServiceBuilders.Count > 1)
            {
                throw new HostConfigurationException("A shelf can only have one service configured");
            }

            ServiceBuilder builder = ServiceBuilders.Single();

            _log.DebugFormat("[Shelf:{0}] Building Service: {1}", Description.Name, builder.Name);

            var controllerFactory = new ServiceControllerFactory();
            ActorFactory <IServiceController> factory = controllerFactory.CreateFactory(inbox =>
            {
                var publish = new PublishChannel(_channel, inbox);

                IServiceController service = builder.Build(inbox, publish);

                return(service);
            });

            ActorRef instance = factory.GetActor();

            _channel.Connect(x => x.AddChannel(instance));

            // this creates the state machine instance in the shelf and tells the servicecontroller
            // to create the service
            instance.Send(new CreateService(Description.Name));

            return(new ShelfHost(instance));
        }
Пример #3
0
        public void EstablishContext()
        {
            _serviceStarted = new FutureChannel <ServiceRunning>();
            _service        = new TestService();
            _hostChannel    = new TestChannel();

            _coordinator = new Model.ServiceCoordinator();

            var b = new LocalServiceBuilder <TestService>(null, _serviceName, (d, name, coordinator) => _service,
                                                          x => x.Start(), x => x.Stop(), x => { }, x => { });


            _controllerFactory = new ServiceControllerFactory();
            _factory           = _controllerFactory.CreateFactory(inbox => b.Build(inbox, _coordinator));
            _instance          = _factory.GetActor();

            _hostChannel.Connect(x =>
            {
                x.AddChannel(_instance);

                x.AddChannel(_serviceStarted);
            });

            _coordinator.Send(new CreateService(_serviceName));
            _coordinator.Send(new StartService(_serviceName));

            _serviceStarted.WaitUntilCompleted(5.Seconds());
        }