/// <summary> /// Constructs a DefaultRemoteManager listening on the specified address and /// a specific port. /// </summary> /// <param name="localAddress">The address to listen on</param> /// <param name="tcpPortProvider">Tcp port provider</param> /// <param name="streamingCodec">Streaming codec</param> /// <param name="tcpClientFactory">provides TcpClient for given endpoint</param> internal StreamingRemoteManager(IPAddress localAddress, ITcpPortProvider tcpPortProvider, IStreamingCodec <T> streamingCodec, ITcpClientConnectionFactory tcpClientFactory) { if (localAddress == null) { throw new ArgumentNullException("localAddress"); } _tcpClientFactory = tcpClientFactory; _observerContainer = new ObserverContainer <T>(); _cachedClients = new Dictionary <IPEndPoint, ProxyObserver>(); _remoteEventCodec = new RemoteEventStreamingCodec <T>(streamingCodec); // Begin to listen for incoming messages _server = new StreamingTransportServer <IRemoteEvent <T> >(localAddress, _observerContainer, tcpPortProvider, _remoteEventCodec); _server.Run(); LocalEndpoint = _server.LocalEndpoint; Identifier = new SocketRemoteIdentifier(LocalEndpoint); }
/// <summary> /// Constructs a DefaultRemoteManager listening on the specified address and any /// available port. /// </summary> /// <param name="localAddress">The address to listen on</param> /// <param name="port">The port to listen on</param> /// <param name="codec">The codec used for serializing messages</param> /// <param name="tcpPortProvider">provides port numbers to listen</param> internal DefaultRemoteManager(IPAddress localAddress, int port, ICodec <T> codec, ITcpPortProvider tcpPortProvider) { if (localAddress == null) { throw new ArgumentNullException("localAddress"); } if (port < 0) { throw new ArgumentException("Listening port must be greater than or equal to zero"); } if (codec == null) { throw new ArgumentNullException("codec"); } _observerContainer = new ObserverContainer <T>(); _codec = new RemoteEventCodec <T>(codec); _cachedClients = new Dictionary <IPEndPoint, ProxyObserver>(); IPEndPoint localEndpoint = new IPEndPoint(localAddress, port); // Begin to listen for incoming messages _server = new TransportServer <IRemoteEvent <T> >(localEndpoint, _observerContainer, _codec, tcpPortProvider); _server.Run(); LocalEndpoint = _server.LocalEndpoint; Identifier = new SocketRemoteIdentifier(LocalEndpoint); }
public WritableRemoteManager(IInjector injector) { using (LOGGER.LogFunction("WritableRemoteManager::WritableRemoteManager")) { _observerContainer = new WritableObserverContainer <T>(); _cachedClients = new Dictionary <IPEndPoint, ProxyObserver>(); _injector = injector; LocalEndpoint = new IPEndPoint(NetworkUtils.LocalIPAddress, 0); Identifier = new SocketRemoteIdentifier(LocalEndpoint); } }
/// <summary> /// Returns an IObserver used to send messages to the remote host at /// the specified IPEndpoint. /// </summary> /// <param name="remoteEndpoint">The IPEndpoint of the remote host</param> /// <returns>An IObserver used to send messages to the remote host</returns> public IObserver <T> GetRemoteObserver(RemoteEventEndPoint <T> remoteEndpoint) { if (remoteEndpoint == null) { throw new ArgumentNullException("remoteEndpoint"); } SocketRemoteIdentifier id = remoteEndpoint.Id as SocketRemoteIdentifier; if (id == null) { throw new ArgumentException("ID not supported"); } return(GetRemoteObserver(id.Addr)); }
/// <summary> /// Registers an IObserver used to handle incoming messages from the remote host /// at the specified IPEndPoint. /// The IDisposable that is returned can be used to unregister the IObserver. /// </summary> /// <param name="remoteEndpoint">The IPEndPoint of the remote host</param> /// <param name="observer">The IObserver to handle incoming messages</param> /// <returns>An IDisposable used to unregister the observer with</returns> public IDisposable RegisterObserver(RemoteEventEndPoint <T> remoteEndpoint, IObserver <T> observer) { if (remoteEndpoint == null) { throw new ArgumentNullException("remoteEndpoint"); } SocketRemoteIdentifier id = remoteEndpoint.Id as SocketRemoteIdentifier; if (id == null) { throw new ArgumentException("ID not supported"); } return(RegisterObserver(id.Addr, observer)); }
/// <summary> /// Constructs a DefaultRemoteManager. Does not listen for incoming messages. /// </summary> /// <param name="codec">The codec used for serializing messages</param> internal DefaultRemoteManager(ICodec <T> codec) { using (LOGGER.LogFunction("DefaultRemoteManager::DefaultRemoteManager")) { if (codec == null) { throw new ArgumentNullException("codec"); } _observerContainer = new ObserverContainer <T>(); _codec = new RemoteEventCodec <T>(codec); _cachedClients = new Dictionary <IPEndPoint, ProxyObserver>(); LocalEndpoint = new IPEndPoint(NetworkUtils.LocalIPAddress, 0); Identifier = new SocketRemoteIdentifier(LocalEndpoint); } }
/// <summary> /// Constructs a DefaultRemoteManager. Does not listen for incoming messages. /// </summary> /// <param name="localAddressProvider">The local address provider</param> /// <param name="codec">The codec used for serializing messages</param> /// <param name="tcpClientFactory">provides TcpClient for given endpoint</param> internal DefaultRemoteManager( ILocalAddressProvider localAddressProvider, ICodec <T> codec, ITcpClientConnectionFactory tcpClientFactory) { using (LOGGER.LogFunction("DefaultRemoteManager::DefaultRemoteManager")) { if (codec == null) { throw new ArgumentNullException("codec"); } _tcpClientFactory = tcpClientFactory; _observerContainer = new ObserverContainer <T>(); _codec = new RemoteEventCodec <T>(codec); _cachedClients = new Dictionary <IPEndPoint, ProxyObserver>(); LocalEndpoint = new IPEndPoint(localAddressProvider.LocalAddress, 0); Identifier = new SocketRemoteIdentifier(LocalEndpoint); } }
/// <summary> /// Look up the IObserver for the registered IPEndPoint or event type /// and execute the IObserver. /// </summary> /// <param name="transportEvent">The incoming remote event</param> public void OnNext(TransportEvent <IRemoteEvent <T> > transportEvent) { IRemoteEvent <T> remoteEvent = transportEvent.Data; remoteEvent.LocalEndPoint = transportEvent.Link.LocalEndpoint; remoteEvent.RemoteEndPoint = transportEvent.Link.RemoteEndpoint; T value = remoteEvent.Value; bool handled = false; if (_universalObserver != null) { _universalObserver.OnNext(value); handled = true; } if (_remoteMessageUniversalObserver != null) { // IObserver was registered by event type IRemoteIdentifier id = new SocketRemoteIdentifier(remoteEvent.RemoteEndPoint); IRemoteMessage <T> remoteMessage = new DefaultRemoteMessage <T>(id, value); _remoteMessageUniversalObserver.OnNext(remoteMessage); handled = true; } IObserver <T> observer; if (_endpointMap.TryGetValue(remoteEvent.RemoteEndPoint, out observer)) { // IObserver was registered by IPEndpoint observer.OnNext(value); handled = true; } if (!handled) { throw new WakeRuntimeException("Unrecognized Wake RemoteEvent message"); } }
public WritableRemoteManager(IPAddress localAddress, int port, ITcpPortProvider tcpPortProvider, IInjector injector) { if (localAddress == null) { throw new ArgumentNullException("localAddress"); } if (port < 0) { throw new ArgumentException("Listening port must be greater than or equal to zero"); } _observerContainer = new WritableObserverContainer <T>(); _cachedClients = new Dictionary <IPEndPoint, ProxyObserver>(); _injector = injector; IPEndPoint localEndpoint = new IPEndPoint(localAddress, port); // Begin to listen for incoming messages _server = new WritableTransportServer <IWritableRemoteEvent <T> >(localEndpoint, _observerContainer, tcpPortProvider, injector); _server.Run(); LocalEndpoint = _server.LocalEndpoint; Identifier = new SocketRemoteIdentifier(LocalEndpoint); }
public static void Main(string[] args) { try { Console.WriteLine("START: {0} Evaluator::InitInjector.", DateTime.Now); Stopwatch timer = new Stopwatch(); InitInjector(); SetCustomTraceListeners(); // logger is reset by this. timer.Stop(); Console.WriteLine("EXIT: {0} Evaluator::InitInjector. Duration: [{1}].", DateTime.Now, timer.Elapsed); using (logger.LogScope("Evaluator::Main")) { if (IsDebuggingEnabled()) { AttachDebugger(); } // Register our exception handler AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; // Fetch some settings from the ConfigurationManager SetHeartbeatPeriod(); SetHeartbeatMaxRetry(); // Parse the command line // The error handler RID should now be written in the configuration file instead if (args.Count() != 1) { var e = new InvalidOperationException("must supply only the evaluator config file!"); Utilities.Diagnostics.Exceptions.Throw(e, logger); } // evaluator configuration file string evaluatorConfigurationPath = args[0]; // Parse the evaluator configuration. evaluatorConfig = new EvaluatorConfigurations(evaluatorConfigurationPath); string rId = evaluatorConfig.ErrorHandlerRID; ContextConfiguration rootContextConfiguration = evaluatorConfig.RootContextConfiguration; Optional<TaskConfiguration> rootTaskConfig = evaluatorConfig.TaskConfiguration; Optional<ServiceConfiguration> rootServiceConfig = evaluatorConfig.RootServiceConfiguration; // remoteManager used as client-only in evaluator IRemoteManager<REEFMessage> remoteManager = injector.GetInstance<IRemoteManagerFactory>().GetInstance(new REEFMessageCodec()); IRemoteIdentifier remoteId = new SocketRemoteIdentifier(NetUtilities.ParseIpEndpoint(rId)); RuntimeClock clock = InstantiateClock(); logger.Log(Level.Info, "Application Id: " + evaluatorConfig.ApplicationId); EvaluatorSettings evaluatorSettings = new EvaluatorSettings( evaluatorConfig.ApplicationId, evaluatorConfig.EvaluatorId, heartbeatPeriodInMs, heartbeatMaxRetry, rootContextConfiguration, clock, remoteManager, injector); HeartBeatManager heartBeatManager = new HeartBeatManager(evaluatorSettings, remoteId); ContextManager contextManager = new ContextManager(heartBeatManager, rootServiceConfig, rootTaskConfig); EvaluatorRuntime evaluatorRuntime = new EvaluatorRuntime(contextManager, heartBeatManager); // TODO: replace with injectionFuture heartBeatManager._evaluatorRuntime = evaluatorRuntime; heartBeatManager._contextManager = contextManager; SetRuntimeHandlers(evaluatorRuntime, clock); clock.Run(); } } catch (Exception e) { Fail(e); } }
public static void Main(string[] args) { try { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "START: {0} Evaluator::InitInjector.", DateTime.Now)); Stopwatch timer = new Stopwatch(); InitInjector(); SetCustomTraceListners(); // _logger is reset by this. timer.Stop(); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "EXIT: {0} Evaluator::InitInjector. Duration: [{1}].", DateTime.Now, timer.Elapsed)); using (_logger.LogScope("Evaluator::Main")) { // Wait for the debugger, if enabled AttachDebuggerIfEnabled(); // Register our exception handler AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; // Fetch some settings from the ConfigurationManager SetHeartbeatPeriod(); SetHeartbeatMaxRetry(); // Parse the command line if (args.Count() < 2) { var e = new InvalidOperationException("must supply at least the rId and evaluator config file"); Utilities.Diagnostics.Exceptions.Throw(e, _logger); } // remote driver Id string rId = args[0]; // evaluator configuraiton file string evaluatorConfigurationPath = args[1]; // Parse the evaluator configuration. _evaluatorConfig = new EvaluatorConfigurations(evaluatorConfigurationPath); ContextConfiguration rootContextConfiguration = _evaluatorConfig.RootContextConfiguration; Optional<TaskConfiguration> rootTaskConfig = _evaluatorConfig.TaskConfiguration; Optional<ServiceConfiguration> rootServiceConfig = _evaluatorConfig.RootServiceConfiguration; // remoteManager used as client-only in evaluator IRemoteManager<REEFMessage> remoteManager = _injector.GetInstance<IRemoteManagerFactory>().GetInstance(new REEFMessageCodec()); IRemoteIdentifier remoteId = new SocketRemoteIdentifier(NetUtilities.ParseIpEndpoint(rId)); RuntimeClock clock = InstantiateClock(); _logger.Log(Level.Info, "Application Id: " + _evaluatorConfig.ApplicationId); EvaluatorSettings evaluatorSettings = new EvaluatorSettings( _evaluatorConfig.ApplicationId, _evaluatorConfig.EvaluatorId, _heartbeatPeriodInMs, _heartbeatMaxRetry, rootContextConfiguration, clock, remoteManager, _injector); HeartBeatManager heartBeatManager = new HeartBeatManager(evaluatorSettings, remoteId); ContextManager contextManager = new ContextManager(heartBeatManager, rootServiceConfig, rootTaskConfig); EvaluatorRuntime evaluatorRuntime = new EvaluatorRuntime(contextManager, heartBeatManager); // TODO: replace with injectionFuture heartBeatManager._evaluatorRuntime = evaluatorRuntime; heartBeatManager._contextManager = contextManager; SetRuntimeHandlers(evaluatorRuntime, clock); Task evaluatorTask = Task.Run(new Action(clock.Run)); evaluatorTask.Wait(); } } catch (Exception e) { Fail(e); } }