gpt4 book ai didi

org.zeromq.ZContext.createSocket()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 00:48:49 29 4
gpt4 key购买 nike

本文整理了Java中org.zeromq.ZContext.createSocket()方法的一些代码示例,展示了ZContext.createSocket()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZContext.createSocket()方法的具体详情如下:
包路径:org.zeromq.ZContext
类名称:ZContext
方法名:createSocket

ZContext.createSocket介绍

[英]Creates a new managed socket within this ZContext instance. Use this to get automatic management of the socket at shutdown
[中]在此ZContext实例中创建新的托管套接字。使用此选项可以在关机时自动管理插座

代码示例

代码示例来源:origin: org.zeromq/jeromq

@Override
public List<Socket> createSockets(ZContext ctx, Object... args)
{
  //create replies pipe that will forward replies to user
  replies = ctx.createSocket(ZMQ.PAIR);
  assert (replies != null);
  //create ZAP handler and get ready for requests
  Socket handler = ctx.createSocket(ZMQ.REP);
  assert (handler != null);
  return Arrays.asList(handler, replies);
}

代码示例来源:origin: org.zeromq/jeromq

@Override
public List<Socket> createSockets(ZContext ctx, Object... args)
{
  monitor = ctx.createSocket(ZMQ.PAIR);
  assert (monitor != null);
  return Collections.singletonList(monitor);
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

public ZeroMQDeliverySync(String name, String remoteContactPoint){
  if (name.endsWith(":")){
    name = name.substring(0, name.length()-1);
  }
  this.name = name;
  context = Main.getZmqContext();
  sender = context.createSocket(ZMQ.REQ);
  sender.connect(remoteContactPoint);
  closed = false;
}

代码示例来源:origin: stackoverflow.com

frontend = context.createSocket(ZMQ.XSUB);
System.out.println("Subscriber connecting to: " + addressSubscriber);
frontend.connect(addressSubscriber);
backend = context.createSocket(ZMQ.XPUB);
System.out.println("Publisher binding to: " + addressPublisher);
backend.bind(addressPublisher);

代码示例来源:origin: org.zeromq/jeromq

private ZAgent createAgent(ZContext ctx)
{
  Socket pipe = ctx.createSocket(ZMQ.PAIR);
  boolean rc = pipe.connect(repliesAddress);
  assert (rc);
  return new ZAgent.SimpleAgent(pipe, repliesAddress);
}

代码示例来源:origin: org.zeromq/jeromq

public static Socket fork(ZContext ctx, IAttachedRunnable runnable, Object... args)
  {
    Socket pipe = ctx.createSocket(ZMQ.PAIR);

    if (pipe != null) {
      pipe.bind(String.format("inproc://zctx-pipe-%d", pipe.hashCode()));
    }
    else {
      return null;
    }

    //  Connect child pipe to our pipe
    ZContext ccontext = ZContext.shadow(ctx);
    Socket cpipe = ccontext.createSocket(ZMQ.PAIR);
    if (cpipe == null) {
      return null;
    }
    cpipe.connect(String.format("inproc://zctx-pipe-%d", pipe.hashCode()));

    //  Prepare child thread
    Thread shim = new ShimThread(ccontext, runnable, args, cpipe);
    shim.start();

    return pipe;
  }
}

代码示例来源:origin: miniway/zper

