void OnReceiveDetach(Detach detach) { if (detach.Error != null) { Utils.Trace(TraceLevel.Error, "{0}: Detach {1}", this, detach.Error); } StateTransition stateTransition; this.TransitState("R:DETACH", StateTransition.ReceiveClose, out stateTransition); if (stateTransition.To == AmqpObjectState.End) { this.CompleteClose(false, null); } else { if (detach.Error != null) { this.CompleteOpen(false, AmqpException.FromError(detach.Error)); } this.Close(); } }
// Use this for initialization void Start() { timer = 0; waitTime = 2f; runControl = FindObjectOfType <BeginRun>(); launchControl = FindObjectOfType <Detach>(); }
private void RemotelyCloseLastCoordinatorLink(bool expectDetachResponse, bool closed, Error error) { lock (matchersLock) { var matcher = GetLastMatcher(); matcher.WithOnComplete(context => { var detach = new Detach { Closed = true, Handle = lastInitiatedCoordinatorLinkHandle }; if (error != null) { detach.Error = error; } context.SendCommand(detach); }); if (expectDetachResponse) { var detachMatcher = new FrameMatcher <Detach>().WithAssertion(detach => Assert.AreEqual(closed, detach.Closed)); AddMatcher(detachMatcher); } } }
void OnReceiveDetach(Detach detach) { AmqpTrace.Provider.AmqpLinkDetach(this, this.Name, this.LocalHandle ?? 0u, "R:DETACH", detach.Error != null ? detach.Error.Condition.Value : string.Empty); this.OnReceiveCloseCommand("R:DETACH", detach.Error); }
public void ExpectDetach(bool expectClosed, bool sendResponse, bool replyClosed, Symbol errorType = null, String errorMessage = null) { var detachMatcher = new FrameMatcher <Detach>() .WithAssertion(detach => Assert.AreEqual(expectClosed, detach.Closed)); if (sendResponse) { detachMatcher.WithOnComplete(context => { var detach = new Detach { Closed = replyClosed, Handle = context.Command.Handle }; if (errorType != null) { detach.Error = new Error(errorType) { Description = errorMessage }; } context.SendCommand(detach); }); } AddMatcher(detachMatcher); }
internal bool OnDetach(Detach detach) { this.Error = detach.Error; lock (this.ThisLock) { if (this.state == LinkState.DetachSent) { this.state = LinkState.End; } else if (this.state == LinkState.Attached) { this.SendDetach(null); this.state = LinkState.End; } else { throw new AmqpException(ErrorCode.IllegalState, Fx.Format(SRAmqp.AmqpIllegalOperationState, "OnDetach", this.state)); } this.OnClose(detach.Error); } this.session.RemoveLink(this, detach.Handle); this.NotifyClosed(detach.Error); return(true); }
public static bool Closed(this Detach detach) { if (!detach.Closed.HasValue) { return(false); } return(detach.Closed.Value); }
void SendDetach(Error error) { Detach detach = new Detach() { Handle = this.handle, Error = error, Closed = true }; this.session.SendCommand(detach); }
// Use this for initialization void Start() { launcher = GameObject.Find("PlayerThrower").GetComponent <Detach>(); player = GameObject.FindGameObjectWithTag("Player"); obstacleModifier = FindObjectOfType <Bounce>(); gameScore = FindObjectOfType <Score>(); booster = FindObjectOfType <Jetpack>(); openShop = GetComponent <AudioSource>(); upgradeScreen.SetActive(false); }
void OnDetach(Detach detach) { Link link = this.GetLink(detach.Handle); if (link.OnDetach(detach)) { lock (this.ThisLock) { this.localLinks[link.Handle] = null; this.remoteLinks[detach.Handle] = null; } } }
private void InterceptDetachFrame(Detach detach) { if (!State.CanReceiveFrames()) { throw new AmqpException(ErrorCode.IllegalState, $"Received Detach frame but session state is {State.ToString()}."); } if (State == SessionStateEnum.DISCARDING) { return; } GetRemoteLink(detach.Handle).HandleLinkFrame(detach); }
void SendDetach(Error error) { Detach detach = new Detach() { Handle = this.handle, Error = error, Closed = !this.detach }; IHandler handler = this.session.Connection.Handler; if (handler != null && handler.CanHandle(EventId.LinkLocalClose)) { handler.Handle(Event.Create(EventId.LinkLocalClose, this.session.Connection, this.session, this, context: detach)); } this.session.SendCommand(detach); }
internal bool OnDetach(Detach detach) { IHandler handler = this.session.Connection.Handler; if (handler != null && handler.CanHandle(EventId.LinkRemoteClose)) { handler.Handle(Event.Create(EventId.LinkRemoteClose, this.session.Connection, this.session, this, context: detach)); } Error remoteError = detach.Error; if (remoteError == null && this.detach && detach.Closed) { remoteError = new Error(ErrorCode.InternalError) { Description = "Link is closed by peer though a detach was requested." }; } this.Error = remoteError; lock (this.ThisLock) { if (this.state == LinkState.DetachSent) { this.state = LinkState.End; } else if (this.state == LinkState.Attached) { this.SendDetach(null); this.state = LinkState.End; } else { throw new AmqpException(ErrorCode.IllegalState, Fx.Format(SRAmqp.AmqpIllegalOperationState, "OnDetach", this.state)); } this.OnClose(remoteError); } this.session.RemoveLink(this, detach.Handle); this.NotifyClosed(remoteError); return(true); }
private AmqpObjectState SendDetach() { StateTransition stateTransition = base.TransitState("S:DETACH", StateTransition.SendClose); Detach detach = new Detach() { Handle = this.LocalHandle, Closed = new bool?(true) }; Exception terminalException = base.TerminalException; if (terminalException != null) { detach.Error = AmqpError.FromException(terminalException, true); } this.Session.SendCommand(detach); return(stateTransition.To); }
void SendDetach() { this.TransitState("S:DETACH", StateTransition.SendClose); Detach detach = new Detach(); detach.Handle = this.LocalHandle; detach.Closed = true; Exception exception = this.TerminalException; if (exception != null) { detach.Error = AmqpError.FromException(exception); } this.Session.SendCommand(detach); }
private void HandleDetachFrame(Detach detach) { if (State != LinkStateEnum.ATTACHED && State != LinkStateEnum.DETACH_SENT && State != LinkStateEnum.DESTROYED) { throw new AmqpException(ErrorCode.IllegalState, $"Received Detach frame but link state is {State.ToString()}."); } if (detach.Error != null) { trace.Debug("Detaching Link {0} Due to Error From Remote Link Endpoint: '{1}'", LocalHandle, detach.Error); } if (State == LinkStateEnum.ATTACHED) { State = LinkStateEnum.DETACH_RECEIVED; } DetachLink(null, destoryLink: detach.Closed); }
AmqpObjectState SendDetach() { StateTransition transition = this.TransitState("S:DETACH", StateTransition.SendClose); Detach detach = new Detach(); detach.Handle = this.LocalHandle; detach.Closed = true; Exception exception = this.TerminalException; if (exception != null && transition.To != AmqpObjectState.End) { detach.Error = Error.FromException(exception); } this.Session.SendCommand(detach); AmqpTrace.Provider.AmqpLinkDetach(this, this.Name, this.LocalHandle ?? 0u, "S:DETACH", detach.Error != null ? detach.Error.Condition.Value : string.Empty); return(transition.To); }
internal bool OnDetach(Detach detach) { Error remoteError = detach.Error; if (remoteError == null && this.detach && detach.Closed) { remoteError = new Error() { Condition = ErrorCode.InternalError, Description = "Link is closed by peer though a detach was requested." }; } this.Error = remoteError; lock (this.ThisLock) { if (this.state == LinkState.DetachSent) { this.state = LinkState.End; } else if (this.state == LinkState.Attached) { this.SendDetach(null); this.state = LinkState.End; } else { throw new AmqpException(ErrorCode.IllegalState, Fx.Format(SRAmqp.AmqpIllegalOperationState, "OnDetach", this.state)); } this.OnClose(remoteError); } this.session.RemoveLink(this, detach.Handle); this.NotifyClosed(remoteError); return(true); }
public void RemotelyDetachLastOpenedLinkOnLastOpenedSession(bool expectDetachResponse, bool closed, Symbol errorType, string errorMessage, int delayBeforeSend = 0) { lock (matchers) { IMatcher lastMatcher = GetLastMatcher(); lastMatcher.WithOnComplete(context => { Detach detach = new Detach() { Closed = closed, Handle = lastInitiatedLinkHandle }; if (errorType != null) { detach.Error = new Error(errorType) { Description = errorMessage, }; } //Insert a delay if requested if (delayBeforeSend > 0) { Thread.Sleep(delayBeforeSend); } context.SendCommand(lastInitiatedChannel, detach); }); if (expectDetachResponse) { // Expect a response to our Detach. var detachMatcher = new FrameMatcher <Detach>() .WithAssertion(detach => Assert.AreEqual(closed, detach.Closed)); // TODO: enable matching on the channel number of the response. AddMatcher(detachMatcher); } } }
void OnDetach(Detach detach) { Link link = this.GetLink(detach.Handle); link.OnDetach(detach); }
public virtual IEnumerator<ITask> DetachHandler(Detach detach) { // Check if the sensor was already registered. UnregisterDevice(detach.Body.ServiceUri); detach.ResponsePort.Post(DefaultSubmitResponseType.Instance); yield break; }
public void ExpectReceiverAttach( Action <string> linkNameMatcher, Action <Source> sourceMatcher, Action <Target> targetMatcher, bool settled = false, bool refuseLink = false, Symbol errorType = null, string errorMessage = null, Source responseSourceOverride = null, Action <Symbol[]> desiredCapabilitiesMatcher = null) { var attachMatcher = new FrameMatcher <Attach>() .WithAssertion(attach => linkNameMatcher(attach.LinkName)) .WithAssertion(attach => Assert.AreEqual(Role.RECEIVER, attach.Role)) .WithAssertion(attach => Assert.AreEqual(settled ? SenderSettleMode.Settled : SenderSettleMode.Unsettled, attach.SndSettleMode)) .WithAssertion(attach => Assert.AreEqual(ReceiverSettleMode.First, attach.RcvSettleMode)) .WithAssertion(attach => sourceMatcher(attach.Source as Source)) .WithAssertion(attach => targetMatcher(attach.Target as Target)) .WithOnComplete(context => { var attach = new Attach() { Role = Role.SENDER, SndSettleMode = SenderSettleMode.Unsettled, RcvSettleMode = ReceiverSettleMode.First, InitialDeliveryCount = 0, Handle = context.Command.Handle, LinkName = context.Command.LinkName, Target = context.Command.Target, }; if (refuseLink) { attach.Source = null; } else if (responseSourceOverride != null) { attach.Source = responseSourceOverride; } else { attach.Source = context.Command.Source; } this.lastInitiatedLinkHandle = context.Command.Handle; context.SendCommand(attach); }); if (desiredCapabilitiesMatcher != null) { attachMatcher.WithAssertion(attach => desiredCapabilitiesMatcher(attach.DesiredCapabilities)); } if (refuseLink) { attachMatcher.WithOnComplete(context => { var detach = new Detach { Closed = true, Handle = context.Command.Handle }; context.SendCommand(detach); }); } AddMatcher(attachMatcher); }
// detach public static bool Closed(this Detach detach) { return(detach.Closed == null ? false : detach.Closed.Value); }
internal void OnDetach() { Detach?.Invoke(this, EventArgs.Empty); }
public void ExpectSenderAttach(Action <Source> sourceMatcher, Action <Target> targetMatcher, bool refuseLink = false, uint creditAmount = 100, bool senderSettled = false) { var attachMatcher = new FrameMatcher <Attach>() .WithAssertion(attach => Assert.IsNotNull(attach.LinkName)) .WithAssertion(attach => Assert.AreEqual(attach.Role, Role.SENDER)) .WithAssertion(attach => Assert.AreEqual(senderSettled ? SenderSettleMode.Settled : SenderSettleMode.Unsettled, attach.SndSettleMode)) .WithAssertion(attach => Assert.AreEqual(attach.RcvSettleMode, ReceiverSettleMode.First)) .WithAssertion(attach => sourceMatcher(attach.Source as Source)) .WithAssertion(attach => targetMatcher(attach.Target as Target)) .WithOnComplete(context => { var attach = new Attach() { Role = Role.RECEIVER, OfferedCapabilities = null, SndSettleMode = senderSettled ? SenderSettleMode.Settled : SenderSettleMode.Unsettled, RcvSettleMode = ReceiverSettleMode.First, Handle = context.Command.Handle, LinkName = context.Command.LinkName, Source = context.Command.Source }; if (refuseLink) { attach.Target = null; } else { attach.Target = context.Command.Target; } lastInitiatedLinkHandle = context.Command.Handle; context.SendCommand(attach); if (refuseLink) { var detach = new Detach { Closed = true, Handle = context.Command.Handle }; context.SendCommand(detach); } else { var flow = new Flow { NextIncomingId = 1, IncomingWindow = 2048, NextOutgoingId = 1, OutgoingWindow = 2024, LinkCredit = creditAmount, Handle = context.Command.Handle, DeliveryCount = context.Command.InitialDeliveryCount, }; context.SendCommand(flow); } }); AddMatcher(attachMatcher); }
private void OnReceiveDetach(Detach detach) { base.OnReceiveCloseCommand("R:DETACH", detach.Error); }