use of org.apache.storm.generated.HBMessage in project storm by apache.
the class ThriftDecoder method decode.
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
long available = buf.readableBytes();
if (available < INTEGER_SIZE) {
return null;
}
buf.markReaderIndex();
int thriftLen = buf.readInt();
available -= INTEGER_SIZE;
if (available < thriftLen) {
// We haven't received the entire object yet, return and wait for more bytes.
buf.resetReaderIndex();
return null;
}
byte[] serialized = new byte[thriftLen];
buf.readBytes(serialized, 0, thriftLen);
HBMessage m = (HBMessage) Utils.thriftDeserialize(HBMessage.class, serialized);
if (m.get_type() == HBServerMessageType.CONTROL_MESSAGE) {
ControlMessage cm = ControlMessage.read(m.get_data().get_message_blob());
return cm;
} else if (m.get_type() == HBServerMessageType.SASL_MESSAGE_TOKEN) {
SaslMessageToken sm = SaslMessageToken.read(m.get_data().get_message_blob());
return sm;
} else {
return m;
}
}
use of org.apache.storm.generated.HBMessage in project storm by apache.
the class ThriftEncoder method encodeNettySerializable.
private HBMessage encodeNettySerializable(INettySerializable netty_message, HBServerMessageType mType) {
HBMessageData message_data = new HBMessageData();
HBMessage m = new HBMessage();
try {
ChannelBuffer cbuffer = netty_message.buffer();
if (cbuffer.hasArray()) {
message_data.set_message_blob(cbuffer.array());
} else {
byte[] buff = new byte[netty_message.encodeLength()];
cbuffer.readBytes(buff, 0, netty_message.encodeLength());
message_data.set_message_blob(buff);
}
m.set_type(mType);
m.set_data(message_data);
return m;
} catch (IOException e) {
LOG.error("Failed to encode NettySerializable: ", e);
throw new RuntimeException(e);
}
}
use of org.apache.storm.generated.HBMessage in project storm by apache.
the class Pacemaker method getPulse.
private HBMessage getPulse(String path, boolean authenticated) {
if (authenticated) {
byte[] details = heartbeats.get(path);
LOG.debug("Getting Pulse for path [ {} ]...data [ {} ].", path, details);
meterGetPulseCount.mark();
if (details != null) {
meterTotalSentSize.mark(details.length);
}
HBPulse hbPulse = new HBPulse();
hbPulse.set_id(path);
hbPulse.set_details(details);
return new HBMessage(HBServerMessageType.GET_PULSE_RESPONSE, HBMessageData.pulse(hbPulse));
} else {
return notAuthorized();
}
}
use of org.apache.storm.generated.HBMessage in project storm by apache.
the class Pacemaker method handleMessage.
@Override
public HBMessage handleMessage(HBMessage m, boolean authenticated) {
HBMessage response = null;
HBMessageData data = m.get_data();
switch(m.get_type()) {
case CREATE_PATH:
response = createPath(data.get_path());
break;
case EXISTS:
response = pathExists(data.get_path(), authenticated);
break;
case SEND_PULSE:
response = sendPulse(data.get_pulse());
break;
case GET_ALL_PULSE_FOR_PATH:
response = getAllPulseForPath(data.get_path(), authenticated);
break;
case GET_ALL_NODES_FOR_PATH:
response = getAllNodesForPath(data.get_path(), authenticated);
break;
case GET_PULSE:
response = getPulse(data.get_path(), authenticated);
break;
case DELETE_PATH:
response = deletePath(data.get_path());
break;
case DELETE_PULSE_ID:
response = deletePulseId(data.get_path());
break;
default:
LOG.info("Got Unexpected Type: {}", m.get_type());
break;
}
if (response != null)
response.set_message_id(m.get_message_id());
return response;
}
use of org.apache.storm.generated.HBMessage in project storm by apache.
the class PacemakerClient method send.
public HBMessage send(HBMessage m) throws PacemakerConnectionException {
LOG.debug("Sending message: {}", m.toString());
try {
int next = availableMessageSlots.take();
synchronized (m) {
m.set_message_id(next);
messages[next] = m;
LOG.debug("Put message in slot: {}", Integer.toString(next));
do {
waitUntilReady();
Channel channel = channelRef.get();
if (channel != null) {
channel.write(m);
m.wait(1000);
}
} while (messages[next] == m);
}
HBMessage ret = messages[next];
if (ret == null) {
// This can happen if we lost the connection and subsequently reconnected or timed out.
send(m);
}
messages[next] = null;
LOG.debug("Got Response: {}", ret);
return ret;
} catch (InterruptedException e) {
LOG.error("PacemakerClient send interrupted: ", e);
throw new RuntimeException(e);
}
}
Aggregations