use of services.moleculer.util.FastBuildTree in project moleculer-java by moleculer-java.
the class Transporter method createPingPacket.
// --- PING PACKET ---
public Tree createPingPacket(String id) {
FastBuildTree msg = new FastBuildTree(4);
msg.putUnsafe("ver", ServiceBroker.PROTOCOL_VERSION);
msg.putUnsafe("sender", nodeID);
msg.putUnsafe("id", id);
msg.putUnsafe("time", System.currentTimeMillis());
return msg;
}
use of services.moleculer.util.FastBuildTree in project moleculer-java by moleculer-java.
the class Transporter method createRequestPacket.
// --- REQUEST PACKET ---
public Tree createRequestPacket(Context ctx) {
FastBuildTree msg = new FastBuildTree(7);
// Add basic properties
msg.putUnsafe("ver", ServiceBroker.PROTOCOL_VERSION);
msg.putUnsafe("sender", nodeID);
msg.putUnsafe("id", ctx.id);
msg.putUnsafe("action", ctx.name);
// Add params and meta
if (ctx.params != null) {
msg.putUnsafe("params", ctx.params.asObject());
Tree meta = ctx.params.getMeta(false);
if (meta != null) {
msg.putUnsafe("meta", meta.asObject());
}
}
// Add opts
if (ctx.opts != null) {
msg.putUnsafe("timeout", ctx.opts.timeout);
}
// Return message
return msg;
}
use of services.moleculer.util.FastBuildTree in project moleculer-java by moleculer-java.
the class Transporter method sendPongPacket.
protected void sendPongPacket(String sender, Tree ping) {
String id = ping.get("id", "");
if (id == null || id.isEmpty()) {
return;
}
long time = ping.get("time", 0L);
FastBuildTree msg = new FastBuildTree(5);
msg.putUnsafe("ver", PROTOCOL_VERSION);
msg.putUnsafe("sender", this.nodeID);
msg.putUnsafe("id", id);
msg.putUnsafe("received", time);
msg.putUnsafe("time", System.currentTimeMillis());
publish(channel(pongChannel, sender), msg);
}
use of services.moleculer.util.FastBuildTree in project moleculer-java by moleculer-java.
the class Transporter method sendDiscoverPacket.
// --- GENERIC MOLECULER PACKETS ---
protected void sendDiscoverPacket(String channel) {
FastBuildTree msg = new FastBuildTree(2);
msg.putUnsafe("ver", PROTOCOL_VERSION);
msg.putUnsafe("sender", nodeID);
publish(channel, msg);
}
use of services.moleculer.util.FastBuildTree in project moleculer-java by moleculer-java.
the class RemoteListenerEndpoint method on.
// --- INVOKE REMOTE LISTENER ---
@Override
public void on(String name, Tree payload, Groups groups, boolean broadcast) throws Exception {
FastBuildTree msg = new FastBuildTree(6);
msg.putUnsafe("ver", ServiceBroker.PROTOCOL_VERSION);
msg.putUnsafe("sender", nodeID);
msg.putUnsafe("event", name);
msg.putUnsafe("broadcast", broadcast);
if (groups != null) {
String[] array = groups.groups();
if (array != null && array.length > 0) {
msg.putUnsafe("groups", array);
}
}
if (payload != null) {
msg.putUnsafe("data", payload);
}
transporter.publish(PACKET_EVENT, nodeID, msg);
}
Aggregations