本文整理汇总了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();
}
示例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;
}
}
}
}
示例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();
}
}
示例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");
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
}
示例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();
}
示例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;
}
}
}
示例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);
}
}
示例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);
}
}
}
示例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());
}
示例15: receive
import org.zeromq.ZMQException; //导入依赖的package包/类
@Override
public byte[] receive() {
checkClosed();
try {
return socket.recv(0);
} catch (ZMQException ex) {
throw ZMQExceptions.wrap(ex);
}
}