本文整理汇总了Java中org.zeromq.ZMQ.Socket.setLinger方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.setLinger方法的具体用法?Java Socket.setLinger怎么用?Java Socket.setLinger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.zeromq.ZMQ.Socket
的用法示例。
在下文中一共展示了Socket.setLinger方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: destroySocket
import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
* 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;
if (sockets.contains(s)) {
try {
s.setLinger(linger);
} catch (ZMQException e) {
if (e.getErrorCode() != ZMQ.ETERM()) {
throw e;
}
}
s.close();
sockets.remove(s);
}
}
示例2: testPollerUnregister
import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Test
public void testPollerUnregister() {
Context context = ZMQ.context(1);
Socket socketOne = context.socket(ZMQ.SUB);
Socket socketTwo = context.socket(ZMQ.REP);
Poller poller = new ZMQ.Poller(2);
poller.register(socketOne, ZMQ.Poller.POLLIN);
poller.register(socketTwo, ZMQ.Poller.POLLIN);
socketOne.setLinger(0);
socketOne.close();
socketTwo.setLinger(0);
socketTwo.close();
poller.unregister(socketOne);
poller.unregister(socketTwo);
context.term();
}
示例3: connect
import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
protected Socket connect(final AbstractChannel channel)
{
final Socket zmqSocket = zmqContext.createSocket(channel.getZmqSocketType());
zmqSocket.setLinger(1000L);
zmqSocket.setReceiveTimeOut(receiveTimeoutMillis);
zmqSocket.connect(channel.getAddress());
channels.add(channel);
LOGGER.info("Connected channel: {} {}", channel.getClass().getSimpleName(), channel.getAddress());
return zmqSocket;
}
示例4: destroySocket
import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
* 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;
if (sockets.contains(s)) {
try {
s.setLinger(linger);
} catch (ZError.CtxTerminatedException e) {}
s.close();
sockets.remove(s);
}
}
示例5: buildZPipe
import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static List<Socket> buildZPipe(Context ctx) {
Socket socket1 = ctx.socket(ZMQ.PAIR);
socket1.setLinger(0);
socket1.setHWM(1);
Socket socket2 = ctx.socket(ZMQ.PAIR);
socket2.setLinger(0);
socket2.setHWM(1);
String iface = "inproc://" + new BigInteger(130, rand).toString(32);
socket1.bind(iface);
socket2.connect(iface);
return Arrays.asList(socket1, socket2);
}
示例6: main
import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void main (String[] args) {
Context context = ZMQ.context(1);
// Socket to talk to clients
Socket publisher = context.socket(ZMQ.PUB);
publisher.setLinger(5000);
// In 0MQ 3.x pub socket could drop messages if sub can follow the generation of pub messages
publisher.setSndHWM(0);
publisher.bind("tcp://*:5561");
// Socket to receive signals
Socket syncservice = context.socket(ZMQ.REP);
syncservice.bind("tcp://*:5562");
System.out.println("Waiting subscribers");
// Get synchronization from subscribers
int subscribers = 0;
while (subscribers < SUBSCRIBERS_EXPECTED) {
// - wait for synchronization request
syncservice.recv(0);
// - send synchronization reply
syncservice.send("", 0);
subscribers++;
}
// Now broadcast exactly 1M updates followed by END
System.out.println ("Broadcasting messages");
int update_nbr;
for (update_nbr = 0; update_nbr < 1000000; update_nbr++){
publisher.send("Rhubarb", 0);
}
publisher.send("END", 0);
// clean up
publisher.close();
syncservice.close();
context.term();
}
示例7: set_linger
import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static Socket set_linger(Socket socket, long linger_ms) {
socket.setLinger(linger_ms);
return socket;
}