Пример #1
0
 public override void Handle(SwitchOverResponse response)
 {
     EnsureMagic();
     if (_protocolStack == null)
     {
         Decline("Attempted to switch over when protocol stack not established");
     }
     else if (response.Status() != StatusCode.Success)
     {
         Decline("Server failed to switch over");
     }
     else
     {
         _future.complete(_protocolStack);
     }
 }
Пример #2
0
        public override void Handle(SwitchOverRequest switchOverRequest)
        {
            EnsureMagic();
            ProtocolStack protocolStack = _protocolStackBuilder.build();
            Optional <Protocol_ApplicationProtocol> switchOverProtocol  = _applicationProtocolRepository.select(switchOverRequest.ProtocolName(), switchOverRequest.Version());
            IList <Protocol_ModifierProtocol>       switchOverModifiers = switchOverRequest.ModifierProtocols().Select(pair => _modifierProtocolRepository.select(pair.first(), pair.other())).flatMap(Streams.ofOptional).ToList();

            if (!switchOverProtocol.Present)
            {
                _channel.writeAndFlush(SwitchOverResponse.Failure);
                Decline(string.Format("Cannot switch to protocol {0} version {1:D}", switchOverRequest.ProtocolName(), switchOverRequest.Version()));
            }
            else if (protocolStack.ApplicationProtocol() == null)
            {
                _channel.writeAndFlush(SwitchOverResponse.Failure);
                Decline(string.Format("Attempted to switch to protocol {0} version {1:D} before negotiation complete", switchOverRequest.ProtocolName(), switchOverRequest.Version()));
            }
            else if (!switchOverProtocol.get().Equals(protocolStack.ApplicationProtocol()))
            {
                _channel.writeAndFlush(SwitchOverResponse.Failure);
                Decline(string.Format("Switch over mismatch: requested {0} version {1} but negotiated {2} version {3}", switchOverRequest.ProtocolName(), switchOverRequest.Version(), protocolStack.ApplicationProtocol().category(), protocolStack.ApplicationProtocol().implementation()));
            }
//JAVA TO C# CONVERTER WARNING: LINQ 'SequenceEqual' is not always identical to Java AbstractList 'equals':
//ORIGINAL LINE: else if (!switchOverModifiers.equals(protocolStack.modifierProtocols()))
            else if (!switchOverModifiers.SequenceEqual(protocolStack.ModifierProtocols()))
            {
                _channel.writeAndFlush(SwitchOverResponse.Failure);
                Decline(string.Format("Switch over mismatch: requested modifiers {0} but negotiated {1}", switchOverRequest.ModifierProtocols(), protocolStack.ModifierProtocols()));
            }
            else
            {
                SwitchOverResponse response = new SwitchOverResponse(SUCCESS);
                _channel.writeAndFlush(response);

                _protocolStackFuture.complete(protocolStack);
            }
        }
Пример #3
0
 public override void Handle(SwitchOverResponse switchOverResponse)
 {
     Out.writeInt(2);
     Out.writeInt(switchOverResponse.Status().codeValue());
 }