Search in sources :

Example 11 with Channel

use of org.apache.storm.shade.io.netty.channel.Channel in project storm by apache.

the class SaslStormClientHandler method channelActive.

@Override
public void channelActive(ChannelHandlerContext ctx) {
    Channel channel = ctx.channel();
    LOG.info("Connection established from " + channel.localAddress() + " to " + channel.remoteAddress());
    try {
        SaslNettyClient saslNettyClient = channel.attr(SaslNettyClientState.SASL_NETTY_CLIENT).get();
        if (saslNettyClient == null) {
            LOG.debug("Creating saslNettyClient now " + "for channel: " + channel);
            saslNettyClient = new SaslNettyClient(name, token);
            channel.attr(SaslNettyClientState.SASL_NETTY_CLIENT).set(saslNettyClient);
        }
        LOG.debug("Sending SASL_TOKEN_MESSAGE_REQUEST");
        channel.writeAndFlush(ControlMessage.SASL_TOKEN_MESSAGE_REQUEST, channel.voidPromise());
    } catch (Exception e) {
        LOG.error("Failed to authenticate with server " + "due to error: ", e);
    }
}
Also used : Channel(org.apache.storm.shade.io.netty.channel.Channel) IOException(java.io.IOException)

Example 12 with Channel

use of org.apache.storm.shade.io.netty.channel.Channel in project storm by apache.

the class SaslStormClientHandler method handleSaslMessageToken.

private void handleSaslMessageToken(ChannelHandlerContext ctx, SaslMessageToken saslMessageToken) throws Exception {
    Channel channel = ctx.channel();
    SaslNettyClient saslNettyClient = getChannelSaslNettyClient(channel);
    LOG.debug("Responding to server's token of length: " + saslMessageToken.getSaslToken().length);
    // Generate SASL response (but we only actually send the response if
    // it's non-null.
    byte[] responseToServer = saslNettyClient.saslResponse(saslMessageToken);
    if (responseToServer == null) {
        // If we generate a null response, then authentication has completed
        // (if not, warn), and return without sending a response back to the
        // server.
        LOG.debug("Response to server is null: " + "authentication should now be complete.");
        if (!saslNettyClient.isComplete()) {
            LOG.warn("Generated a null response, " + "but authentication is not complete.");
            throw new Exception("Server response is null, but as far as " + "we can tell, we are not authenticated yet.");
        }
        this.client.channelReady(channel);
        return;
    } else {
        LOG.debug("Response to server token has length:" + responseToServer.length);
    }
    // Construct a message containing the SASL response and send it to the
    // server.
    SaslMessageToken saslResponse = new SaslMessageToken(responseToServer);
    channel.writeAndFlush(saslResponse, channel.voidPromise());
}
Also used : Channel(org.apache.storm.shade.io.netty.channel.Channel) IOException(java.io.IOException)

Example 13 with Channel

use of org.apache.storm.shade.io.netty.channel.Channel in project storm by apache.

the class Client method srcAddressName.

private String srcAddressName() {
    String name = null;
    Channel channel = channelRef.get();
    if (channel != null) {
        SocketAddress address = channel.localAddress();
        if (address != null) {
            name = address.toString();
        }
    }
    return name;
}
Also used : NioSocketChannel(org.apache.storm.shade.io.netty.channel.socket.nio.NioSocketChannel) Channel(org.apache.storm.shade.io.netty.channel.Channel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

Channel (org.apache.storm.shade.io.netty.channel.Channel)13 IOException (java.io.IOException)8 NioSocketChannel (org.apache.storm.shade.io.netty.channel.socket.nio.NioSocketChannel)5 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 HBMessage (org.apache.storm.generated.HBMessage)1 TaskMessage (org.apache.storm.messaging.TaskMessage)1