use of org.apache.storm.generated.HBMessageData 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.HBMessageData 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.HBMessageData in project storm by apache.
the class Pacemaker method getAllNodesForPath.
private HBMessage getAllNodesForPath(String path, boolean authenticated) {
LOG.debug("List all nodes for path {}", path);
if (authenticated) {
Set<String> pulseIds = new HashSet<>();
for (String key : heartbeats.keySet()) {
String[] replaceStr = key.replaceFirst(path, "").split("/");
String trimmed = null;
for (String str : replaceStr) {
if (!str.equals("")) {
trimmed = str;
break;
}
}
if (trimmed != null && key.indexOf(path) == 0) {
pulseIds.add(trimmed);
}
}
HBMessageData hbMessageData = HBMessageData.nodes(new HBNodes(new ArrayList(pulseIds)));
return new HBMessage(HBServerMessageType.GET_ALL_NODES_FOR_PATH_RESPONSE, hbMessageData);
} else {
return notAuthorized();
}
}
Aggregations