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


Java ZMQException类代码示例

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


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

示例1: run

import org.zeromq.ZMQException; //导入依赖的package包/类
@Override
public void run() {
    LOGGER.info("Started ZMQ pusher");

    pull.connect("tcp://127.0.0.1:"+ port);

    while (!Thread.interrupted() || stopped.get()) {
        String m = null;
        try {
            m = pull.recvStr();
            InputHandler.handleMessage(m);
        } catch (ZMQException ex) {
            LOGGER.error("ZMQ error in KV7/8 processing", ex);
        } catch (Exception e) {
            LOGGER.error("Error in KV7/8 processing", e);
            metrics.increaseBucketValue("kv78turbo.messages.errors", ChronoUnit.HOURS);
            if (m != null) {
                LOGGER.debug("Got message {}", m);
            }
        }
    }

    LOGGER.debug("Processing task is interrupted");
    disconnect();
}
 
开发者ID:CROW-NDOV,项目名称:displaydirect,代码行数:26,代码来源:Kv78ProcessTask.java

示例2: recvMessage

import org.zeromq.ZMQException; //导入依赖的package包/类
/**
 * Receive and parse multipart message.
 *
 * @param socket    zmq socket to receive message on
 * @param flag      parameters passed to ZMsg.recvMsg()
 * @return reply    null if no message is received
 *
 * @throws ProtocolException    RequestDispatcher protocol violated
 * @throws ZmqEtermException    when context is closed while receiving messages
 * @throws IOException          other IOErrors (encompasses Protocol and ZmqEtermException)
 */
public static TransferWrapper recvMessage(ZMQ.Socket socket, int flag) throws ProtocolException {
    {
        try {
            ZMsg message = ZMsg.recvMsg(socket, flag);

            if (message == null || message.size() <= 2 ) {
                // message.size() check works around bug in jeromq:
                // https://github.com/zeromq/jeromq/commit/750b5f408ab2e925d17de700eda3e16185b770fc
                return null;
            }

            return new TransferWrapper(message);

        } catch (ZMQException e) {
            if (e.getErrorCode() == ZMQ.Error.ETERM.getCode()){
                log.debug("Received ETERM.");
                throw new ZmqEtermException(e);
            } else {
                throw e;
            }
        }
    }
}
 
开发者ID:HeinrichHartmann,项目名称:RequestDispatcher,代码行数:35,代码来源:TransferHelper.java

示例3: run

import org.zeromq.ZMQException; //导入依赖的package包/类
/**
 * Print messages to output stream.
 * Socket gets closed on ETERM.
 */
@Override
public void run() {
    try {
        log.info("Starting print loop.");
        String msg = null;
        while (true) {
            msg = socket.recvStr();
            log.debug("Received " + msg);
            outputStream.println(msg);
        }
    } catch (ZMQException e) {
        log.info("Catched ETERM. Closing socket. ");
        socket.close();
        outputStream.flush();
    }
}
 
开发者ID:HeinrichHartmann,项目名称:RequestDispatcher,代码行数:21,代码来源:PrintServer.java

示例4: run

import org.zeromq.ZMQException; //导入依赖的package包/类
/**
 * Push every message received on to the ring buffer
 * until signaled to stop
 *
 * Critical Path! Any additional work here will impact
 * total throughput!
 */
@Override
public void run() {
    logger.debug("starting server socket");
    while(socketListening) {
        // receive bytes representing a metric to be saved
        byte[] receivedBytes = null;
        try {
            receivedBytes = serverSocket.recv(0);
        } catch (ZMQException e) {
            logger.error(e.getMessage());
            close();
        }

        // publish metric to ring buffer
        long seq = ringBuffer.next();
        ByteArrayHolder metricHolder = ringBuffer.get(seq);
        metricHolder.setValue(receivedBytes);
        ringBuffer.publish(seq);
    }

    logger.debug("zeromq listening socket exiting");
}
 
开发者ID:kavehg,项目名称:raider,代码行数:30,代码来源:ReceiveSocket.java

示例5: createConnectableSocketWithStandardSettings

