Esempio n. 1
0
 public override void Handle(SwitchOverRequest switchOverRequest)
 {
     Out.writeInt(3);
     StringMarshal.marshal(Out, switchOverRequest.ProtocolName());
     Out.writeInt(switchOverRequest.Version());
     Out.writeInt(switchOverRequest.ModifierProtocols().Count);
     switchOverRequest.ModifierProtocols().ForEach(pair =>
     {
         StringMarshal.marshal(Out, pair.first());
         StringMarshal.marshal(Out, pair.other());
     });
 }
Esempio n. 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);
            }
        }