當前位置: 首頁>>代碼示例>>Java>>正文


Java ZMQ.proxy方法代碼示例

本文整理匯總了Java中org.zeromq.ZMQ.proxy方法的典型用法代碼示例。如果您正苦於以下問題:Java ZMQ.proxy方法的具體用法?Java ZMQ.proxy怎麽用?Java ZMQ.proxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.zeromq.ZMQ的用法示例。


在下文中一共展示了ZMQ.proxy方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.zeromq.ZMQ; //導入方法依賴的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

示例2: run

import org.zeromq.ZMQ; //導入方法依賴的package包/類
@Override
public void run() {
	ctx = new ZContext();

       frontend = ctx.createSocket(ZMQ.ROUTER);
       frontend.bind("tcp://*:5570");

       backend = ctx.createSocket(ZMQ.DEALER);
       backend.bind("inproc://backend");

       //  Launch pool of worker threads, precise number is not critical
       for (int threadNbr = 0; threadNbr < 2; threadNbr++) {
           new Thread(new JeroMQServerWorker(ctx)).start();
       }

       //  Connect backend to frontend via a proxy
       ZMQ.proxy(frontend, backend, null);


}
 
開發者ID:comdata,項目名稱:HomeAutomation,代碼行數:21,代碼來源:JeroMQServerThread.java

示例3: start

import org.zeromq.ZMQ; //導入方法依賴的package包/類
public synchronized void start() {
    Log.write("Starting service on " + this.port);
    this.context = ZMQ.context(1);
    this.internal = context.socket(ZMQ.DEALER);
    this.internal.bind(getInternalAddress());
    this.external = context.socket(ZMQ.ROUTER);
    this.external.bind(getExternalAddress());
    startWorkers();
    try {
        ZMQ.proxy(external, internal, null);
    } catch (ZError.IOException ex) {
        Throwable cause = ex.getCause();
        if (cause instanceof ClosedChannelException) {
            stop();
        } else {
            throw ex;
        }
    }
}
 
開發者ID:technige,項目名稱:zerograph,代碼行數:20,代碼來源:Service.java

示例4: run

import org.zeromq.ZMQ; //導入方法依賴的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();
}
 
開發者ID:opendaylight,項目名稱:fpc,代碼行數:32,代碼來源:ZMQNBIServerPool.java

示例5: run

import org.zeromq.ZMQ; //導入方法依賴的package包/類
/**
 * This is where ZeroMQ and MessagePack are implemented, and the long running process initialized to receive incoming
 * messages.
 * <p>
 * Upon executing the userland source code any action functions registered MUST be stored so they MAY be referenced
 * by either "request" or "response" in the case of Middleware, or by the specific action name in the case of a
 * Service. This reference SHOULD then be used to effectively route messages received by the SDK to their relevant
 * action function.
 */
public void run() {
    if (this.action != null) {
        Scanner in = new Scanner(System.in);
        String payload = in.next();
        try {
            S commandReply = processRequest(this.action, getSdkCommand(this.action, null, payload));
            System.out.print(serializer.serializeInJson(commandReply));
        } catch (Exception e) {
            Logger.log(e);
            runErrorCallback();
            try {
                System.out.print(serializer.serializeInJson(getErrorPayload(e)));
            } catch (JsonProcessingException e1) {
                Logger.log(e1);
                System.out.print("");
            }
        }
    } else {
        startSocket();

        setWorkers();

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                if (shutdownCallable != null) {
                    Component.this.runShutdown();
                }

                if (!stopped) {
                    Component.this.stopSocket();
                }
            }
        }));

        ZMQ.proxy(router, dealer, null);
    }
}
 
開發者ID:kusanagi,項目名稱:katana-sdk-java7,代碼行數:48,代碼來源:Component.java

示例6: run

import org.zeromq.ZMQ; //導入方法依賴的package包/類
public void run() {
    ZMQ.Socket middleendreceiver  = context.socket(ZMQ.SUB);
    middleendreceiver.connect("inproc://sender-middleend-"+ fid);
    middleendreceiver.subscribe("".getBytes()); //dummy topic.


    ZMQ.Socket backend  = context.socket(ZMQ.PUSH);
    backend.bind("tcp://*:" + port);

    ZMQ.proxy(middleendreceiver, backend, null);
}
 
開發者ID:usc-cloud,項目名稱:floe2,代碼行數:12,代碼來源:TestZMQ.java

示例7: run

import org.zeromq.ZMQ; //導入方法依賴的package包/類
@Override
public void run() {
    System.out.println("ZMQ: RUN CALLED");
    ZMQ.proxy(external, internal, null);
}
 
開發者ID:TinderBackend,項目名稱:neo4j-zmq-extension,代碼行數:6,代碼來源:ZmqKernelExtension.java

示例8: ZeroMQProxy

import org.zeromq.ZMQ; //導入方法依賴的package包/類
public ZeroMQProxy (final int portOUT,final int portMETA){
	kryo.register(DataField[].class);
	ctx = Main.getZmqContext();
	
	subscriberX = ctx.createSocket(ZMQ.XSUB);
    publisherX = ctx.createSocket(ZMQ.XPUB);
    publisherX.setXpubVerbose(true);
    publisherX.setHWM(0);
    subscriberX.setHWM(0);
    publisherX.bind("tcp://*:"+portOUT);
    
    clients = ctx.createSocket(ZMQ.REP);
    clients.bind ("tcp://*:"+portMETA);

    Thread dataProxy = new Thread(new Runnable(){

		@Override
		public void run() {
	           ZMQ.proxy(subscriberX, publisherX, null);
		}
    });
    dataProxy.setName("ZMQ-PROXY-Thread");
    dataProxy.start();
    
    Thread metaResponder =  new Thread(new Runnable(){
		@Override
		public void run() {
			while (true) {
				String request = clients.recvStr (0);
				String [] parts = request.split("\\?");
				if (parts.length > 1){
					try{
						long startTime = System.currentTimeMillis();
						if (parts.length > 2){
							startTime = Long.parseLong(parts[2]);
						}
						ZeroMQDeliverySync d = new ZeroMQDeliverySync(parts[0], parts[1]);
						final DefaultDistributionRequest  distributionReq = DefaultDistributionRequest.create(d, Mappings.getVSensorConfig(parts[0]), "select * from "+parts[0], startTime);
						logger.info("ZMQ request received: "+distributionReq.toString());
						DataDistributer.getInstance(d.getClass()).addListener(distributionReq);
					}catch (Exception e){
						logger.warn("ZMQ request parsing error: " + request, e);
					}
				}
				byte[] b=new byte[0];
				ByteArrayOutputStream bais = new ByteArrayOutputStream();
	            Output o = new Output(bais);
	            kryo.writeObjectOrNull(o,structures.get(parts[0]),DataField[].class);
	            o.close();
	            b = bais.toByteArray();
	            clients.send(b, 0);
			}
		}
	});
    metaResponder.setName("ZMQ-META-Thread");
       metaResponder.start();
}
 
開發者ID:LSIR,項目名稱:gsn,代碼行數:58,代碼來源:ZeroMQProxy.java


注:本文中的org.zeromq.ZMQ.proxy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。