use of org.apache.storm.shade.io.netty.channel.Channel in project storm by apache.
the class KerberosSaslClientHandler method handleControlMessage.
private void handleControlMessage(ChannelHandlerContext ctx, ControlMessage controlMessage) throws Exception {
Channel channel = ctx.channel();
KerberosSaslNettyClient saslNettyClient = getChannelSaslClient(channel);
if (controlMessage == ControlMessage.SASL_COMPLETE_REQUEST) {
LOG.debug("Server has sent us the SaslComplete message. Allowing normal work to proceed.");
if (!saslNettyClient.isComplete()) {
String errorMessage = "Server returned a Sasl-complete message, but as far as we can tell, we are not authenticated yet.";
LOG.error(errorMessage);
throw new Exception(errorMessage);
}
ctx.pipeline().remove(this);
this.client.channelReady(channel);
// We call fireChannelRead since the client is allowed to
// perform this request. The client's request will now proceed
// to the next pipeline component namely StormClientHandler.
ctx.fireChannelRead(controlMessage);
} else {
LOG.warn("Unexpected control message: {}", controlMessage);
}
}
use of org.apache.storm.shade.io.netty.channel.Channel in project storm by apache.
the class Client method closeChannel.
private void closeChannel() {
Channel channel = channelRef.get();
if (channel != null) {
channel.close();
LOG.debug("channel to {} closed", dstAddressPrefixedName);
}
}
use of org.apache.storm.shade.io.netty.channel.Channel in project storm by apache.
the class PacemakerClient method channelReady.
@Override
public synchronized void channelReady(Channel channel) {
Channel oldChannel = channelRef.get();
if (oldChannel != null) {
LOG.debug("Closing oldChannel is connected: {}", oldChannel.toString());
close_channel();
}
channelRef.set(channel);
retryTimes = 0;
LOG.debug("Channel is ready: {}", channel.toString());
ready.set(true);
this.notifyAll();
}
use of org.apache.storm.shade.io.netty.channel.Channel in project storm by apache.
the class KerberosSaslClientHandler method handleSaslMessageToken.
private void handleSaslMessageToken(ChannelHandlerContext ctx, SaslMessageToken saslMessageToken) throws Exception {
Channel channel = ctx.channel();
KerberosSaslNettyClient saslNettyClient = getChannelSaslClient(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("Our reponse to the server is null, but as far as we can tell, we are not authenticated yet.");
}
this.client.channelReady(channel);
} 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());
}
}
use of org.apache.storm.shade.io.netty.channel.Channel in project storm by apache.
the class Client method send.
/**
* Enqueue task messages to be sent to the remote destination (cf. `host` and `port`).
*/
@Override
public void send(Iterator<TaskMessage> msgs) {
if (closing) {
int numMessages = iteratorSize(msgs);
LOG.error("Dropping {} messages because the Netty client to {} is being closed", numMessages, dstAddressPrefixedName);
return;
}
if (!hasMessages(msgs)) {
return;
}
Channel channel = getConnectedChannel();
if (channel == null) {
/*
* Connection is unavailable. We will drop pending messages and let at-least-once message replay kick in.
*
* Another option would be to buffer the messages in memory. But this option has the risk of causing OOM errors,
* especially for topologies that disable message acking because we don't know whether the connection recovery will
* succeed or not, and how long the recovery will take.
*/
dropMessages(msgs);
return;
}
try {
while (msgs.hasNext()) {
TaskMessage message = msgs.next();
MessageBatch batch = batcher.add(message);
if (batch != null) {
writeMessage(channel, batch);
}
}
MessageBatch batch = batcher.drain();
if (batch != null) {
writeMessage(channel, batch);
}
} catch (IOException e) {
LOG.warn("Exception when sending message to remote worker.", e);
dropMessages(msgs);
}
}
Aggregations