Search in sources :

Example 1 with FastBuildTree

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;
}
Also used : FastBuildTree(services.moleculer.util.FastBuildTree)

Example 2 with FastBuildTree

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;
}
Also used : FastBuildTree(services.moleculer.util.FastBuildTree) FastBuildTree(services.moleculer.util.FastBuildTree) Tree(io.datatree.Tree)

Example 3 with FastBuildTree

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);
}
Also used : FastBuildTree(services.moleculer.util.FastBuildTree)

Example 4 with FastBuildTree

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);
}
Also used : FastBuildTree(services.moleculer.util.FastBuildTree)

Example 5 with FastBuildTree

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);
}
Also used : FastBuildTree(services.moleculer.util.FastBuildTree)

Aggregations

FastBuildTree (services.moleculer.util.FastBuildTree)15 Tree (io.datatree.Tree)5 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 NodeDescriptor (services.moleculer.transporter.tcp.NodeDescriptor)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 CommonUtils.readTree (services.moleculer.util.CommonUtils.readTree)2 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 InetAddress (java.net.InetAddress)1 NetworkInterface (java.net.NetworkInterface)1 RemoteException (java.rmi.RemoteException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1