use of org.apache.storm.generated.HBMessage in project storm by apache.
the class PacemakerServer method received.
public void received(Object mesg, String remote, Channel channel) throws InterruptedException {
cleanPipeline(channel);
boolean authenticated = (authMethod == ThriftNettyServerCodec.AuthMethod.NONE) || authenticated_channels.contains(channel);
HBMessage m = (HBMessage) mesg;
LOG.debug("received message. Passing to handler. {} : {} : {}", handler.toString(), m.toString(), channel.toString());
HBMessage response = handler.handleMessage(m, authenticated);
if (response != null) {
LOG.debug("Got Response from handler: {}", response);
channel.write(response);
} else {
LOG.info("Got null response from handler handling message: {}", m);
}
}
use of org.apache.storm.generated.HBMessage in project storm by apache.
the class ThriftEncoder method encode.
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) {
if (msg == null) {
return null;
}
LOG.debug("Trying to encode: " + msg.getClass().toString() + " : " + msg.toString());
HBMessage m;
if (msg instanceof INettySerializable) {
INettySerializable nettyMsg = (INettySerializable) msg;
HBServerMessageType type;
if (msg instanceof ControlMessage) {
type = HBServerMessageType.CONTROL_MESSAGE;
} else if (msg instanceof SaslMessageToken) {
type = HBServerMessageType.SASL_MESSAGE_TOKEN;
} else {
LOG.error("Didn't recognise INettySerializable: " + nettyMsg.toString());
throw new RuntimeException("Unrecognized INettySerializable.");
}
m = encodeNettySerializable(nettyMsg, type);
} else {
m = (HBMessage) msg;
}
try {
byte[] serialized = Utils.thriftSerialize(m);
ChannelBuffer ret = ChannelBuffers.directBuffer(serialized.length + 4);
ret.writeInt(serialized.length);
ret.writeBytes(serialized);
return ret;
} catch (RuntimeException e) {
LOG.error("Failed to serialize.", e);
throw e;
}
}
use of org.apache.storm.generated.HBMessage 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();
}
}
use of org.apache.storm.generated.HBMessage in project storm by apache.
the class Pacemaker method pathExists.
private HBMessage pathExists(String path, boolean authenticated) {
HBMessage response = null;
if (authenticated) {
boolean itDoes = heartbeats.containsKey(path);
LOG.debug("Checking if path [ {} ] exists... {} .", path, itDoes);
response = new HBMessage(HBServerMessageType.EXISTS_RESPONSE, HBMessageData.boolval(itDoes));
} else {
response = notAuthorized();
}
return response;
}
use of org.apache.storm.generated.HBMessage in project storm by apache.
the class PacemakerClient method gotMessage.
public void gotMessage(HBMessage m) {
int message_id = m.get_message_id();
if (message_id >= 0 && message_id < maxPending) {
LOG.debug("Pacemaker client got message: {}", m.toString());
HBMessage request = messages[message_id];
if (request == null) {
LOG.debug("No message for slot: {}", Integer.toString(message_id));
} else {
synchronized (request) {
messages[message_id] = m;
request.notifyAll();
availableMessageSlots.add(message_id);
}
}
} else {
LOG.error("Got Message with bad id: {}", m.toString());
}
}
Aggregations