public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { String name = args[0].val(); String endpoint = args[1].val(); int type = ZMQ.SUB; if (args.length == 3) { String stype = args[2].val().toUpperCase(); if (!"PUB".equals(stype) && !"SUB".equals(stype)) { throw new ConfigRuntimeException( "You must specify PUB or SUB" + " for comm_disconnect's third argument!", Exceptions.ExceptionType.NotFoundException, t); } if ("PUB".equals(stype)) { type = ZMQ.PUB; } } NodePoint node; try { if (type == ZMQ.PUB) { node = Tracking.getPub(name); } else { node = Tracking.getSub(name); } } catch (InvalidNameException ex) { throw new ConfigRuntimeException( "Invalid name " + name + " given to comm_disconnect!", Exceptions.ExceptionType.FormatException, t); } if (node == null) { throw new ConfigRuntimeException( "Unknown " + name + " " + " given to comm_disconnect!", Exceptions.ExceptionType.NotFoundException, t); } try { node.disconnect(endpoint); } catch (ZMQException e) { throw new ConfigRuntimeException( "Exception while disconnecting: " + e.getMessage(), Exceptions.ExceptionType.IOException, t); } return CNull.NULL; }
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { String name = args[0].val(); String endpoint = args[1].val(); int type = ZMQ.PUB; if (args.length == 3) { String stype = args[2].val().toUpperCase(); if (!"PUB".equals(stype) && !"SUB".equals(stype)) { throw new ConfigRuntimeException( "You must specify PUB or SUB" + " for comm_listen's third argument!", Exceptions.ExceptionType.NotFoundException, t); } if ("SUB".equals(stype)) { type = ZMQ.SUB; } } NodePoint node; DaemonManager daemon = environment.getEnv(GlobalEnv.class).GetDaemonManager(); try { node = Tracking.getOrCreate(daemon, type, name); } catch (InvalidNameException ex) { throw new ConfigRuntimeException( "Invalid name " + name + " given to comm_listen!", Exceptions.ExceptionType.FormatException, t); } try { node.listen(endpoint); } catch (ZMQException e) { throw new ConfigRuntimeException( "Exception while listening: " + e.getMessage(), Exceptions.ExceptionType.IOException, t); } return CNull.NULL; }
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { String name = args[0].val(); String channel = args[1].val(); String message = args[2].val(); String origpub = name; if (args.length == 4) { origpub = args[3].val(); } NodePoint node; try { node = Tracking.getPub(name); if (node == null) { throw new ConfigRuntimeException( "Unknown PUB " + name + " given to comm_publish!", Exceptions.ExceptionType.NotFoundException, t); } ((Publisher) node).publish(channel, message, origpub); } catch (InvalidChannelException ex) { throw new ConfigRuntimeException( "Invalid channel " + channel + " given to comm_publish!", Exceptions.ExceptionType.FormatException, t); } catch (InvalidNameException ex) { throw new ConfigRuntimeException( "Invalid name " + name + " given to comm_publish!", Exceptions.ExceptionType.FormatException, t); } catch (ZMQException e) { throw new ConfigRuntimeException( "Exception while publishing: " + e.getMessage(), Exceptions.ExceptionType.IOException, t); } return CNull.NULL; }
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { String name = args[0].val(); int type = ZMQ.SUB; if (args.length == 2) { String stype = args[1].val().toUpperCase(); if (!"PUB".equals(stype) && !"SUB".equals(stype)) { throw new ConfigRuntimeException( "You must specify PUB or SUB" + " for comm_close's second argument!", Exceptions.ExceptionType.NotFoundException, t); } if ("PUB".equals(stype)) { type = ZMQ.PUB; } } boolean found; try { found = Tracking.close(name, type); } catch (InvalidNameException ex) { throw new ConfigRuntimeException( "Invalid name " + name + " given to comm_close!", Exceptions.ExceptionType.FormatException, t); } catch (ZMQException e) { throw new ConfigRuntimeException( "Exception while closing: " + e.getMessage(), Exceptions.ExceptionType.IOException, t); } if (!found) { throw new ConfigRuntimeException( "Unknown " + name + " " + " given to comm_close!", Exceptions.ExceptionType.NotFoundException, t); } return CNull.NULL; }
@Override protected void run() throws Exception { while (!Thread.currentThread().isInterrupted() && isRunning()) { byte[] message = "".getBytes(); poller.poll(200); if (poller.pollin(0)) { try { message = listener.recv(0); } catch (ZMQException e) { if (e.getErrorCode() == ZMQ.Error.ETERM.getCode()) { break; } } log.info("hi: {}", message); String response = "World"; listener.send(response.getBytes(), 0); } } }
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { String name = args[0].val(); String channel = args[1].val(); NodePoint node; try { node = Tracking.getSub(name); } catch (com.entityreborn.communication.Exceptions.InvalidNameException ex) { throw new ConfigRuntimeException( "Invalid name " + name + " given to comm_unsubscribe!", Exceptions.ExceptionType.FormatException, t); } if (node == null) { throw new ConfigRuntimeException( "Unknown SUB " + name + " given to comm_unsubscribe!", Exceptions.ExceptionType.NotFoundException, t); } try { ((Subscriber) node).unsubscribe(channel); } catch (InvalidChannelException ex) { throw new ConfigRuntimeException( "Invalid channel " + channel + " given to comm_subscribe!", Exceptions.ExceptionType.FormatException, t); } catch (ZMQException e) { throw new ConfigRuntimeException( "Exception while unsubscribing: " + e.getMessage(), Exceptions.ExceptionType.IOException, t); } return CNull.NULL; }