@Override
public void run()
{
  String workerBind = "inproc://reader-worker";
  Socket router = context.createSocket(ZMQ.ROUTER);
  Socket inrouter = context.createSocket(ZMQ.ROUTER);
  router.setSendBufferSize(sendBufferSize);
  router.setEncoder(PersistEncoder.class);
  inrouter.bind(workerBind);
  for (int i = 0; i < numWorkers; i++) {
    String id = String.valueOf(i);
    ZPReaderWorker worker = new ZPReaderWorker(context, workerBind, id);
    worker.start();
    workers.add(id.getBytes());
  }
  LOG.info("Reader bind on " + bind);
  router.bind(bind);
  ZDevice.loadBalanceDevice(router, inrouter, workers);
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

public ZeroMQDeliveryAsync(String name){
  if (name.endsWith(":")){
    name = name.substring(0, name.length()-1);
  }
  this.name = name;
  context = Main.getZmqContext();
  // Socket to talk to clients
  publisher = context.createSocket(ZMQ.PUB);
  publisher.setLinger(5000);
  publisher.setSndHWM(0); // no limit
  publisher.bind("inproc://stream/"+name);
  Main.getZmqProxy().connectTo(name);
  closed = false;
}

代码示例来源:origin: fiber-space/jupyter-kernel-jsr223

public static void runKernelDebug(Session session) throws FileNotFoundException,
    InvalidKeyException,
    UnsupportedEncodingException,
    IOException {
  Session._DEBUG_ = true;
  ZContext ctx = new ZContext();
  Socket channel = ctx.createSocket(ZMQ.REP);
  channel.bind("tcp://127.0.0.1:2222");
  byte[] msg = channel.recv();
  String sArgs = new String(msg, StandardCharsets.UTF_8);
  String[] newArgs = sArgs.split(" ");
  channel.send("ok");
  runKernel(session, newArgs);
}

代码示例来源:origin: miniway/zper

@Override
public void run()
{
  LOG.info("Started Worker " + identity);
  worker = context.createSocket(ZMQ.DEALER);
  worker.setIdentity(identity.getBytes());
  worker.connect(bindAddr);
  try {
    loop();
  } catch (ZMQException e) {
    if (e.getErrorCode() != ZMQ.Error.ETERM.getCode())
      throw e;
  }
  context.destroy();
  LOG.info("Ended Reader Worker " + identity);
}

代码示例来源:origin: miniway/zper

@Override
public void run()
{
  LOG.info("Started Worker " + identity);
  worker = context.createSocket(ZMQ.DEALER);
  worker.setRcvHWM(2000);
  worker.setIdentity(identity.getBytes());
  worker.connect(bindAddr);
  try {
    loop();
  } catch (ZMQException e) {
    if (e.getErrorCode() != ZMQ.Error.ETERM.getCode())
      throw e;
  }
  LOG.info("Ended Writer Worker " + identity);
  context.destroy();
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

@Override
public boolean initialize() {
  
  kryo.register(StreamElement4Rest.class);
  kryo.register(DataField[].class);
  AddressBean addressBean = getActiveAddressBean();
  
  structure = getActiveAddressBean().getOutputStructure();
  String _lport = addressBean.getPredicateValue("local_port");
  laddress = addressBean.getPredicateValue("local_address");
  if ( laddress == null || laddress.trim().length() == 0 ) 
    throw new RuntimeException( "The >local_address< parameter is missing from the ZeroMQ wrapper." );
  if (_lport != null){
    lport = Integer.parseInt(_lport); 
    if ( lport <= 0 || lport > 65535 ) 
      throw new RuntimeException( "The >local_port< parameter must be a valid port number." );
  } else {
    throw new RuntimeException( "The >local_port< parameter is missing from the ZeroMQ wrapper." );
  }
  
  ZContext ctx = Main.getZmqContext();
  receiver = ctx.createSocket(ZMQ.REP);
  receiver.bind("tcp://*:"+lport);
  receiver.setReceiveTimeOut(10000);
  return true;
}

代码示例来源:origin: fbacchella/LogHub

public Socket newSocket(Method method, Sockets type, String endpoint, int hwm, int timeout) {
  Socket socket = context.createSocket(type.ordinal());
  socket.setRcvHWM(hwm);
  socket.setSndHWM(hwm);
  socket.setSendTimeOut(timeout);
  socket.setReceiveTimeOut(timeout);
  method.act(socket, endpoint);
  String url = endpoint + ":" + type.toString() + ":" + method.getSymbol();
  socket.setIdentity(url.getBytes());
  logger.debug("new socket: {}", url);
  return socket;
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

@Override
public DataField[] getOutputFormat() {
  if (structure == null){
    requester = ctx.createSocket(ZMQ.REQ);
    requester.setReceiveTimeOut(1000);
    requester.setSendTimeOut(1000);
    requester.setLinger(0);
    requester.connect(remoteContactPoint_META);
    if (requester.send(vsensor + "?tcp://" + laddress + ":" + lport)){
      byte[] rec = requester.recv();
      if (rec != null){
        structure =  kryo.readObjectOrNull(new Input(new ByteArrayInputStream(rec)),DataField[].class);
        if (structure != null)
          requester.close();
        return structure;
      }
    }
    requester.close();
  }
  return structure;
}

代码示例来源:origin: org.projectreactor/reactor-net

@Override
public void run() {
  if (closed) {
    return;
  }
  if (null == zmq) {
    zmq = new ZContext(ioThreadCount);
    shutdownCtx = true;
  }
  socket = zmq.createSocket(socketType);
  socket.setIdentity(id.toString().getBytes());
  configure(socket);
  pollin = new ZMQ.PollItem(socket, ZMQ.Poller.POLLIN);
  if (log.isTraceEnabled()) {
    zloop.verbose(true);
  }
  zloop.addPoller(pollin, inputHandler, null);
  start(socket);
  zloop.start();
  zmq.destroySocket(socket);
}

代码示例来源:origin: miniway/zper

@Override
public void run()
{
  String workerBind = "inproc://writer-worker";
  Socket router = context.createSocket(ZMQ.ROUTER);
  Socket inrouter = context.createSocket(ZMQ.ROUTER);
  router.setRcvHWM(recvHWM);
  router.setRouterMandatory(true);
  router.setRouterHandlover(true);
  router.setReceiveBufferSize(recvBufferSize);
  router.setMaxMsgSize(maxMessageSize);
  inrouter.setRouterMandatory(true);
  if (decoder)
    router.setDecoder(PersistDecoder.class);
  inrouter.setRouterMandatory(true);
  inrouter.bind(workerBind);
  for (int i = 0; i < numWorkers; i++) {
    String id = String.valueOf(i);
    ZPWriterWorker worker = new ZPWriterWorker(context, workerBind, id, decoder);
    worker.start();
    workers.add(id.getBytes());
  }
  LOG.info("Writer Bind on " + bind);
  router.bind(bind);
  ZDevice.addressDevice(router, inrouter, workers);
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

requester = ctx.createSocket(ZMQ.REQ);
requester.setReceiveTimeOut(1000);
requester.setSendTimeOut(1000);

代码示例来源:origin: ch.epfl.gsn/gsn-core

receiver.close();
ZContext ctx = Main.getZmqContext();
receiver = ctx.createSocket(ZMQ.REP);
receiver.bind("tcp://*:"+lport);
receiver.setReceiveTimeOut(10000);

代码示例来源:origin: io.projectreactor/reactor-net

@Override
public void run() {
  try {
    if (closed) {
      return;
    }
    if (null == zmq) {
      zmq = new ZContext(ioThreadCount);
      shutdownCtx = true;
    }
    socket = zmq.createSocket(socketType);
    socket.setIdentity(id.toString().getBytes());
    configure(socket);
    pollin = new ZMQ.PollItem(socket, ZMQ.Poller.POLLIN);
    if (log.isDebugEnabled()) {
      zloop.verbose(true);
    }
    zloop.addPoller(pollin, inputHandler, null);
    start(socket);
    zloop.start();
    zmq.destroySocket(socket);
  } catch (Exception e) {
    b.onError(e);
  }
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

@Override
public void run(){
  ZContext context = Main.getZmqContext();
  ZMQ.Socket subscriber = context.createSocket(ZMQ.SUB);

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com