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


Java Poller类代码示例

本文整理汇总了Java中org.zeromq.ZMQ.Poller的典型用法代码示例。如果您正苦于以下问题:Java Poller类的具体用法?Java Poller怎么用?Java Poller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: initZmq

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
protected void initZmq(int clientRequestPort, int workerResponsePort)
{
	Context zmqContext = ZMQ.context(1);
	clientSocket = zmqContext.socket(ZMQ.ROUTER);
	workerSocket = zmqContext.socket(ZMQ.ROUTER);

	clientSocket.setLinger(0);
	workerSocket.setLinger(0);

	clientSocket.setReceiveTimeOut(100);
	workerSocket.setReceiveTimeOut(100);

	clientSocket.bind("tcp://*:" + clientRequestPort);
	workerSocket.bind("tcp://*:" + workerResponsePort);

	poll = new Poller(2);
	poll.register(clientSocket, Poller.POLLIN);
	poll.register(workerSocket, Poller.POLLIN);

	logger.info("Zmq proxy binds to client port [" + clientRequestPort + "] and worker port ["
			+ workerResponsePort + "]");
}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:23,代码来源:ZmqProxy.java

示例2: ZmqResponder

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
/**
 * @param port
 * @param timeout
 */
public ZmqResponder(int port, Integer timeout)
{
	this.timeout = timeout == null ? -1 : timeout;
	context = ZMQ.context(1);
	// Socket to talk to server
	responder = context.socket(ZMQ.REP);
	responder.setLinger(0);
	String url = String.format("tcp://localhost:%d", port);
	responder.connect(url);
	poller = new Poller(1);
	poller.register(responder, Poller.POLLIN);
	if (timeout != null)
	{
		responder.setReceiveTimeOut(timeout);
		responder.setSendTimeOut(timeout);
	}
}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:22,代码来源:ZmqResponder.java

示例3: rebuild

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
private void rebuild() {
    pollact = null;

    pollSize = pollers.size();
    pollset = new Poller(pollSize);

    pollact = new SPoller[pollSize];

    int itemNbr = 0;
    for (SPoller poller : pollers) {
        pollset.register(poller.item);
        pollact[itemNbr] = poller;
        itemNbr++;
    }
    dirty = false;
}
 
开发者ID:zeromq,项目名称:jzmq3-x,代码行数:17,代码来源:ZLoop.java

示例4: testPollerUnregister

import org.zeromq.ZMQ.Poller; //导入依赖的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();
}
 
开发者ID:zeromq,项目名称:jzmq3-x,代码行数:20,代码来源:ZMQTest.java

