/** 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(); } }
/** 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(); } }
Encoder out = new BinaryEncoder(bbo); writeHandshake(out); // prepend handshake
writeHandshake(out); // prepend handshake if needed META_WRITER.write(context.requestCallMeta(), out);