当前位置: 首页>>代码示例>>Java>>正文


Java Context.term方法代码示例

本文整理汇总了Java中org.zeromq.ZMQ.Context.term方法的典型用法代码示例。如果您正苦于以下问题:Java Context.term方法的具体用法?Java Context.term怎么用?Java Context.term使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.zeromq.ZMQ.Context的用法示例。


在下文中一共展示了Context.term方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) {

        // Prepare our context and subscriber
        Context context = ZMQ.context(1);
        Socket subscriber = context.socket(ZMQ.SUB);

        subscriber.connect("tcp://localhost:5563");
        subscriber.subscribe("B".getBytes(ZMQ.CHARSET));
        while (!Thread.currentThread ().isInterrupted ()) {
            // Read envelope with address
            String address = subscriber.recvStr ();
            // Read message contents
            String contents = subscriber.recvStr ();
            System.out.println(address + " : " + contents);
        }
        subscriber.close ();
        context.term ();
    }
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:19,代码来源:psenvsub.java

示例2: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) {
    //  Prepare our context and sockets
    Context context = ZMQ.context(1);

    //  This is where the weather server sits
    Socket frontend =  context.socket(ZMQ.SUB);
    frontend.connect("tcp://192.168.55.210:5556");

    //  This is our public endpoint for subscribers
    Socket backend  = context.socket(ZMQ.PUB);
    backend.bind("tcp://10.1.1.0:8100");

    //  Subscribe on everything
    frontend.subscribe(ZMQ.SUBSCRIPTION_ALL);

    //  Run the proxy until the user interrupts us
    ZMQ.proxy (frontend, backend, null);

    frontend.close();
    backend.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:23,代码来源:wuproxy.java

示例3: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) throws Exception {
    // Prepare our context and publisher
    Context context = ZMQ.context(1);
    Socket publisher = context.socket(ZMQ.PUB);

    publisher.bind("tcp://*:5563");
    while (!Thread.currentThread ().isInterrupted ()) {
        // Write two messages, each with an envelope and content
        publisher.sendMore ("A");
        publisher.send ("We don't want to see this");
        publisher.sendMore ("B");
        publisher.send("We would like to see this");
    }
    publisher.close ();
    context.term ();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:17,代码来源:psenvpub.java

示例4: sendAsync

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
private static void sendAsync(int val, String account) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    Context context = ZMQ.context(1);

    //  Socket to talk to server
    Socket requester = context.socket(ZMQ.REQ);
    requester.connect("tcp://localhost:5559");
    System.out.println("launch and connect client.");
    ValidateRequest req = new ValidateRequest(account, new BigDecimal(val));

    //send request
    requester.send(objectMapper.writeValueAsString(req), 0);
    //receive response
    String responseStr = requester.recvStr(0);

    //parse and print reply
    ValidateResponse reply = objectMapper.readValue(responseStr, ValidateResponse.class);
    System.out.println("Received reply for request= " + req + " reply= " + reply + "");

    //  We never get here but clean up anyhow
    requester.close();
    context.term();
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:24,代码来源:TestAsyncMicroServiceMain.java

示例5: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) {
    //  Prepare our context and sockets
    Context context = ZMQ.context(1);

    //  Socket facing clients
    Socket frontend = context.socket(ZMQ.ROUTER);
    frontend.bind("tcp://*:5559");

    //  Socket facing services
    Socket backend = context.socket(ZMQ.DEALER);
    backend.bind("tcp://*:5560");

    //  Start the proxy
    ZMQ.proxy (frontend, backend, null);

    //  We never get here but clean up anyhow
    frontend.close();
    backend.close();
    context.term();
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:21,代码来源:ZeroMQBroker.java

示例6: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) throws InterruptedException {

        Context context = ZMQ.context(1);
        Socket sink = context.socket(ZMQ.ROUTER);
        sink.bind("inproc://example");

        //  First allow 0MQ to set the identity, [00] + random 4byte
        Socket anonymous = context.socket(ZMQ.REQ);

        anonymous.connect("inproc://example");
        anonymous.send ("ROUTER uses a generated UUID",0);
        ZHelper.dump (sink);

        //  Then set the identity ourself
        Socket identified = context.socket(ZMQ.REQ);
        identified.setIdentity("Hello".getBytes (ZMQ.CHARSET));
        identified.connect ("inproc://example");
        identified.send("ROUTER socket uses REQ's socket identity", 0);
        ZHelper.dump (sink);

        sink.close ();
        anonymous.close ();
        identified.close();
        context.term();

    }
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:27,代码来源:identity.java