示例5: rebuild

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
private void rebuild()
{
    pollact = null;

    pollSize = pollers.size();
    pollset = new Poller(pollSize);

    pollact = new SPoller[pollSize];

    int itemNbr = 0;
    for (SPoller poller : pollers) {
        pollset.register(poller.item);
        pollact[itemNbr] = poller;
        itemNbr++;
    }
    dirty = false;
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:18,代码来源:ZLoop.java

示例6: run

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
public void run() {
    ZContext ctx = new ZContext();
    Socket client = ctx.createSocket(ZMQ.DEALER);

    //  Set random identity to make tracing easier
    String identity = String.format("%04X-%04X", rand.nextInt(), rand.nextInt());
    client.setIdentity(identity.getBytes(ZMQ.CHARSET));
    client.connect("tcp://localhost:5570");

    PollItem[] items = new PollItem[] { new PollItem(client, Poller.POLLIN) };

    int requestNbr = 0;
    while (!Thread.currentThread().isInterrupted()) {
        //  Tick once per second, pulling in arriving messages
        for (int centitick = 0; centitick < 100; centitick++) {
            ZMQ.poll(items, 10);
            if (items[0].isReadable()) {
                ZMsg msg = ZMsg.recvMsg(client);
                msg.getLast().print(identity);
                msg.destroy();
            }
        }
        client.send(String.format("request #%d", ++requestNbr), 0);
    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:27,代码来源:asyncsrv.java

示例7: getSocket

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
private Socket getSocket() {
  if (socket == null) {
    socket = getZContext().createSocket(ZMQ.DEALER);
    socket.connect(host + ":" + port);
    getPoller().register(socket, Poller.POLLIN);
  }
  return socket;
}
 
开发者ID:alda-lang,项目名称:alda-client-java,代码行数:9,代码来源:AldaRequest.java

示例8: ServiceControlListener

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
public ServiceControlListener(ServiceController controller) throws ServiceException
{
	this.controller = controller;
	// init zmq
	zmqContext = ZMQ.context(1);
	router = initRouter();
	subscriber = initSubscriber();
	poller = new Poller(2);
	poller.register(router, Poller.POLLIN);
	poller.register(subscriber, Poller.POLLIN);
}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:12,代码来源:ServiceControlListener.java

示例9: initZmq

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
protected void initZmq(byte[] id, String uri, Integer timeout)
{
	this.timeout = timeout == null ? -1 : timeout;
	context = ZMQ.context(1);
	dealer = context.socket(ZMQ.DEALER);
	if (id != null)
	{
		dealer.setIdentity(id);
	}
	dealer.setLinger(0);
	dealer.connect(uri);
	poller = new Poller(1);
	poller.register(dealer, Poller.POLLIN);
}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:15,代码来源:ZmqDealer.java

示例10: ZmqRouter

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
/**
 * @param port
 * @param timeout
 */
public ZmqRouter(int port, Integer timeout)
{
	this.timeout = timeout == null ? -1 : timeout;
	String connect_str = String.format("tcp://*:%d", port);
	context = ZMQ.context(1);
	router = context.socket(ZMQ.ROUTER);
	router.setLinger(0);
	router.bind(connect_str);
	poller = new Poller(1);
	poller.register(router, Poller.POLLIN);
}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:16,代码来源:ZmqRouter.java

示例11: initZmq

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
/**
 * @param id
 * @param uri
 * @param timeout
 */
protected void initZmq(byte[] id, String uri, Integer timeout)
{
	this.timeout = timeout == null ? -1 : timeout;
	context = ZMQ.context(1);
	dealer = context.socket(ZMQ.DEALER);
	if (id != null)
	{
		dealer.setIdentity(id);
	}
	dealer.setLinger(0);
	dealer.connect(uri);
	poller = new Poller(1);
	poller.register(dealer, Poller.POLLIN);
}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:20,代码来源:ZmqDealer.java

示例12: ZmqSubscriber

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
/**
 * @param host
 * @param port
 * @param topic
 * @param timeout
 */
public ZmqSubscriber(String host, int port, String topic, Integer timeout)
{
	this.timeout = timeout == null ? -1 : timeout;
	String connect_str = String.format("tcp://%s:%d", host, port);
	context = ZMQ.context(1);
	sub = context.socket(ZMQ.SUB);
	sub.subscribe(topic.getBytes());
	sub.connect(connect_str);
	poller = new Poller(1);
	poller.register(sub, Poller.POLLIN);

}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:19,代码来源:ZmqSubscriber.java

示例13: ZmqPuller

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
/**
 * @param host
 * @param port
 * @param timeout
 */
public ZmqPuller(String host, int port, Integer timeout)
{
	this.timeout = timeout == null ? -1 : timeout;
	String connect_str = String.format("tcp://%s:%d", host, port);
	context = ZMQ.context(1);
	receiver = context.socket(ZMQ.PULL);
	receiver.connect(connect_str);
	poller = new Poller(1);
	poller.register(receiver, Poller.POLLIN);
}
 
开发者ID:MnAnX,项目名称:Infra,代码行数:16,代码来源:ZmqPuller.java

示例14: handleRequestMessage

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
protected Object handleRequestMessage(final Message<?> requestMessage) {
	if (!running) {
		return null;
	}
	
	Future<Object> response = executorService.submit(new Callable<Object>() {
		public Object call() throws Exception {
			byte[] requestData = requestConverter.convert(requestMessage.getPayload());
			int retriesLeft = retryCount;
			while (!Thread.currentThread().isInterrupted()) {
				socket.send(requestData);
				PollItem items[] = { new PollItem(socket, Poller.POLLIN) };
				int rc = ZMQ.poll(items, socketReceiveTimeout);
				if (rc == -1) {
					break;
				}
				if (items[0].isReadable()) {
					byte[] reply = socket.recv();
					return replyConverter.convert(reply);
				} else if (--retriesLeft == 0) {
					break;
				} else {
					ZmqLazyPirateGateway.this.connect();
				}
			}
			ZmqLazyPirateGateway.this.connect();
			return null;
		}
	});
			
	try {
		return response.get();
	} catch (Throwable t) {
		throw new MessageHandlingException(requestMessage, t);
	}
}
 
开发者ID:moonkev,项目名称:spring-integration-zmq,代码行数:37,代码来源:ZmqLazyPirateGateway.java

示例15: main

import org.zeromq.ZMQ.Poller; //导入依赖的package包/类
public static void main (String[] args)
{
    ZContext ctx = new ZContext ();

    //  Use the Zyre UDP class to make sure we listen on the same
    //  network interface as our peers
    ZreUdp udp = new ZreUdp (ZreInterface.PING_PORT_NUMBER);
    String host = udp.host ();
    Socket collector = ctx.createSocket (ZMQ.SUB);

    //  Bind to an ephemeral port
    int port = collector.bindToRandomPort (String.format ("tcp://%s", host));

    //  Announce this to all peers we connect to
    ZreInterface inf = new ZreInterface ();
    inf.setHeader ("X-ZRELOG", "tcp://%s:%d", host, port);

    //  Get all log messages (don't filter)
    collector.subscribe ("".getBytes ());

    Poller items = ctx.getContext ().poller ();
    
    items.register (collector, Poller.POLLIN);
    items.register (inf.handle (), Poller.POLLIN);
    
    while (!Thread.currentThread ().isInterrupted ()) {
        if (items.poll (1000) == -1)
            break;              //  Interrupted
        //  Handle input on collector
        if (items.pollin (0))
            printLogMsg (collector);

        //  Handle event from interface (ignore it)
        if (items.pollin (1)) {
            ZMsg msg = inf.recv ();
            if (msg == null)
                break;              //  Interrupted
            msg.destroy ();
        }
    }
    inf.destroy ();
    udp.destroy ();
    ctx.destroy ();

}
 
开发者ID:zeromq,项目名称:jyre,代码行数:46,代码来源:ZreLogger.java


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