本文整理汇总了Java中org.zeromq.ZContext.destroy方法的典型用法代码示例。如果您正苦于以下问题:Java ZContext.destroy方法的具体用法?Java ZContext.destroy怎么用?Java ZContext.destroy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.zeromq.ZContext
的用法示例。
在下文中一共展示了ZContext.destroy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.zeromq.ZContext; //导入方法依赖的package包/类
public static void main(String[] args)
{
ZContext context = new ZContext();
Socket subscriber = context.createSocket(ZMQ.SUB);
if (args.length == 1)
subscriber.connect(args[0]);
else
subscriber.connect("tcp://localhost:5556");
Random rand = new Random(System.currentTimeMillis());
String subscription = String.format("%03d", rand.nextInt(1000));
subscriber.subscribe(subscription.getBytes(ZMQ.CHARSET));
while (true) {
String topic = subscriber.recvStr();
if (topic == null)
break;
String data = subscriber.recvStr();
assert(topic.equals(subscription));
System.out.println(data);
}
context.destroy();
}
示例2: run
import org.zeromq.ZContext; //导入方法依赖的package包/类
public void run() {
ZContext ctx = new ZContext();
Socket subscriber = ctx.createSocket(ZMQ.SUB);
subscriber.connect("tcp://localhost:5556");
subscriber.subscribe(ZMQ.SUBSCRIPTION_ALL);
while (true) {
kvsimple kvMsg = kvsimple.recv(subscriber);
if (kvMsg == null)
break;
clonecli1.kvMap.put(kvMsg.getKey(), kvMsg);
System.out.println("receiving " + kvMsg);
sequence.incrementAndGet();
}
ctx.destroy();
}
示例3: main
import org.zeromq.ZContext; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main( String[] args )
{
final ZContext ctx = new ZContext();
final Socket client = ctx.createSocket( ZMQ.PAIR );
//client.connect( "ipc:///tmp/zmqtest" );
client.connect( "tcp://localhost:5556" );
String msg = "";
for ( int i = 0; i < 10; ++i )
{
client.send( "Hello " + i );
}
client.send( "exit" );
ctx.destroy();
}
示例4: main
import org.zeromq.ZContext; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main( String[] args )
{
final ZContext ctx = new ZContext();
final Socket server = ctx.createSocket( ZMQ.PAIR );
server.bind( "ipc:///tmp/zmqtest" );
// server.bind( "tcp://*:5556" );
System.out.println( "bind complete" );
String msg = "";
while ( !msg.equals( "exit" ) )
{
msg = server.recvStr();
System.out.println( msg );
}
ctx.destroy();
}
示例5: run
import org.zeromq.ZContext; //导入方法依赖的package包/类
@Override
public void run() {
context = new ZContext();
clientSocket = context.createSocket(ZMQ.PAIR);
try {
clientSocket.bind("tcp://*:" + incomingPort);
logger.info("ComputationalServer UP");
while (!Thread.currentThread().isInterrupted())
receiveRequest();
} catch (Exception e) {
e.printStackTrace();
} finally {
context.destroy();
logger.info("ComputationalServer DOWN");
}
}
示例6: handShake
import org.zeromq.ZContext; //导入方法依赖的package包/类
public void handShake() throws Exception {
context = new ZContext();
Socket server = context.createSocket(ZMQ.REQ);
server.connect(connectionString);
server.send(request.toMsg());
String reply = new String(server.recv());
context.destroy();
if (reply.startsWith("ERROR"))
throw new Exception(reply);
String[] parts = reply.split(" ");
port = Integer.parseInt(parts[0]);
recordsHint = Integer.parseInt(parts[1]);
}
示例7: run
import org.zeromq.ZContext; //导入方法依赖的package包/类
@Override
public void run()
{
ZContext ctx = new ZContext();
Socket client = ctx.createSocket(ZMQ.REQ);
client.connect(String.format("ipc://%s-localfe.ipc", self));
while (true) {
// Send request, get reply
client.send("HELLO", 0);
String reply = client.recvStr(0);
if (reply == null)
break; // Interrupted
System.out.printf("Client: %s\n", reply);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
ctx.destroy();
}
示例8: run
import org.zeromq.ZContext; //导入方法依赖的package包/类
public void run() {
ZContext ctx = new ZContext();
// Frontend socket talks to clients over TCP
Socket frontend = ctx.createSocket(ZMQ.ROUTER);
frontend.bind("tcp://*:5570");
// Backend socket talks to workers over inproc
Socket backend = ctx.createSocket(ZMQ.DEALER);
backend.bind("inproc://backend");
// Launch pool of worker threads, precise number is not critical
for (int threadNbr = 0; threadNbr < 5; threadNbr++)
new Thread(new server_worker(ctx)).start();
// Connect backend to frontend via a proxy
ZMQ.proxy(frontend, backend, null);
ctx.destroy();
}
示例9: main
import org.zeromq.ZContext; //导入方法依赖的package包/类
public static void main(String[] args)
{
if (args.length < 1) {
System.out.printf("I: syntax: flserver1 <endpoint>\n");
System.exit(0);
}
ZContext ctx = new ZContext();
Socket server = ctx.createSocket(ZMQ.REP);
server.bind(args[0]);
System.out.printf ("I: echo service is ready at %s\n", args[0]);
while (true) {
ZMsg msg = ZMsg.recvMsg(server);
if (msg == null)
break; // Interrupted
msg.send(server);
}
if (Thread.currentThread().isInterrupted())
System.out.printf ("W: interrupted\n");
ctx.destroy();
}
示例10: run
import org.zeromq.ZContext; //导入方法依赖的package包/类
public void run()
{
ZContext context = new ZContext();
// Prepare our context and sockets
Socket worker = context.createSocket(ZMQ.REQ);
worker.connect("ipc://backend.ipc");
ZFrame frame = new ZFrame(lruqueue3.LRU_READY);
// Tell backend we're ready for work
frame.send(worker, 0);
while (true) {
ZMsg msg = ZMsg.recvMsg(worker);
if (msg == null)
break;
msg.getLast().reset("OK".getBytes(ZMQ.CHARSET));
msg.send(worker);
System.out.println(Thread.currentThread().getName() + " Worker Sent OK");
}
context.destroy();
}
示例11: run
import org.zeromq.ZContext; //导入方法依赖的package包/类
@Override
public void run (Object ... args)
{
ZContext context = new ZContext();
// Prepare our context and sockets
Socket client = context.createSocket (ZMQ.REQ);
ZHelper.setId (client); // Set a printable identity
client.connect("ipc://frontend.ipc");
// Send request, get reply
client.send("HELLO");
String reply = client.recvStr ();
System.out.println("Client: " + reply);
context.destroy ();
}
示例12: main
import org.zeromq.ZContext; //导入方法依赖的package包/类
public static void main(String[] argv)
{
// Start child threads
ZContext ctx = new ZContext();
ZThread.fork(ctx, new Publisher());
ZThread.fork(ctx, new Subscriber());
Socket subscriber = ctx.createSocket(ZMQ.XSUB);
subscriber.connect("tcp://localhost:6000");
Socket publisher = ctx.createSocket(ZMQ.XPUB);
publisher.bind("tcp://*:6001");
Socket listener = ZThread.fork(ctx, new Listener());
ZMQ.proxy (subscriber, publisher, listener);
System.out.println(" interrupted");
// Tell attached threads to exit
ctx.destroy();
}
示例13: run
import org.zeromq.ZContext; //导入方法依赖的package包/类
@Override
public void run() {
ZContext ctx = new ZContext();
// Frontend socket talks to clients over TCP
Socket frontend = ctx.createSocket(ZMQ.ROUTER);
frontend.bind("tcp://*:5570");
// Backend socket talks to workers over inproc
Socket backend = ctx.createSocket(ZMQ.DEALER);
backend.bind("inproc://backend");
// Launch pool of worker threads, precise number is not critical
for (int threadNbr = 0; threadNbr < requestHanlderPoolSize; threadNbr++) {
try {
new Thread(new server_worker(ctx)).start();
} catch (Exception e) {
// Does nothing as a warning was already issued.
}
}
// Connect backend to frontend via a proxy
ZMQ.proxy(frontend, backend, null);
LOG.info("ZMQNBIServerPool - Exiting MAIN server thread");
frontend.unbind("tcp://*:5570");
backend.unbind("inproc://backend");
ctx.destroySocket(frontend);
ctx.destroySocket(backend);
ctx.destroy();
}
示例14: run
import org.zeromq.ZContext; //导入方法依赖的package包/类
@Override
public void run() {
context = new ZContext();
Socket killerSocket = context.createSocket(ZMQ.PAIR);
killerSocket.bind(killerSocketString);
// wait for the job to be completed
killerSocket.recv();
kill();
context.destroy();
}
示例15: done
import org.zeromq.ZContext; //导入方法依赖的package包/类
public void done() {
context = new ZContext();
Socket server = context.createSocket(ZMQ.REQ);
server.connect(connectionString);
server.send("DONE " + port);
server.recv(); // ACK
context.destroy();
}