/// <summary> /// Release any contained resources. /// </summary> /// <param name="disposing">true if managed resources are to be released</param> protected virtual void Dispose(bool disposing) { if (!disposing) { return; } if (_isRunning) { Stop(); } if (_poller.IsRunning) { _poller?.Stop(); } _poller?.Dispose(); _beacon?.Dispose(); _inbox?.Dispose(); _outbox?.Dispose(); foreach (var peer in _peers.Values) { peer.Destroy(); } foreach (var group in _peerGroups.Values) { group.Dispose(); } foreach (var group in _ownGroups.Values) { group.Dispose(); } }
public void Dispose() { _actor?.Dispose(); _publisher?.Dispose(); _subscriber?.Dispose(); _beacon?.Dispose(); _poll?.Dispose(); _shim?.Dispose(); }
/// <summary> /// Release any contained resources. /// </summary> /// <param name="disposing">true if managed resources are to be released</param> protected virtual void Dispose(bool disposing) { if (!disposing) { return; } Stop(); if (_useEvents) { _inboxPoller?.StopAsync(); _inboxPoller?.Dispose(); } _actor?.Dispose(); _inbox?.Dispose(); }
/// <summary> /// Release any contained resources. /// </summary> public void Dispose() { //send destroy message to pipe m_self.Options.SendTimeout = TimeSpan.Zero; try { m_self.Send(ActorKnownMessages.END_PIPE); m_self.WaitForSignal(); } catch (AgainException) { } m_shimTask.Wait(); m_self.Dispose(); m_sendEvent.Dispose(); m_receiveEvent.Dispose(); }
/// <summary> /// Release any contained resources. /// </summary> /// <param name="disposing">true if managed resources are to be released</param> protected virtual void Dispose(bool disposing) { if (!disposing) { return; } // send destroy message to pipe if (m_self.TrySendFrame(EndShimMessage)) { m_self.ReceiveSignal(); } m_shimThread.Join(); m_self.Dispose(); m_sendEvent.Dispose(); m_receiveEvent.Dispose(); }
private void CreateShimThread(T state) { //start Shim thread Task shimTask = Task.Factory.StartNew( x => this.shim.Handler.RunPipeline(this.shim.Pipe), TaskCreationOptions.LongRunning); //pipeline dead if task completed, no matter what state it completed in //it is unusable to the Actors socket, to dispose of Actors socket shimTask.ContinueWith(antecedant => { //Dispose of own socket if (self != null) { self.Dispose(); } }); }
protected virtual void Dispose(bool disposing) { // release other disposable objects if (disposing) { //send destroy message to pipe m_self.Options.SendTimeout = TimeSpan.Zero; try { m_self.Send(ActorKnownMessages.END_PIPE); m_self.WaitForSignal(); } catch (AgainException ex) { } m_self.Dispose(); } }
public void RunPipeline(PairSocket shim) { while (true) { try { //Message for this actor/shim handler is expected to be //Frame[0] : Command //Frame[1] : Payload // //Result back to actor is a simple echoing of the Payload, where //the payload is prefixed with "ECHO BACK " NetMQMessage msg = shim.ReceiveMessage(); string command = msg[0].ConvertToString(); if (command == ActorKnownMessages.END_PIPE) { break; } if (command == "ECHO") { shim.Send(string.Format("ECHO BACK : {0}", msg[1].ConvertToString())); } else { shim.Send("Error: invalid message to actor"); } } //You WILL need to decide what Exceptions should be caught here, this is for //demonstration purposes only, any unhandled falut will bubble up to callers code catch (Exception e) { shim.Send(string.Format("Error: Exception occurred {0}", e.Message)); } } //broken out of work loop, so should dispose shim socket now shim.Dispose(); }
/// <summary> /// Release any contained resources. /// </summary> /// <param name="disposing">true if managed resources are to be released</param> protected virtual void Dispose(bool disposing) { if (!disposing) { return; } // send destroy message to pipe m_self.Options.SendTimeout = TimeSpan.Zero; try { m_self.Send(EndShimMessage); m_self.ReceiveSignal(); } catch (AgainException) {} m_shimThread.Join(); m_self.Dispose(); }
/// <summary> /// Execute the shimhandler's Run method, signal ok and then dispose of the shim. /// </summary> private void RunShim() { try { m_shimHandler.Run(m_shim); } catch (TerminatingException) {} // Do not block, if the other end of the pipe is already deleted m_shim.Options.SendTimeout = TimeSpan.Zero; try { m_shim.SignalOK(); } catch (AgainException) {} m_shim.Dispose(); }
/// <summary> /// Release any contained resources. /// </summary> /// <param name="disposing">true if managed resources are to be released</param> protected virtual void Dispose(bool disposing) { if (Interlocked.CompareExchange(ref m_isDisposed, 1, 0) != 0) { return; } if (!disposing) { return; } // send destroy message to pipe if (m_self.TrySendFrame(EndShimMessage)) { m_self.ReceiveSignal(); } m_shimThread.Join(); m_self.Dispose(); m_sendEvent.Dispose(); m_receiveEvent.Dispose(); }
public void Run(PairSocket shim) { string shimAdd = $"inproc://wsrouter-{Id}"; Monitor.Enter(this); try { isRuning = true; shim.SignalOK(); shim.ReceiveReady += OnShimReady; MessagesPipe = new PairSocket(); MessagesPipe.Connect(shimAdd); MessagesPipe.ReceiveReady += OnMessagePipeReady; Stream = new StreamSocket(); Stream.Bind(Address); Stream.ReceiveReady += OnStreamReady; Poller = new NetMQPoller { MessagesPipe, shim, Stream }; MessagesPipe.SignalOK(); Poller.Run(); shim.Dispose(); } catch (Exception ex) { Console.WriteLine(ex); } finally { Monitor.Exit(this); } }
public void RunPipeline(PairSocket shim) { shim.SignalOK(); shim.ReceiveReady += OnShimReady; m_messagesPipe = m_context.CreatePairSocket(); m_messagesPipe.Connect(string.Format("inproc://wsrouter-{0}", m_id)); m_messagesPipe.ReceiveReady += OnMessagePipeReady; m_stream = m_context.CreateStreamSocket(); m_stream.ReceiveReady += OnStreamReady; m_poller = new Poller(m_messagesPipe, shim, m_stream); m_messagesPipe.SignalOK(); m_poller.Start(); m_messagesPipe.Dispose(); m_stream.Dispose(); }
void OnApplicationQuit()//cleanup { VisionClient.Close(); VisionClient.Dispose(); SimulationClient.Close(); SimulationClient.Dispose(); ScreenshotServer.Close(); ScreenshotServer.Dispose(); try { VisionPoller.StopAsync(); SimulationPoller.StopAsync(); ScreenshotPoller.StopAsync(); } catch (System.Exception e) { UnityEngine.Debug.Log("Tried to stopasync while the poller wasn't running! Oops."); } VisionPoller.Dispose(); SimulationPoller.Dispose(); ScreenshotPoller.Dispose(); }
/// <summary> /// Create a new Actor within the given shim-handler and state-information. /// </summary> /// <param name="context">the context for this actor to live within</param> /// <param name="shimHandler">this <see cref="IShimHandler"/> is will handle the actions we send to the shim</param> /// <param name="state">this generic type represents the state-information that the action will use</param> public Actor([NotNull] NetMQContext context, [NotNull] IShimHandler <T> shimHandler, T state) { m_self = context.CreatePairSocket(); m_shim = new Shim <T>(shimHandler, context.CreatePairSocket()); m_self.Options.SendHighWatermark = 1000; m_self.Options.SendHighWatermark = 1000; EventHandler <NetMQSocketEventArgs> onReceive = (sender, e) => m_receiveEvent.Fire(this, new NetMQActorEventArgs <T>(this)); EventHandler <NetMQSocketEventArgs> onSend = (sender, e) => m_sendEvent.Fire(this, new NetMQActorEventArgs <T>(this)); m_receiveEvent = new EventDelegator <NetMQActorEventArgs <T> >( () => m_self.ReceiveReady += onReceive, () => m_self.ReceiveReady -= onReceive); m_sendEvent = new EventDelegator <NetMQActorEventArgs <T> >( () => m_self.SendReady += onSend, () => m_self.SendReady -= onSend); //now binding and connect pipe ends string endPoint = string.Empty; while (true) { Action bindAction = () => { endPoint = GetEndPointName(); m_self.Bind(endPoint); }; try { bindAction(); break; } catch (NetMQException nex) { if (nex.ErrorCode == ErrorCode.EFAULT) { bindAction(); } } } m_shim.Pipe.Connect(endPoint); try { //Initialise the shim handler m_shim.Handler.Initialise(state); } catch (Exception) { m_self.Dispose(); m_shim.Pipe.Dispose(); throw; } //Create Shim thread handler CreateShimThread(); // Mandatory handshake for new actor so that constructor returns only // when actor has also initialized. This eliminates timing issues at // application start up. m_self.WaitForSignal(); }
public void Dispose() { m_reader.Dispose(); m_writer.Dispose(); }