/** * The ZMQ_LINGER option shall set the linger period for the specified socket. * The linger period determines how long pending messages which have yet to be sent to a peer * shall linger in memory after a socket is disconnected with disconnect or closed with close, * and further affects the termination of the socket's context with Ctx#term. * The following outlines the different behaviours: A value of -1 specifies an infinite linger period. * Pending messages shall not be discarded after a call to disconnect() or close(); * attempting to terminate the socket's context with Ctx#term() shall block until all pending messages have been sent to a peer. * The value of 0 specifies no linger period. Pending messages shall be discarded immediately after a call to disconnect() or close(). * Positive values specify an upper bound for the linger period in milliseconds. * Pending messages shall not be discarded after a call to disconnect() or close(); * attempting to terminate the socket's context with Ctx#term() shall block until either all pending messages have been sent to a peer, * or the linger period expires, after which any pending messages shall be discarded. * * @param value * the linger period in milliseconds. * @return true if the option was set, otherwise false * @deprecated the linger option has only integer range, use {@link #setLinger(int)} instead * @see #getLinger() */ @Deprecated public boolean setLinger(long value) { return setLinger(Long.valueOf(value).intValue()); }
/** * Destroys managed socket within this context * and remove from sockets list * @param s * org.zeromq.Socket object to destroy */ public void destroySocket(Socket s) { if (s == null) { return; } s.setLinger(linger); s.close(); try { mutex.lock(); this.sockets.remove(s); } finally { mutex.unlock(); } }
public void close(Socket socket) { try { logger.debug("close socket {}: {}", socket, socket); socket.setLinger(0); context.destroySocket(socket); } catch (ZMQException|zmq.ZError.IOException|zmq.ZError.CtxTerminatedException|zmq.ZError.InstantiationException e) { ZMQHelper.logZMQException(logger, "close " + socket, e); } catch (java.nio.channels.ClosedSelectorException e) { logger.debug("in close: " + e); } catch (Exception e) { logger.error("in close: " + e); } finally { } }
requester.setReceiveTimeOut(1000); requester.setSendTimeOut(1000); requester.setLinger(0); requester.connect(remoteContactPoint_META); if (requester.send(vsensor + "?tcp://" + laddress + ":" + lport)){
private JeroMqManager(final String name, final JeroMqConfiguration config) { super(null, name); publisher = CONTEXT.socket(ZMQ.PUB); publisher.setAffinity(config.affinity); publisher.setBacklog(config.backlog); publisher.setDelayAttachOnConnect(config.delayAttachOnConnect); if (config.identity != null) { publisher.setIdentity(config.identity); } publisher.setIPv4Only(config.ipv4Only); publisher.setLinger(config.linger); publisher.setMaxMsgSize(config.maxMsgSize); publisher.setRcvHWM(config.rcvHwm); publisher.setReceiveBufferSize(config.receiveBufferSize); publisher.setReceiveTimeOut(config.receiveTimeOut); publisher.setReconnectIVL(config.reconnectIVL); publisher.setReconnectIVLMax(config.reconnectIVLMax); publisher.setSendBufferSize(config.sendBufferSize); publisher.setSendTimeOut(config.sendTimeOut); publisher.setSndHWM(config.sndHwm); publisher.setTCPKeepAlive(config.tcpKeepAlive); publisher.setTCPKeepAliveCount(config.tcpKeepAliveCount); publisher.setTCPKeepAliveIdle(config.tcpKeepAliveIdle); publisher.setTCPKeepAliveInterval(config.tcpKeepAliveInterval); publisher.setXpubVerbose(config.xpubVerbose); for (final String endpoint : config.endpoints) { publisher.bind(endpoint); } LOGGER.debug("Created JeroMqManager with {}", config); }
/** * Configures a socket based on metadata. * * @param socket the socket * @param metadata the metadata */ public static void configure(ZMQ.Socket socket, ZeroMQMetadata metadata) { socket.setLinger(0); if (metadata.getHighWater() > -1) { socket.setHWM(metadata.getHighWater()); } else { socket.setHWM(1000); } if (metadata.getMulticastRate() > -1) { socket.setRate(metadata.getMulticastRate()); } if (metadata.getMulticastRecovery() > -1) { socket.setRecoveryInterval(metadata.getMulticastRecovery()); } if (metadata.getReceiveBuffer() > -1) { socket.setReceiveBufferSize(metadata.getReceiveBuffer()); } if (metadata.getSendBuffer() > -1) { socket.setSendBufferSize(metadata.getSendBuffer()); } } }
/** * Configures a socket based on metadata. * * @param socket the socket * @param metadata the metadata */ public static void configure(ZMQ.Socket socket, ZeroMQMetadata metadata) { socket.setLinger(0); if (metadata.getHighWater() > -1) { socket.setHWM(metadata.getHighWater()); } else { socket.setHWM(1000); } if (metadata.getMulticastRate() > -1) { socket.setRate(metadata.getMulticastRate()); } if (metadata.getMulticastRecovery() > -1) { socket.setRecoveryInterval(metadata.getMulticastRecovery()); } if (metadata.getReceiveBuffer() > -1) { socket.setReceiveBufferSize(metadata.getReceiveBuffer()); } if (metadata.getSendBuffer() > -1) { socket.setSendBufferSize(metadata.getSendBuffer()); } } }
@Override public DataField[] getOutputFormat() { if (structure == null){ requester = ctx.createSocket(ZMQ.REQ); requester.setReceiveTimeOut(1000); requester.setSendTimeOut(1000); requester.setLinger(0); requester.connect(remoteContactPoint_META); if (requester.send(vsensor + "?tcp://" + laddress + ":" + lport)){ byte[] rec = requester.recv(); if (rec != null){ structure = kryo.readObjectOrNull(new Input(new ByteArrayInputStream(rec)),DataField[].class); if (structure != null) requester.close(); return structure; } } requester.close(); } return structure; }
/** * A Topic handler that subscribes but has a publisher too. * @param paddress String. My TCP address for publishing. * @param addresses List. My TCP address and topics for listening. * @throws Exception */ public RTopic(String phandler, List<String> addresses) throws Exception { this(addresses); publisher = context.socket(ZMQ.PUB); publisher.bind(phandler); publisher.setIdentity("B".getBytes()); publisher.setLinger(5000); publisher.setHWM(0); }
public WebMQPublisher(String port, String topic, String message) throws Exception { String binding = "tcp://*:" + port; context = ZMQ.context(1); publisher = context.socket(ZMQ.PUB); publisher.bind(binding); Thread.sleep(1000); publisher.setIdentity("B".getBytes()); publisher.setLinger(5000); publisher.setHWM(0); publisher.sendMore(topic); boolean isSent = publisher.send(message); publisher.close(); context.term(); } }
public ZeroMQDeliveryAsync(String name){ if (name.endsWith(":")){ name = name.substring(0, name.length()-1); } this.name = name; context = Main.getZmqContext(); // Socket to talk to clients publisher = context.createSocket(ZMQ.PUB); publisher.setLinger(5000); publisher.setSndHWM(0); // no limit publisher.bind("inproc://stream/"+name); Main.getZmqProxy().connectTo(name); closed = false; }
public Publisher(String binding, String topicName) throws Exception { mapper.setSerializationInclusion(Include.NON_NULL); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); context = ZMQ.context(1); publisher = context.socket(ZMQ.PUB); publisher.bind(binding); Thread.sleep(100); //System.out.println("Starting Publisher.."); publisher.setIdentity("B".getBytes()); publisher.setLinger(5000); publisher.setHWM(0); this.topicName = topicName; }
public Socket[] getPair(String name) { String endPoint = "inproc://pair/" + name; Socket socket1 = newSocket(Method.BIND, Sockets.PAIR, endPoint); socket1.setLinger(0); socket1.setHWM(1); Socket socket2 = newSocket(Method.CONNECT, Sockets.PAIR, endPoint); socket2.setLinger(0); socket2.setHWM(1); return new Socket[] {socket1, socket2}; } }
public ZMQ.Socket createControlSocket() { ZMQ.Socket controlSocket = context.socket(ZMQ.SUB); controlSocket.setLinger(0); controlSocket.subscribe(EMPTY_BYTES); controlSocket.connect("inproc://fabric3"); return controlSocket; }
public static Socket set_linger(Socket socket, long linger_ms) { socket.setLinger(linger_ms); return socket; }