/** * Writes a request message and returns the result through a Callback. * Clients can also use a Future interface by creating a new CallFuture<T>, * passing it in as the Callback parameter, and then waiting on that Future. * @param <T> the return type of the message. * @param messageName the name of the message to invoke. * @param request the request data to send. * @param callback the callback which will be invoked when the response is returned * or an error occurs. * @throws Exception if an error occurs sending the message. */ public <T> void request(String messageName, Object request, Callback<T> callback) throws Exception { request(new Request(messageName, request, new RPCContext()), callback); }
private RPCContext makeContext() { RPCContext context = new RPCContext(); context.setMessage(message); return context; }
/** Writes a request message and reads a response or error message. */ public Object request(String messageName, Object request) throws Exception { // Initialize request Request rpcRequest = new Request(messageName, request, new RPCContext()); CallFuture<Object> future = /* only need a Future for two-way messages */ rpcRequest.getMessage().isOneWay() ? null : new CallFuture<>(); // Send request request(rpcRequest, future); if (future == null) // the message is one-way, so return immediately return null; try { // the message is two-way, wait for the result return future.get(); } catch (ExecutionException e) { if (e.getCause() instanceof Exception) { throw (Exception)e.getCause(); } else { throw new AvroRemoteException(e.getCause()); } } }
RPCContext context = new RPCContext(); context.setHandshakeResponse(handshake); for (RPCPlugin plugin : rpcMetaPlugins) {
RPCContext context = new RPCContext(); context.setHandshakeRequest(request); context.setHandshakeResponse(response);
private void writeHandshake(Encoder out) throws IOException { if (getTransceiver().isConnected()) return; MD5 localHash = new MD5(); localHash.bytes(local.getMD5()); String remoteName = transceiver.getRemoteName(); MD5 remoteHash = REMOTE_HASHES.get(remoteName); if (remoteHash == null) { // guess remote is local remoteHash = localHash; remote = local; } else { remote = REMOTE_PROTOCOLS.get(remoteHash); } HandshakeRequest handshake = new HandshakeRequest(); handshake.clientHash = localHash; handshake.serverHash = remoteHash; if (sendLocalText) handshake.clientProtocol = local.toString(); RPCContext context = new RPCContext(); context.setHandshakeRequest(handshake); for (RPCPlugin plugin : rpcMetaPlugins) { plugin.clientStartConnect(context); } handshake.meta = context.requestHandshakeMeta(); HANDSHAKE_WRITER.write(handshake, out); }
BinaryEncoder out = EncoderFactory.get().binaryEncoder(bbo, null); Exception error = null; RPCContext context = new RPCContext(); List<ByteBuffer> payload = null; List<ByteBuffer> handshake = null;
/** * Writes a request message and returns the result through a Callback. * Clients can also use a Future interface by creating a new CallFuture<T>, * passing it in as the Callback parameter, and then waiting on that Future. * @param <T> the return type of the message. * @param messageName the name of the message to invoke. * @param request the request data to send. * @param callback the callback which will be invoked when the response is returned * or an error occurs. * @throws Exception if an error occurs sending the message. */ public <T> void request(String messageName, Object request, Callback<T> callback) throws Exception { request(new Request(messageName, request, new RPCContext()), callback); }
/** Writes a request message and reads a response or error message. */ public Object request(String messageName, Object request) throws Exception { // Initialize request Request rpcRequest = new Request(messageName, request, new RPCContext()); CallFuture<Object> future = /* only need a Future for two-way messages */ rpcRequest.getMessage().isOneWay() ? null : new CallFuture<Object>(); // Send request request(rpcRequest, future); if (future == null) // the message is one-way, so return immediately return null; try { // the message is two-way, wait for the result return future.get(); } catch (ExecutionException e) { if (e.getCause() instanceof Exception) { throw (Exception)e.getCause(); } else { throw new AvroRemoteException(e.getCause()); } } }
RPCContext context = new RPCContext(); if (handshake.meta != null) { context.setResponseHandshakeMeta((Map<Utf8, ByteBuffer>) handshake.meta);
RPCContext context = new RPCContext(); context.setHandshakeResponse(handshake); for (RPCPlugin plugin : rpcMetaPlugins) {
RPCContext context = new RPCContext(); if (handshake.meta != null) { context.setResponseHandshakeMeta((Map<CharSequence, ByteBuffer>) handshake.meta);
private void writeHandshake(Encoder out) throws IOException { MD5 localHash = new MD5(); localHash.bytes(local.getMD5()); String remoteName = transceiver.getRemoteName(); MD5 remoteHash = REMOTE_HASHES.get(remoteName); remote = REMOTE_PROTOCOLS.get(remoteHash); if (remoteHash == null) { // guess remote is local remoteHash = localHash; remote = local; } HandshakeRequest handshake = new HandshakeRequest(); handshake.clientHash = localHash; handshake.serverHash = remoteHash; if (sendLocalText) handshake.clientProtocol = new Utf8(local.toString()); RPCContext context = new RPCContext(); for (RPCPlugin plugin : rpcMetaPlugins) { plugin.clientStartConnect(context); } handshake.meta = context.requestHandshakeMeta(); HANDSHAKE_WRITER.write(handshake, out); }
RPCContext context = new RPCContext(); context.setRequestHandshakeMeta((Map<CharSequence, ByteBuffer>) request.meta);
private void writeHandshake(Encoder out) throws IOException { if (getTransceiver().isConnected()) return; MD5 localHash = new MD5(); localHash.bytes(local.getMD5()); String remoteName = transceiver.getRemoteName(); MD5 remoteHash = REMOTE_HASHES.get(remoteName); remote = REMOTE_PROTOCOLS.get(remoteHash); if (remoteHash == null) { // guess remote is local remoteHash = localHash; remote = local; } HandshakeRequest handshake = new HandshakeRequest(); handshake.clientHash = localHash; handshake.serverHash = remoteHash; if (sendLocalText) handshake.clientProtocol = new Utf8(local.toString()); RPCContext context = new RPCContext(); for (RPCPlugin plugin : rpcMetaPlugins) { plugin.clientStartConnect(context); } handshake.meta = context.requestHandshakeMeta(); HANDSHAKE_WRITER.write(handshake, out); }
RPCContext context = new RPCContext(); context.setHandshakeRequest(request); context.setHandshakeResponse(response);
RPCContext context = new RPCContext(); context.setRequestHandshakeMeta((Map<Utf8, ByteBuffer>) request.meta);
private void writeHandshake(Encoder out) throws IOException { if (getTransceiver().isConnected()) return; MD5 localHash = new MD5(); localHash.bytes(local.getMD5()); String remoteName = transceiver.getRemoteName(); MD5 remoteHash = REMOTE_HASHES.get(remoteName); if (remoteHash == null) { // guess remote is local remoteHash = localHash; remote = local; } else { remote = REMOTE_PROTOCOLS.get(remoteHash); } HandshakeRequest handshake = new HandshakeRequest(); handshake.clientHash = localHash; handshake.serverHash = remoteHash; if (sendLocalText) handshake.clientProtocol = local.toString(); RPCContext context = new RPCContext(); context.setHandshakeRequest(handshake); for (RPCPlugin plugin : rpcMetaPlugins) { plugin.clientStartConnect(context); } handshake.meta = context.requestHandshakeMeta(); HANDSHAKE_WRITER.write(handshake, out); }
Encoder out = new BinaryEncoder(bbo); Exception error = null; RPCContext context = new RPCContext(); try { Protocol remote = handshake(in, out);
BinaryDecoder in = null; Message m; RPCContext context = new RPCContext(); do { ByteBufferOutputStream bbo = new ByteBufferOutputStream();