Search in sources :

Example 6 with WireFormatInfo

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.WireFormatInfo in project fabric8 by jboss-fuse.

the class OpenwireProtocol method snoopConnectionParameters.

@Override
public void snoopConnectionParameters(final SocketWrapper socket, Buffer received, final Handler<ConnectionParameters> handler) {
    OpenwireProtocolDecoder h = new OpenwireProtocolDecoder(this);
    h.errorHandler(new Handler<String>() {

        @Override
        public void handle(String error) {
            LOG.info("Openwire protocol decoding error: " + error);
            socket.close();
        }
    });
    h.codecHandler(new Handler<Command>() {

        @Override
        public void handle(Command event) {
            if (event instanceof WireFormatInfo) {
                WireFormatInfo info = (WireFormatInfo) event;
                ConnectionParameters parameters = new ConnectionParameters();
                try {
                    parameters.protocolVirtualHost = info.getHost();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                handler.handle(parameters);
            } else {
                LOG.info("Expected a WireFormatInfo frame");
                socket.close();
            }
        }
    });
    socket.readStream().dataHandler(h);
    h.handle(received);
}
Also used : Command(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Command) WireFormatInfo(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.WireFormatInfo) ConnectionParameters(io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters) IOException(java.io.IOException)

Aggregations

WireFormatInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.WireFormatInfo)6 Command (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Command)1 ConnectionParameters (io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters)1 IOException (java.io.IOException)1