/** * Called by {@link Requestor#request(String,Object,Callback)} for two-way messages using callbacks. */ public void transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback) throws IOException { // The default implementation works synchronously try { List<ByteBuffer> response = transceive(request); callback.handleResult(response); } catch (IOException e) { callback.handleError(e); } }
@Override public synchronized List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException { if (saslResponsePiggybacked) { // still need to read response saslResponsePiggybacked = false; Status status = readStatus(); ByteBuffer frame = readFrame(); switch (status) { case COMPLETE: break; case FAIL: throw new SaslException("Fail: "+toString(frame)); default: throw new IOException("Unexpected SASL status: "+status); } } return super.transceive(request); }
/** Return the remote protocol. Force a handshake if required. */ public Protocol getRemote() throws IOException { if (remote != null) return remote; // already have it MD5 remoteHash = REMOTE_HASHES.get(transceiver.getRemoteName()); if (remoteHash != null) { remote = REMOTE_PROTOCOLS.get(remoteHash); if (remote != null) return remote; // already cached } handshakeLock.lock(); try { // force handshake ByteBufferOutputStream bbo = new ByteBufferOutputStream(); // direct because the payload is tiny. Encoder out = ENCODER_FACTORY.directBinaryEncoder(bbo, null); writeHandshake(out); out.writeInt(0); // empty metadata out.writeString(""); // bogus message name List<ByteBuffer> response = getTransceiver().transceive(bbo.getBufferList()); ByteBufferInputStream bbi = new ByteBufferInputStream(response); BinaryDecoder in = DecoderFactory.get().binaryDecoder(bbi, null); readHandshake(in); return this.remote; } finally { handshakeLock.unlock(); } }
List<ByteBuffer> response = transceiver.transceive(byteBufferOutputStream.getBufferList());
getTransceiver().transceive (handshake.getBytes(), new TransceiverCallback<>(handshake, callback));
} else { CallFuture<T> callFuture = new CallFuture<>(callback); t.transceive(request.getBytes(), new TransceiverCallback<>(request, callFuture)); t.transceive(request.getBytes(), new TransceiverCallback<>(request, callback));
@Override public synchronized List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException { this.connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", CONTENT_TYPE); connection.setRequestProperty("Content-Length", Integer.toString(getLength(request))); connection.setDoOutput(true); //LOG.info("Connecting to: "+url); return super.transceive(request); }
/** * Called by {@link Requestor#request(String,Object,Callback)} for two-way messages using callbacks. */ public void transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback) throws IOException { // The default implementation works synchronously try { List<ByteBuffer> response = transceive(request); callback.handleResult(response); } catch (IOException e) { callback.handleError(e); } }
@Override public synchronized List<ByteBuffer> transceive(List<ByteBuffer> request) throws IOException { if (saslResponsePiggybacked) { // still need to read response saslResponsePiggybacked = false; Status status = readStatus(); ByteBuffer frame = readFrame(); switch (status) { case COMPLETE: break; case FAIL: throw new SaslException("Fail: "+toString(frame)); default: throw new IOException("Unexpected SASL status: "+status); } } return super.transceive(request); }
/** Return the remote protocol. Force a handshake if required. */ public Protocol getRemote() throws IOException { if (remote != null) return remote; // already have it MD5 remoteHash = REMOTE_HASHES.get(transceiver.getRemoteName()); if (remoteHash != null) { remote = REMOTE_PROTOCOLS.get(remoteHash); if (remote != null) return remote; // already cached } handshakeLock.lock(); try { // force handshake ByteBufferOutputStream bbo = new ByteBufferOutputStream(); // direct because the payload is tiny. Encoder out = ENCODER_FACTORY.directBinaryEncoder(bbo, null); writeHandshake(out); out.writeInt(0); // empty metadata out.writeString(""); // bogus message name List<ByteBuffer> response = getTransceiver().transceive(bbo.getBufferList()); ByteBufferInputStream bbi = new ByteBufferInputStream(response); BinaryDecoder in = DecoderFactory.get().binaryDecoder(bbi, null); readHandshake(in); return this.remote; } finally { handshakeLock.unlock(); } }
List<ByteBuffer> response = transceiver.transceive(byteBufferOutputStream.getBufferList());
getTransceiver().transceive (handshake.getBytes(), new TransceiverCallback<T>(handshake, callback));
} else { CallFuture<T> callFuture = new CallFuture<T>(callback); t.transceive(request.getBytes(), new TransceiverCallback<T>(request, callFuture)); t.transceive(request.getBytes(), new TransceiverCallback<T>(request, callback));
getTransceiver().transceive(bbo.getBufferList());
List<ByteBuffer> response = t.transceive(requestBytes); ByteBufferInputStream bbi = new ByteBufferInputStream(response); in = DecoderFactory.defaultFactory().createBinaryDecoder(bbi, in);