System.out.println ("E: protocol error");
}
private void controlMessage ()
{
ZMsg msg = ZMsg.recvMsg (pipe);
String method = msg.popString ();
if (method.equals ("SUBSCRIBE")) {
String path = msg.popString ();
// Store subscription along with any previous ones
// Check we don't already have a subscription for this path
for (Sub sub: subs) {
if (path.equals (sub.path))
return;
}
// Subscription path must start with '/'
// We'll do better error handling later
assert (path.startsWith ("/"));
// New subscription, store it for later replay
String inbox = config.resolve ("client/inbox", ".inbox");
sub = new Sub (this, inbox, path);
subs.add (sub);
}
else
if (method.equals ("SET INBOX")) {
String path = msg.popString ();
config.setPath ("client/inbox", path);
}
else
if (method.equals ("SET RESYNC")) {
long enabled = Long.parseLong (msg.popString ());
// Request resynchronization from server
config.setPath ("client/resync", enabled > 0 ? "1" :"0");
}
else
if (method.equals ("CONFIG")) {
String config_file = msg.popString ();
config.destroy ();
config = FmqConfig.load (config_file);
if (config != null)
applyConfig ();
else {
System.out.printf ("E: cannot load config file '%s'\n", config_file);
config = new FmqConfig ("root", null);
}
}
else
if (method.equals ("SETOPTION")) {
String path = msg.popString ();
String value = msg.popString ();
config.setPath (path, value);
config ();
}
else
if (method.equals ("STOP")) {
pipe.send ("OK");
stopped = true;
}
else
if (method.equals ("CONNECT")) {
String endpoint = msg.popString ();
if (nbrServers < MAX_SERVERS) {
Server server = new Server (ctx, endpoint);
servers [nbrServers++] = server;
dirty = true;
serverExecute (server, Event.initialize_event);
} else
System.out.printf ("E: too many server connections (max %d)\n", MAX_SERVERS);
}
msg.destroy ();
}