private static void receiveVersionNegotiation(final VersionNegotiator negotiator, final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException { final int version = dis.readInt(); if (negotiator.isVersionSupported(version)) { dos.write(RESOURCE_OK); dos.flush(); negotiator.setVersion(version); } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT); dos.flush(); throw new HandshakeException("Unable to negotiate an acceptable version of the Distributed Cache Protocol"); } dos.write(DIFFERENT_RESOURCE_VERSION); dos.writeInt(preferred); dos.flush(); receiveVersionNegotiation(negotiator, dis, dos); } } }
final Integer preferred = negotiator.getPreferredVersion(requestedVersion); if (preferred == null) { logger.debug("Peer {} requested version {} of the Load Balance Protocol. This version is not acceptable. Aborting communications.", peerDescription, requestedVersion);
final Integer preferredVersion = negotiator.getPreferredVersion(requestedVersion); if (preferredVersion == null) { logger.debug("Peer {} requested version {} of the Load Balance Protocol. This version is not acceptable. Aborting communications.", peerDescription, requestedVersion);
@SuppressWarnings("unchecked") public static <T extends ServerProtocol> T receiveServerProtocolNegotiation(final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException { final String protocolName = dis.readUTF(); final int version = dis.readInt(); final T protocol = (T) RemoteResourceManager.createServerProtocol(protocolName); final VersionNegotiator negotiator = protocol.getVersionNegotiator(); if (negotiator.isVersionSupported(version)) { dos.write(RESOURCE_OK); dos.flush(); negotiator.setVersion(version); return protocol; } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT); dos.flush(); throw new HandshakeException("Unable to negotiate an acceptable version of the ServerProtocol " + protocolName); } dos.write(DIFFERENT_RESOURCE_VERSION); dos.writeInt(preferred); dos.flush(); return receiveServerProtocolNegotiation(dis, dos); } }
@SuppressWarnings("unchecked") public static <T extends FlowFileCodec> T receiveCodecNegotiation(final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException { final String codecName = dis.readUTF(); final int version = dis.readInt(); final T codec = (T) RemoteResourceManager.createCodec(codecName, version); final VersionNegotiator negotiator = codec.getVersionNegotiator(); if (negotiator.isVersionSupported(version)) { dos.write(RESOURCE_OK); dos.flush(); negotiator.setVersion(version); return codec; } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT); dos.flush(); throw new HandshakeException("Unable to negotiate an acceptable version of the FlowFileCodec " + codecName); } dos.write(DIFFERENT_RESOURCE_VERSION); dos.writeInt(preferred); dos.flush(); return receiveCodecNegotiation(dis, dos); } }
@SuppressWarnings("unchecked") public static <T extends ClientProtocol> T receiveClientProtocolNegotiation(final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException { final String protocolName = dis.readUTF(); final int version = dis.readInt(); final T protocol = (T) RemoteResourceManager.createClientProtocol(protocolName); final VersionNegotiator negotiator = protocol.getVersionNegotiator(); if (negotiator.isVersionSupported(version)) { dos.write(RESOURCE_OK); dos.flush(); negotiator.setVersion(version); return protocol; } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT); dos.flush(); throw new HandshakeException("Unable to negotiate an acceptable version of the ClientProtocol " + protocolName); } dos.write(DIFFERENT_RESOURCE_VERSION); dos.writeInt(preferred); dos.flush(); return receiveClientProtocolNegotiation(dis, dos); } }
return resource; } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT);
protected Integer negotiateTransportProtocolVersion(final HttpServletRequest req, final VersionNegotiator transportProtocolVersionNegotiator) throws BadRequestException { String protocolVersionStr = req.getHeader(HttpHeaders.PROTOCOL_VERSION); if (isEmpty(protocolVersionStr)) { throw new BadRequestException("Protocol version was not specified."); } final Integer requestedProtocolVersion; try { requestedProtocolVersion = Integer.valueOf(protocolVersionStr); } catch (NumberFormatException e) { throw new BadRequestException("Specified protocol version was not in a valid number format: " + protocolVersionStr); } Integer protocolVersion; if (transportProtocolVersionNegotiator.isVersionSupported(requestedProtocolVersion)) { return requestedProtocolVersion; } else { protocolVersion = transportProtocolVersionNegotiator.getPreferredVersion(requestedProtocolVersion); } if (protocolVersion == null) { throw new BadRequestException("Specified protocol version is not supported: " + protocolVersionStr); } return protocolVersion; }
final Integer newPreference = negotiator.getPreferredVersion(newVersion);
private static void initiateVersionNegotiation(final VersionNegotiator negotiator, final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException { // Write the classname of the RemoteStreamCodec, followed by its version dos.writeInt(negotiator.getVersion()); dos.flush(); // wait for response from server. final int statusCode = dis.read(); switch (statusCode) { case RESOURCE_OK: // server accepted our proposal of codec name/version return; case DIFFERENT_RESOURCE_VERSION: // server accepted our proposal of codec name but not the version // Get server's preferred version final int newVersion = dis.readInt(); // Determine our new preferred version that is no greater than the server's preferred version. final Integer newPreference = negotiator.getPreferredVersion(newVersion); // If we could not agree with server on a version, fail now. if (newPreference == null) { throw new HandshakeException("Could not agree on protocol version"); } negotiator.setVersion(newPreference); // Attempt negotiation of resource based on our new preferred version. initiateVersionNegotiation(negotiator, dis, dos); return; case ABORT: throw new HandshakeException("Remote destination aborted connection with message: " + dis.readUTF()); default: throw new HandshakeException("Received unexpected response code " + statusCode + " when negotiating version with remote server"); } }
@SuppressWarnings("unchecked") public static <T extends FlowFileCodec> T receiveCodecNegotiation(final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException { final String codecName = dis.readUTF(); final int version = dis.readInt(); final T codec = (T) RemoteResourceManager.createCodec(codecName, version); final VersionNegotiator negotiator = codec.getVersionNegotiator(); if (negotiator.isVersionSupported(version)) { dos.write(RESOURCE_OK); dos.flush(); negotiator.setVersion(version); return codec; } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT); dos.flush(); throw new HandshakeException("Unable to negotiate an acceptable version of the FlowFileCodec " + codecName); } dos.write(DIFFERENT_RESOURCE_VERSION); dos.writeInt(preferred); dos.flush(); return receiveCodecNegotiation(dis, dos); } }
@SuppressWarnings("unchecked") public static <T extends ClientProtocol> T receiveClientProtocolNegotiation(final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException { final String protocolName = dis.readUTF(); final int version = dis.readInt(); final T protocol = (T) RemoteResourceManager.createClientProtocol(protocolName); final VersionNegotiator negotiator = protocol.getVersionNegotiator(); if (negotiator.isVersionSupported(version)) { dos.write(RESOURCE_OK); dos.flush(); negotiator.setVersion(version); return protocol; } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT); dos.flush(); throw new HandshakeException("Unable to negotiate an acceptable version of the ClientProtocol " + protocolName); } dos.write(DIFFERENT_RESOURCE_VERSION); dos.writeInt(preferred); dos.flush(); return receiveClientProtocolNegotiation(dis, dos); } }
@SuppressWarnings("unchecked") public static <T extends ServerProtocol> T receiveServerProtocolNegotiation(final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException { final String protocolName = dis.readUTF(); final int version = dis.readInt(); final T protocol = (T) RemoteResourceManager.createServerProtocol(protocolName); final VersionNegotiator negotiator = protocol.getVersionNegotiator(); if (negotiator.isVersionSupported(version)) { dos.write(RESOURCE_OK); dos.flush(); negotiator.setVersion(version); return protocol; } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT); dos.flush(); throw new HandshakeException("Unable to negotiate an acceptable version of the ServerProtocol " + protocolName); } dos.write(DIFFERENT_RESOURCE_VERSION); dos.writeInt(preferred); dos.flush(); return receiveServerProtocolNegotiation(dis, dos); } }
return resource; } else { final Integer preferred = negotiator.getPreferredVersion(version); if (preferred == null) { dos.write(ABORT);