Example usage for com.rabbitmq.utility BlockingCell BlockingCell

List of usage examples for com.rabbitmq.utility BlockingCell BlockingCell

Introduction

In this page you can find the example usage for com.rabbitmq.utility BlockingCell BlockingCell.

Prototype

public BlockingCell() 

Source Link

Document

Instantiate a new BlockingCell waiting for a value of the specified type.

Usage

From source file:net.lshift.accent.ConnectionSmokeTest.java

License:Apache License

private static ControlledConnectionProxy createProxy(int port) throws IOException {
    ControlledConnectionProxy proxy = new ControlledConnectionProxy(port, "proxy", "localhost",
            ConnectionFactory.DEFAULT_AMQP_PORT, new BlockingCell<Exception>());
    proxy.start();//from ww w.j  ava  2  s .  co  m

    return proxy;
}

From source file:net.lshift.accent.ControlledConnectionProxy.java

License:Mozilla Public License

public void run() {
    try {//  w w w. ja  v a2 s .  c o  m
        this.inServer = new ServerSocket(listenPort);
        inServer.setReuseAddress(true);

        this.inSock = inServer.accept();
        this.outSock = new Socket(host, port);

        DataInputStream iis = new DataInputStream(this.inSock.getInputStream());
        DataOutputStream ios = new DataOutputStream(this.inSock.getOutputStream());
        DataInputStream ois = new DataInputStream(this.outSock.getInputStream());
        DataOutputStream oos = new DataOutputStream(this.outSock.getOutputStream());

        byte[] handshake = new byte[8];
        iis.readFully(handshake);
        oos.write(handshake);

        BlockingCell<Exception> wio = new BlockingCell<Exception>();

        new Thread(new DirectionHandler(wio, true, iis, oos)).start();
        new Thread(new DirectionHandler(wio, false, ois, ios)).start();

        waitAndLogException(wio); // either stops => we stop
    } catch (Exception e) {
        reportAndLogNonNullException(e);
    } finally {
        try {
            if (this.inSock != null)
                this.inSock.close();
        } catch (Exception e) {
            logException(e);
        }
        try {
            if (this.outSock != null)
                this.outSock.close();
        } catch (Exception e) {
            logException(e);
        }
        this.reportEnd.setIfUnset(null);
    }
}

From source file:uk.trainwatch.rabbitmq.RabbitRPCClient.java

License:Apache License

private byte[] primitiveCall(AMQP.BasicProperties props, byte[] message)
        throws IOException, ShutdownSignalException, TimeoutException {
    checkConsumer();/* w w w  .  ja  va 2  s . com*/
    BlockingCell<Object> k = new BlockingCell<>();

    String replyId = RabbitMQ.newCorrelationId();
    props = ((props == null) ? new AMQP.BasicProperties.Builder() : props.builder()).correlationId(replyId)
            .replyTo(replyQueue).build();
    continuationMap.put(replyId, k);

    publish(props, message);

    Object reply = k.uninterruptibleGet(timeout);
    if (reply instanceof ShutdownSignalException) {
        ShutdownSignalException sig = (ShutdownSignalException) reply;
        ShutdownSignalException wrapper = new ShutdownSignalException(sig.isHardError(),
                sig.isInitiatedByApplication(), sig.getReason(), sig.getReference());
        wrapper.initCause(sig);
        throw wrapper;
    } else {
        return (byte[]) reply;
    }
}