示例7: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) {
    Context context = ZMQ.context(1);

    //  Socket to talk to server
    Socket requester = context.socket(ZMQ.REQ);
    requester.connect("tcp://localhost:5559");
    
    System.out.println("launch and connect client.");

    for (int request_nbr = 0; request_nbr < 10; request_nbr++) {
        requester.send("Hello", 0);
        String reply = requester.recvStr (0);
        System.out.println("Received reply " + request_nbr + " [" + reply + "]");
    }
    
    //  We never get here but clean up anyhow
    requester.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:20,代码来源:rrclient.java

示例8: run

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public void run()
{
    Context context = ZMQ.context(1);

    //  Prepare our context and sockets
    Socket client  = context.socket(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);

    client.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:19,代码来源:lbbroker.java

示例9: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) {

        Context context = ZMQ.context(1);
    
        //  Bind to inproc: endpoint, then start upstream thread
        Socket receiver = context.socket(ZMQ.PAIR);
        receiver.bind("inproc://step3");
        
        //  Step 2 relays the signal to step 3
        Thread step2 = new Step2 (context);
        step2.start();
        
        //  Wait for signal
        receiver.recv(0);
        receiver.close ();
    
        System.out.println ("Test successful!");
        context.term ();
    }
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:20,代码来源:mtrelay.java

示例10: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) {
    Context context = ZMQ.context(1);

    //  First, connect our subscriber socket
    Socket subscriber = context.socket(ZMQ.SUB);
    subscriber.connect("tcp://localhost:5561");
    subscriber.subscribe(ZMQ.SUBSCRIPTION_ALL);

    //  Second, synchronize with publisher
    Socket syncclient = context.socket(ZMQ.REQ);
    syncclient.connect("tcp://localhost:5562");

    //  - send a synchronization request
    syncclient.send(ZMQ.MESSAGE_SEPARATOR, 0);

    //  - wait for synchronization reply
    syncclient.recv(0);

    //  Third, get our updates and report how many we got
    int update_nbr = 0;
    while (true) {
        String string = subscriber.recvStr(0);
        if (string.equals("END")) {
            break;
        }
        update_nbr++;
    }
    System.out.println("Received " + update_nbr + " updates.");

    subscriber.close();
    syncclient.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:34,代码来源:syncsub.java

示例11: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
public static void main (String[] args) throws Exception {
    Context context = ZMQ.context (1);

    //  Socket to talk to server
    Socket responder = context.socket (ZMQ.REP);
    responder.connect ("tcp://localhost:5560");

    while (!Thread.currentThread ().isInterrupted ()) {
        //  Wait for next request from client
        String string = responder.recvStr (0);
        System.out.printf ("Received request: [%s]\n", string);

        //  Do some 'work'
        Thread.sleep (1000);

        //  Send reply back to client
        responder.send ("World");
    }

    //  We never get here but clean up anyhow
    responder.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:24,代码来源:rrworker.java

示例12: main

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
/**
 * Send a string using ZMQ. The program has been originally used for sending control messages in Idommar.
 * @param args
 */
public static void main(String[] args) throws Exception {

	if ( args.length < 2 ) {
		System.out.println("missing parameters");
		return;
	}

	try {
		// read the command line arguments and create a ZMQ context.
		String address = args[0];
		String command = args[1];
		Context context = ZMQ.context(1);
		Socket controlSocket = context.socket(ZMQ.REQ);
		//System.out.println("ALGO: ZMQ created context");
		
		// configure the ZMQ connection
		controlSocket.setReceiveTimeOut(10000);
		controlSocket.connect(address);
		
		// send the command
		controlSocket.send(command);
		//System.out.println("ZMQ connected to socket");
		
		// close the socket and terminate the context.
		controlSocket.close();
		context.term();
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(0);
	}
}
 
开发者ID:jasjisdo,项目名称:spark-newsreel-recommender,代码行数:36,代码来源:StringSender.java

示例13: execute

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
@Override
public void execute(ServiceContext serviceContext) throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    Context context = ZMQ.context(1);

    //  Socket to talk to server
    Socket responder = context.socket(ZMQ.REP);
    responder.connect(zeroMqBrokerAddress);
    ZMQ.PollItem items[] = {new ZMQ.PollItem(responder, ZMQ.Poller.POLLIN)};
    while (!Thread.currentThread().isInterrupted() && !serviceContext.isCancelled()) {
        //  Wait for next request from client
        int rc = ZMQ.poll(items, 1000);
        if (rc == -1) {
            continue;
        }

        if (items[0].isReadable()) {
            String reqStr = responder.recvStr(0);
            System.out.printf("Received request: [%s]\n", reqStr);

            ValidateRequest req = objectMapper.readValue(reqStr, ValidateRequest.class);

            ValidateResponse result = validateOperation(req.getAccount(), req.getSum());
            System.out.printf("send response request: [%s]\n", result);

            responder.send(objectMapper.writeValueAsString(result));
        }
    }
    System.out.println("Stop async read!");

    //  We never get here but clean up anyhow
    responder.close();
    context.term();

}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:36,代码来源:AsyncBankServiceImpl.java

示例14: testProxy

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
@Test
public void testProxy() throws Exception {

    if (ZMQ.getFullVersion() < ZMQ.make_version(3, 2, 2)) {
        // Can only test zmq_proxy on ZMQ >= of 3.2.2
        return;
    }

    Context ctx = ZMQ.context(1);
    assert (ctx != null);

    Main mt = new Main(ctx);
    mt.start();
    new Dealer(ctx, "AA").start();
    new Dealer(ctx, "BB").start();

    Thread.sleep(1000);
    Thread c1 = new Client(ctx, "X");
    c1.start();

    Thread c2 = new Client(ctx, "Y");
    c2.start();

    c1.join();
    c2.join();

    ctx.term();
}
 
开发者ID:zeromq,项目名称:jzmq3-x,代码行数:29,代码来源:ZMQTest.java

示例15: run

import org.zeromq.ZMQ.Context; //导入方法依赖的package包/类
@Override
public void run() {

    Context context = ZMQ.context(1);
    Socket worker = context.socket(ZMQ.DEALER);
    ZHelper.setId (worker);  //  Set a printable identity

    worker.connect("tcp://localhost:5671");

    int total = 0;
    while (true) {
        //  Tell the broker we're ready for work
        worker.sendMore ("");
        worker.send ("Hi Boss");

        //  Get workload from broker, until finished
        worker.recvStr ();   //  Envelope delimiter
        String workload = worker.recvStr ();
        boolean finished = workload.equals ("Fired!");
        if (finished) {
            System.out.printf ("Completed: %d tasks\n", total);
            break;
        }
        total++;

        //  Do some random work
        try {
            Thread.sleep (rand.nextInt (500) + 1);
        } catch (InterruptedException e) {
        }
    }
    worker.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:35,代码来源:rtdealer.java


注:本文中的org.zeromq.ZMQ.Context.term方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。