@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); } }
public static boolean isCodecSupported(final String codecName, final int version) { if (!isCodecSupported(codecName)) { return false; } final FlowFileCodec codec = createCodec(codecName); final VersionNegotiator negotiator = codec.getVersionNegotiator(); return (negotiator.isVersionSupported(version)); }
@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); } }
public static List<Integer> getSupportedVersions(final String codecName) { final FlowFileCodec codec = createCodec(codecName); return codec.getSupportedVersions(); }
public static ClientProtocol createClientProtocol(final String protocolName) { final Set<Class<? extends ClientProtocol>> classSet = getClientProtocolClasses(protocolName); if (classSet.isEmpty()) { throw new IllegalArgumentException("Unknkown Client Protocol: " + protocolName); } Class<? extends ClientProtocol> desiredClass = desiredClientProtocolClassMap.get(protocolName); if (desiredClass == null && classSet.size() > 1) { throw new IllegalStateException("Multiple implementations of Client Protocol " + protocolName + " were found and no preferred implementation has been specified"); } if (desiredClass != null && !classSet.contains(desiredClass)) { throw new IllegalStateException("Desired implementation of Client Protocol " + protocolName + " is set to " + desiredClass + ", but that Protocol is not registered as a Client Protocol"); } if (desiredClass == null) { desiredClass = classSet.iterator().next(); } try { return desiredClass.newInstance(); } catch (final Exception e) { throw new RuntimeException("Unable to instantiate class " + desiredClass.getName(), e); } } }
public static ServerProtocol createServerProtocol(final String protocolName) { final Set<Class<? extends ServerProtocol>> classSet = getServerProtocolClasses(protocolName); if (classSet.isEmpty()) { throw new IllegalArgumentException("Unknkown Server Protocol: " + protocolName); } Class<? extends ServerProtocol> desiredClass = desiredServerProtocolClassMap.get(protocolName); if (desiredClass == null && classSet.size() > 1) { throw new IllegalStateException("Multiple implementations of Server Protocol " + protocolName + " were found and no preferred implementation has been specified"); } if (desiredClass != null && !classSet.contains(desiredClass)) { throw new IllegalStateException("Desired implementation of Server Protocol " + protocolName + " is set to " + desiredClass + ", but that Protocol is not registered as a Server Protocol"); } if (desiredClass == null) { desiredClass = classSet.iterator().next(); } try { return desiredClass.newInstance(); } catch (final Exception e) { throw new RuntimeException("Unable to instantiate class " + desiredClass.getName(), e); } }
} else { RemoteResourceManager.setServerProtocolImplementation(SocketFlowFileServerProtocol.RESOURCE_NAME, SocketFlowFileServerProtocol.class);
public static FlowFileCodec createCodec(final String codecName, final int version) { final FlowFileCodec codec = createCodec(codecName); final VersionNegotiator negotiator = codec.getVersionNegotiator(); if (!negotiator.isVersionSupported(version)) { throw new IllegalArgumentException("FlowFile Codec " + codecName + " does not support version " + version); } negotiator.setVersion(version); return codec; }
public static ClientProtocol createClientProtocol(final String protocolName) { final Set<Class<? extends ClientProtocol>> classSet = getClientProtocolClasses(protocolName); if (classSet.isEmpty()) { throw new IllegalArgumentException("Unknkown Client Protocol: " + protocolName); } Class<? extends ClientProtocol> desiredClass = desiredClientProtocolClassMap.get(protocolName); if (desiredClass == null && classSet.size() > 1) { throw new IllegalStateException("Multiple implementations of Client Protocol " + protocolName + " were found and no preferred implementation has been specified"); } if (desiredClass != null && !classSet.contains(desiredClass)) { throw new IllegalStateException("Desired implementation of Client Protocol " + protocolName + " is set to " + desiredClass + ", but that Protocol is not registered as a Client Protocol"); } if (desiredClass == null) { desiredClass = classSet.iterator().next(); } try { return desiredClass.newInstance(); } catch (final Exception e) { throw new RuntimeException("Unable to instantiate class " + desiredClass.getName(), e); } } }
public static ServerProtocol createServerProtocol(final String protocolName) { final Set<Class<? extends ServerProtocol>> classSet = getServerProtocolClasses(protocolName); if (classSet.isEmpty()) { throw new IllegalArgumentException("Unknkown Server Protocol: " + protocolName); } Class<? extends ServerProtocol> desiredClass = desiredServerProtocolClassMap.get(protocolName); if (desiredClass == null && classSet.size() > 1) { throw new IllegalStateException("Multiple implementations of Server Protocol " + protocolName + " were found and no preferred implementation has been specified"); } if (desiredClass != null && !classSet.contains(desiredClass)) { throw new IllegalStateException("Desired implementation of Server Protocol " + protocolName + " is set to " + desiredClass + ", but that Protocol is not registered as a Server Protocol"); } if (desiredClass == null) { desiredClass = classSet.iterator().next(); } try { return desiredClass.newInstance(); } catch (final Exception e) { throw new RuntimeException("Unable to instantiate class " + desiredClass.getName(), e); } }
public static boolean isCodecSupported(final String codecName, final int version) { if (!isCodecSupported(codecName)) { return false; } final FlowFileCodec codec = createCodec(codecName); final VersionNegotiator negotiator = codec.getVersionNegotiator(); return (negotiator.isVersionSupported(version)); }
@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 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 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); } }
public static List<Integer> getSupportedVersions(final String codecName) { final FlowFileCodec codec = createCodec(codecName); return codec.getSupportedVersions(); }
public static FlowFileCodec createCodec(final String codecName, final int version) { final FlowFileCodec codec = createCodec(codecName); final VersionNegotiator negotiator = codec.getVersionNegotiator(); if (!negotiator.isVersionSupported(version)) { throw new IllegalArgumentException("FlowFile Codec " + codecName + " does not support version " + version); } negotiator.setVersion(version); return codec; }
@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); } }