![JAR search and dependency download from the Maven repository](/logo.png)
io.nextop.client.MessageControl Maven / Gradle / Ivy
package io.nextop.client;
import io.nextop.Message;
import io.nextop.Route;
import io.nextop.WireValue;
import java.util.HashMap;
import java.util.Map;
public final class MessageControl {
public static enum Direction {
SEND,
RECEIVE
}
public static enum Type {
// FIXME
// SUBSCRIBE, // <->
// UNSUBSCRIBE, // <->
MESSAGE,
ERROR,
COMPLETE
}
public static MessageControl send(Message message) {
return send(Type.MESSAGE, message);
}
public static MessageControl send(Type type, Route route) {
Message spec = Message.newBuilder().setRoute(route).build();
return send(type, spec);
}
public static MessageControl send(Type type, Message message) {
return create(Direction.SEND, type, message);
}
public static MessageControl receive(Message message) {
return receive(Type.MESSAGE, message);
}
public static MessageControl receive(Type type, Route route) {
Message spec = Message.newBuilder().setRoute(route).build();
return receive(type, spec);
}
public static MessageControl receive(Type type, Message message) {
return create(Direction.RECEIVE, type, message);
}
public static MessageControl create(Direction dir, Type type, Message message) {
if (null == dir) {
throw new IllegalArgumentException();
}
if (null == type) {
throw new IllegalArgumentException();
}
if (null == message) {
throw new IllegalArgumentException();
}
return new MessageControl(dir, type, message);
}
/////// SERIALIZATION ///////
private static final int S_VERSION = 1;
private static final String S_KEY_VERSION = "version";
private static final String S_KEY_DIR = "dir";
private static final String S_KEY_TYPE = "type";
private static final String S_KEY_MESSAGE = "message";
public static WireValue toWireValue(MessageControl mc) {
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy