/// <summary> /// Stops the journaler; derived classes may override this method to perform /// additional logic when stopping. The registration key controls the journaler's /// registration with the underlying IEventListener. At the time of the call /// the registration is suspended (journaler is no longer receiving LWES events). /// It is the responsibility of the derived class to either call the base-class /// PerformStop method or cancel the registration key. The journaler will hold /// the registration key indefinitely if it is not canceled. /// </summary> /// <param name="registrationKey"></param> /// <returns></returns> protected virtual bool PerformStop(ISinkRegistrationKey registrationKey) { if (registrationKey == null) throw new ArgumentNullException("registrationKey"); registrationKey.Cancel(); return true; }
/// <summary> /// Starts the journaler; derived classes may override this method to perform /// additional logic when starting. The registration key controls the journaler's /// registration with the underlying IEventListener. At the time of the call /// the registration is suspended (journaler is not yet receiving LWES events). /// It is the responsibility of the derived class to either call the base-class /// PerformStart method or activate the registration key. LWES events will not /// flow to the journaler until the key has been activated. /// </summary> /// <param name="registrationKey"></param> /// <returns></returns> protected virtual bool PerformStart(ISinkRegistrationKey registrationKey) { if (registrationKey == null) throw new ArgumentNullException("registrationKey"); return registrationKey.Activate(); }
/// <summary> /// Starts the journaler. /// </summary> public void Start() { if (_status.SetStateIfLessThan(JournalerState.Starting, JournalerState.Initialized)) { try { _registrationKey = _listener.RegisterDataReceiverSink(this); // Let the subclass decide if the start succeeded. if (PerformStart(_registrationKey) && _registrationKey.Activate()) { _status.TryTransition(JournalerState.Active, JournalerState.Starting); } } catch (Exception e) { this.TraceData(TraceEventType.Error, Resources.Error_UnexpectedErrorStartngJournaler, e); _status.TryTransition(JournalerState.Initialized, JournalerState.Starting); } } }
/// <summary> /// Stops the journaler. /// </summary> public void Stop() { if (_status.SetStateIfLessThan(JournalerState.Stopping, JournalerState.Active)) { try { _registrationKey.Suspend(); // Let the subclass decide if the stop succeeded. if (PerformStop(_registrationKey)) { _registrationKey = null; _status.TryTransition(JournalerState.Stopped, JournalerState.Stopping); } } catch (Exception e) { this.TraceData(TraceEventType.Error, Resources.Error_UnexpectedErrorStoppingJournaler, e); _status.TryTransition(JournalerState.Active, JournalerState.Stopping); } } }
bool IDataReceiverSink.HandleData(ISinkRegistrationKey key, EndPoint remoteEP, byte[] data, int offset, int count) { return PerformHandleData(remoteEP, data, offset, count); }