import org.zeromq.ZMQException; //导入依赖的package包/类
protected ZMQ.Socket createConnectableSocketWithStandardSettings() {
    ZMQ.Context zmqContext = context.getZMQContext();
    ZMQ.Socket socket;
    try {
        socket = zmqContext.socket(this.getSocketType().getType());
        socket.setLinger(getLinger());
        socket.setSndHWM(getSendHighWaterMark());
        socket.setRcvHWM(getReceiveHighWaterMark());
        socket.setReceiveTimeOut(getSocketSpec().receiveTimeout);
        socket.setSendTimeOut(getSocketSpec().sendTimeout);
        if (this.getIdentity() != null && this.getIdentity().length > 0) {
            socket.setIdentity(this.getIdentity());
        }
    } catch (ZMQException ex) {
        throw ZMQExceptions.wrap(ex);
    }
    return socket;
}
 
开发者ID:zeromq,项目名称:jzmq-api,代码行数:19,代码来源:SocketBuilder.java

示例6: createBindableSocketWithStandardSettings

import org.zeromq.ZMQException; //导入依赖的package包/类
protected ZMQ.Socket createBindableSocketWithStandardSettings() {
    ZMQ.Context zmqContext = context.getZMQContext();
    ZMQ.Socket socket;
    try {
        socket = zmqContext.socket(this.getSocketType().getType());
        socket.setLinger(this.getLinger());
        socket.setRcvHWM(this.getReceiveHighWaterMark());
        socket.setSndHWM(this.getSendHighWaterMark());
        socket.setReceiveTimeOut(getSocketSpec().receiveTimeout);
        socket.setSendTimeOut(getSocketSpec().sendTimeout);
        if (this.getIdentity() != null && this.getIdentity().length > 0) {
            socket.setIdentity(this.getIdentity());
        }
    } catch (ZMQException ex) {
        throw ZMQExceptions.wrap(ex);
    }
    return socket;
}
 
开发者ID:zeromq,项目名称:jzmq-api,代码行数:19,代码来源:SocketBuilder.java

示例7: doSend

import org.zeromq.ZMQException; //导入依赖的package包/类
synchronized private RPCResponse[] doSend(String json) throws IOException {
    LOGGER.info("JSON Req: " + json);
    zmqSocket.send(json);
    byte[] msg = zmqSocket.recv(0);
    if (msg == null) {
        int errNumber = zmqSocket.base().errno();
        throw new ZMQException("Unable to receive message from socket", errNumber);
    }
    String response = new String(msg);
    LOGGER.info("JSON Resp: " + response);
    
    return new ObjectMapper().readValue(response, RPCResponse[].class);
}
 
开发者ID:cisco-system-traffic-generator,项目名称:trex-java-sdk,代码行数:14,代码来源:TRexTransport.java

示例8: call

import org.zeromq.ZMQException; //导入依赖的package包/类
private String call(String json) {
    LOGGER.info("JSON Req: " + json);
    byte[] msg = transport.sendJson(json);
    if (msg == null) {
        int errNumber = transport.getSocket().base().errno();
        String errMsg = "Unable to receive message from socket";
        ZMQException zmqException = new ZMQException(errMsg, errNumber);
        LOGGER.error(errMsg, zmqException);
        throw zmqException;
    }
    String response = new String(msg);
    LOGGER.info("JSON Resp: " + response);
    return response;
}
 
开发者ID:cisco-system-traffic-generator,项目名称:trex-java-sdk,代码行数:15,代码来源:TRexClient.java

示例9: sendMessage

import org.zeromq.ZMQException; //导入依赖的package包/类
public static void sendMessage(ZMQ.Socket socket, TransferWrapper transferWrapper) {
    try {
        boolean rc = transferWrapper.toMessage().send(socket);
        if (!rc) throw new ZMQException.IOException(new IOException("Error sending message"));
    } catch (ZMQException e) {
        if (e.getErrorCode() == ZMQ.Error.ETERM.getCode()){
            log.debug("Received ETERM.");
            throw new ZmqEtermException(e);
        } else {
            throw e;
        }
    }
}
 
开发者ID:HeinrichHartmann,项目名称:RequestDispatcher,代码行数:14,代码来源:TransferHelper.java

示例10: Router

