public void Update() { for (int i = 0; i < behaviours.Count; i++) { Behaviour b = behaviours[i]; if (!b.Enabled) { continue; } if (b is IStartable) { IStartable startable = b as IStartable; if (!startable.IsStarted) { startable.Start(); startable.IsStarted = true; } } if (b is IUpdatable) { IUpdatable updatable = b as IUpdatable; updatable.Update(); } } }
private void StartStopDisposeLifecycleComps(IStartable start, IStartable stop, IDisposable disp, One one) { start.Start(); // post instantiation startup Assert.AreEqual(4, one.getStarting().Count); Assert.AreEqual("One", one.getStarting()[0]); Assert.AreEqual("Two", one.getStarting()[1]); Assert.AreEqual("Three", one.getStarting()[2]); Assert.AreEqual("Four", one.getStarting()[3]); stop.Stop(); // post instantiation shutdown - REVERSE order. Assert.AreEqual(4, one.getStopping().Count); Assert.AreEqual("Four", one.getStopping()[0]); Assert.AreEqual("Three", one.getStopping()[1]); Assert.AreEqual("Two", one.getStopping()[2]); Assert.AreEqual("One", one.getStopping()[3]); disp.Dispose(); // post instantiation shutdown - REVERSE order. Assert.AreEqual(4, one.getDisposing().Count); Assert.AreEqual("Four", one.getDisposing()[0]); Assert.AreEqual("Three", one.getDisposing()[1]); Assert.AreEqual("Two", one.getDisposing()[2]); Assert.AreEqual("One", one.getDisposing()[3]); }
internal static void SafeStart(this IStartable startable, Tracer tracer) { Contract.Requires <ArgumentNullException>(tracer != null); if (startable == null) { return; } if (startable.IsStarted) { tracer.Info("{0} already started, not restarting it.", startable); return; } try { tracer.Verbose("Starting {0} ...", startable); startable.Start(); tracer.Info("Successfully started {0}.", startable); } catch (Exception excp) { tracer.Severe(excp, "Exception Start()ing {0}", startable); } }
private void StartService( IStartable service, string serviceName) { try { #region Logging _log.Info($"{serviceName} is starting."); #endregion service.Start(); #region Logging _log.Info($"{serviceName} has been started."); #endregion } catch (Exception e) { #region Logging _log.Critical(e, $"{serviceName} starting failed."); #endregion throw; } }
protected virtual void Initialize(StatefulService instance, IStartable starter) { var path = Utility.GetDefaultPath(instance); this.Path = Util.GetWcfUri(path); this.Stateful = instance; this.Starter = starter; }
private static void StartNewTask(int number, IStartable testClass) { Console.WriteLine($"Start Multithreading Task{number} \n"); testClass.Start(); Console.WriteLine("Press key to continue"); Console.ReadKey(); Console.WriteLine(); }
public ServiceContext(MainLoop _worker) { if (Environment.UserInteractive) { _runner = new ConsoleRunner(_worker); } else { _runner = new ServiceRunner(_worker); } }
/// <summary> /// Registers a startable to be intialized in priority order /// at a later stage. /// </summary> public void RegisterWithPriority(IStartable startable, int priority) { // Can't add duplicate priorities. if (startables.ContainsKey(priority)) { throw new ArgumentException($"Startable: {startable} cannot be registered because {startables[priority]} already exists at priority: {priority}"); } startables.Add(priority, startable); }
protected override void InternalStop() { base.InternalStop(); IStartable startableLogWriter = _innerLogWriter as IStartable; if (startableLogWriter != null) { QueueBackgroundAction(() => startableLogWriter.SafeStop(SetupTracerFactory)); } }
public StartupManager( IStartable blockchainIndexingManager, ILogFactory logFactory, IStartable transactionInputDecodingManager, IStartable transactionLogDecodingManager) { _blockchainIndexingManager = blockchainIndexingManager; _log = logFactory.CreateLog(this); _transactionInputDecodingManager = transactionInputDecodingManager; _transactionLogDecodingManager = transactionLogDecodingManager; }
internal static void SafeStop(this IStartable startable, ITracerFactory tracerFactory) { Contract.Requires <ArgumentNullException>(tracerFactory != null); if (startable == null) { return; } Tracer tracer = tracerFactory.TracerFor(startable); SafeStop(startable, tracer); }
private void InitailizeBus(string asmName) { assemblyName = asmName; CreateBootStrapper(); InitializeContainer(); bootStrapper.BeginStart(); logger.Debug("Starting bus"); startable = bootStrapper.GetInstance <IStartable>(); }
public static void Main() { var pubsub = new TopicBasedPubSub(); var alarmClock = new AlarmClock <RetryCooking>(pubsub); pubsub.SubscribeByMessage(alarmClock); var waiter = new Waiter(pubsub); var cook1 = QueuedHandler.Create(new Cook("Tom", pubsub, Random.Next(0, 1000)), "Cook #1"); var cook2 = QueuedHandler.Create(new Cook("Jones", pubsub, Random.Next(0, 1000)), "Cook #2"); var cook3 = QueuedHandler.Create(new Cook("Huck", pubsub, Random.Next(0, 1000)), "Cook #3"); var kitchen = QueuedHandler.Create(MoreFareDispatcher.Create(cook1, cook2, cook3).WrapWithDropper(), "Kitchen"); pubsub.SubscribeByMessage(kitchen); var manager = QueuedHandler.Create(new Manager(pubsub), "Manager #1"); pubsub.SubscribeByMessage(manager); var cashier = QueuedHandler.Create(new Cashier(pubsub), "Cashier #1"); pubsub.SubscribeByMessage(cashier); var midgetHouse = QueuedHandler.Create(new MidgetHouse(pubsub), "Midgets"); pubsub.SubscribeByMessage(midgetHouse); var printer = new PrintingOrderHandler(); //pubsub.SubscribeByMessage<OrderPaid>(printer); //pubsub.SubscribeByMessage<OrderCooked>(printer); //pubsub.SubscribeByMessage<OrderPlaced>(printer); //pubsub.SubscribeByMessage<OrderPriced>(printer); var startables = new IStartable[] { midgetHouse, kitchen, cook1, cook2, cook3, cashier, manager, alarmClock }; var queues = new IQueue[] { midgetHouse, kitchen, cook1, cook2, cook3, cashier, manager }; foreach (var startable in startables) { startable.Start(); } StartMonitoring(queues); TakeOrders(waiter); }
private void InitailizeBus(string asmName) { string logfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config"); XmlConfigurator.ConfigureAndWatch(new FileInfo(logfile)); assemblyName = asmName; CreateBootStrapper(); log4net.GlobalContext.Properties["BusName"] = bootStrapper.GetType().Namespace; InitializeContainer(); bootStrapper.BeginStart(); logger.Debug("Starting bus"); startable = bootStrapper.GetInstance <IStartable>(); }
/// <summary> /// stop the transport on the specifies port. /// </summary> /// <param name="transport"> /// an IStartable object that specifies the transport. /// </param> /// <param name="listenedLocalEndPoints"> /// an ICollection<IPEndPoint> that contains the listened local endpoint.<para/> /// if null, stop the EndPoint(specifiedAddress, portToStop), it's used by UdpClient. /// </param> /// <param name="specifiedAddress"> /// when listenedLocalEndPoints is null, using this address instead.<para/> /// if null, using IPAddress.Any. /// </param> /// <param name="localEndPoint"> /// an object that specifies the port to stop. /// </param> public static void StopTransportByPort(IStartable transport, ICollection <IPEndPoint> listenedLocalEndPoints, IPAddress specifiedAddress, object localEndPoint) { int port; try { port = Convert.ToInt32(localEndPoint, CultureInfo.InvariantCulture); } catch (Exception) { throw new ArgumentException("localEndPoint is not an IPEndPoint/port.", "localEndPoint"); } if (listenedLocalEndPoints == null) { if (specifiedAddress == null) { specifiedAddress = IPAddress.Any; } transport.Stop(new IPEndPoint(specifiedAddress, port)); return; } // get all endpoint to stop. IPEndPoint[] endpoints = new IPEndPoint[listenedLocalEndPoints.Count]; listenedLocalEndPoints.CopyTo(endpoints, 0); // stop the specified endpoint. foreach (IPEndPoint ep in endpoints) { if (ep.Port == port) { transport.Stop(ep); } } }
protected FlowStream(IStartable parent) { _parent = parent; }
/// <summary> /// Initializes a new instance of the <see cref="ServiceContainer" /> class. /// </summary> /// <param name="services">The services.</param> // ReSharper disable once ParameterTypeCanBeEnumerable.Local public ServiceContainer(IStartable[] services) { _services = services.ToList(); }
static void Start(IStartable machine) { machine.Start(); }
public SumDoubleStream(Func <TIn, double> fn, IStartable parent) : base((o, acc) => fn(o) + acc, 0d, parent) { }
// Tuple<TargetStream<T, T2>, Action<T>> public static (Stream <int, int> Stream, Action <TIn> Pusher) GetSumIntStream(Func <TIn, int> fn, IStartable parent) { var tstream = new SumIntStream <TIn>(fn, parent); return(tstream as Stream <int, int>, tstream.Flow); }
public ResultStream(IStartable parent) : base(parent) { }
private TargetStream(Func <TIn, TOut> fn, IStartable parent) : base(parent) => _fn = fn;
/// <summary> /// Marks a startable as having finished its initialization /// process. /// </summary> public void MarkInitializationComplete(IStartable startable) { initializedStartables.Add(startable); CheckForComplete(); }
public void RegisterWith(IStartable startable) { _Instance.Add(startable); }
public StartableDecorator(IStartable startable) { Decorated = startable; }
private ManyTargetStream(Func <TIn, Stream <TOut, TOut[]> > fn, IStartable parent) : base(parent) => _fn = fn;
static void Kaynnista(IStartable laite) { laite.Start(); }
GetIterEndOfStream(Action <TIn> fn, IStartable parent) { var tstream = new IterEndOfStream <TIn>(fn, parent); return(tstream, tstream.Flow); }
public electronics(IStartable startable) { _startable = startable; }
private IterEndOfStream(Action <TIn> fn, IStartable parent) { _fn = fn; _parent = parent; }
// Tuple<TargetStream<T, T2>, Action<T>> public static (Stream <double, double> Stream, Action <TIn> Pusher) GetSumDoubleStream(Func <TIn, double> fn, IStartable parent) { var tstream = new SumDoubleStream <TIn>(fn, parent); return(tstream as Stream <double, double>, tstream.Flow); }
public GameStarter(IStartable game) { _game = game; }
public SumIntStream(Func <TIn, int> fn, IStartable parent) : base((o, acc) => fn(o) + acc, 0, parent) { }