import org.zeromq.ZMQException; //导入依赖的package包/类
public Router(final String addr) {

    new Thread() {

      @Override
      public void run() {
        Context ctx = ZMQ.context(1);
        Socket router = ctx.socket(ZMQ.ROUTER);
        LOGGER.info("Binding reply socket to " + addr);
        router.bind(addr);

        while (!Thread.currentThread().isInterrupted()) {
          try {
            String id = router.recvStr();
            router.sendMore(id);
            router.recv();
            String request = router.recvStr();
            router.sendMore("");

            LOGGER.info("Handling request " + request);
            String response = handle(request);

            LOGGER.info("Sending response");
            router.send(response);
          } catch (Exception e) {
            LOGGER.warn("Error handling request", e);

            if (e instanceof ZMQException) {
              LOGGER.error("Will close reply socket");
              break;
            }
          }
        }
        router.close();
        ctx.close();
        LOGGER.info("Closed reply socket " + addr);
      }

    }.start();
  }
 
开发者ID:Horsed,项目名称:jeromq-toolkit,代码行数:41,代码来源:Router.java

示例11: receiveMessage

import org.zeromq.ZMQException; //导入依赖的package包/类
public static byte[] receiveMessage(ZMQ.Socket zmqSocket) {
    try {
        return zmqSocket.recv(0);
    } catch (ZMQException e) {
        if(e.getErrorCode() == ZMQURIConstants.ERR_ETERM) {
            LOG.log(Level.FINE, "ZeroMQ context terminated. Closing socket...");
            zmqSocket.close();
            return null;
        }
        else {
            throw e;
        }
    }
}
 
开发者ID:claudemamo,项目名称:cxf-rt-transports-zeromq,代码行数:15,代码来源:ZMQUtils.java

示例12: wrap

import org.zeromq.ZMQException; //导入依赖的package包/类
/**
 * Wrap an underlying ZMQException in the appropriate higher level exception.
 * 
 * @param thrown The underlying ZMQException
 * @return A new exception, which wraps a ZMQException
 */
public static ZMQRuntimeException wrap(ZMQException thrown) {
    if (isContextTerminated(thrown)) {
        return new ContextTerminatedException(thrown);
    } else if (isInvalidSocket(thrown)) {
        return new InvalidSocketException(thrown);
    } else {
        return new ZMQRuntimeException(thrown);
    }
}
 
开发者ID:zeromq,项目名称:jzmq-api,代码行数:16,代码来源:ZMQExceptions.java

示例13: poll

import org.zeromq.ZMQException; //导入依赖的package包/类
@Override
public void poll(long timeoutMillis) {
    try {
        int numberOfObjects = poller.poll(timeoutMillis);
        if (numberOfObjects == 0) {
            return;
        }

        // simulate ETERM to make JeroMQ act like jzmq, which no longer returns -1
        if (numberOfObjects < 0) {
            throw new ZMQException("Simulated ETERM error", (int) ZMQ.Error.ETERM.getCode());
        }
    } catch (ZMQException ex) {
        throw ZMQExceptions.wrap(ex);
    }

    for (int index = 0; index < pollables.size(); index++) {
        Pollable pollable = pollables.get(index);
        PollListener listener = listeners.get(index);
        if (pollable != null) {
            if (poller.pollin(index))
                listener.handleIn(pollable);
            if (poller.pollout(index))
                listener.handleOut(pollable);
            if (poller.pollerr(index))
                listener.handleError(pollable);
        }
    }
}
 
开发者ID:zeromq,项目名称:jzmq-api,代码行数:30,代码来源:PollerImpl.java

示例14: run

import org.zeromq.ZMQException; //导入依赖的package包/类
@Override
public void run() {
    try {
        backgroundable.run(context, pipe);
    } catch (ZMQException ex) {
        if (!ZMQExceptions.isContextTerminated(ex)) {
            throw ZMQExceptions.wrap(ex);
        }
    }
    log.debug("Background thread {} has shut down", Thread.currentThread().getName());
}
 
开发者ID:zeromq,项目名称:jzmq-api,代码行数:12,代码来源:ManagedContext.java

示例15: receive

import org.zeromq.ZMQException; //导入依赖的package包/类
@Override
public byte[] receive() {
    checkClosed();
    try {
        return socket.recv(0);
    } catch (ZMQException ex) {
        throw ZMQExceptions.wrap(ex);
    }
}
 
开发者ID:zeromq,项目名称:jzmq-api,代码行数:10,代码来源:ManagedSocket.java


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