@Override public String toString() { return "Standard FlowFile Codec, Version " + versionNegotiator.getVersion(); }
@Override public Transaction startTransaction(final Peer peer, final FlowFileCodec codec, final TransferDirection direction) throws IOException, ProtocolException { if (!handshakeComplete) { throw new IllegalStateException("Handshake has not been performed"); } if (!readyForFileTransfer) { throw new IllegalStateException("Cannot start transaction; handshake resolution was " + handshakeResponse); } return new SocketClientTransaction(versionNegotiator.getVersion(), destination.getIdentifier(), peer, codec, direction, useCompression, (int) destination.getYieldPeriod(TimeUnit.MILLISECONDS), eventReporter); }
@Override public Set<PeerStatus> getPeerStatuses(final Peer peer) throws IOException { if (!handshakeComplete) { throw new IllegalStateException("Handshake has not been performed"); } logger.debug("{} Get Peer Statuses from {}", this, peer); final CommunicationsSession commsSession = peer.getCommunicationsSession(); final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream()); final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream()); final boolean queryPeersForOtherPeers = getVersionNegotiator().getVersion() >= 6; RequestType.REQUEST_PEER_LIST.writeRequestType(dos); dos.flush(); final int numPeers = dis.readInt(); final Set<PeerStatus> peers = new HashSet<>(numPeers); for (int i = 0; i < numPeers; i++) { final String hostname = dis.readUTF(); final int port = dis.readInt(); final boolean secure = dis.readBoolean(); final int flowFileCount = dis.readInt(); peers.add(new PeerStatus(new PeerDescription(hostname, port, secure), flowFileCount, queryPeersForOtherPeers)); } logger.debug("{} Received {} Peer Statuses from {}", this, peers.size(), peer); return peers; }
dos.writeUTF(resource.getResourceName()); final VersionNegotiator negotiator = resource.getVersionNegotiator(); dos.writeInt(negotiator.getVersion()); dos.flush();
private CommsSession leaseCommsSession() throws IOException { CommsSession session = queue.poll(); if (session != null && !session.isClosed()) { return session; } session = createCommsSession(configContext); final VersionNegotiator versionNegotiator = new StandardVersionNegotiator(1); try { ProtocolHandshake.initiateHandshake(session.getInputStream(), session.getOutputStream(), versionNegotiator); session.setProtocolVersion(versionNegotiator.getVersion()); } catch (final HandshakeException e) { IOUtils.closeQuietly(session); throw new IOException(e); } return session; }
if (versionNegotiator.getVersion() >= 5) { if (batchCount > 0) { properties.put(HandshakeProperty.BATCH_COUNT, String.valueOf(batchCount)); if (versionNegotiator.getVersion() >= 3) { dos.writeUTF(peer.getUrl()); transitUriPrefix = peer.getUrl();
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"); } }
private CommsSession leaseCommsSession() throws IOException { CommsSession session = queue.poll(); if (session != null && !session.isClosed()) { return session; } session = createCommsSession(configContext); final VersionNegotiator versionNegotiator = new StandardVersionNegotiator(3, 2, 1); try { ProtocolHandshake.initiateHandshake(session.getInputStream(), session.getOutputStream(), versionNegotiator); session.setProtocolVersion(versionNegotiator.getVersion()); } catch (final HandshakeException e) { try { session.close(); } catch (final IOException ioe) { } throw new IOException(e); } return session; }
if (versionNegotiator.getVersion() >= 3) { String transitUriPrefix = dis.readUTF(); if (!transitUriPrefix.endsWith("/")) {
if (clientProtocol.getVersionNegotiator().getVersion() < 5) { String portId = getPortIdentifier(TransferDirection.RECEIVE); if (portId == null) {
if (getVersionNegotiator().getVersion() > 1) { for (final Connection connection : port.getConnections()) { if (connection.getFlowFileQueue().isFull()) {
final String receivedCRC = transactionConfirmationResponse.getMessage(); if (getVersionNegotiator().getVersion() > 3) { String calculatedCRC = transaction.getCalculatedCRC(); if (!receivedCRC.equals(calculatedCRC)) {
private CommsSession leaseCommsSession() throws IOException { CommsSession session = queue.poll(); if (session != null && !session.isClosed()) { return session; } session = createCommsSession(configContext); final VersionNegotiator versionNegotiator = new StandardVersionNegotiator(1); try { ProtocolHandshake.initiateHandshake(session.getInputStream(), session.getOutputStream(), versionNegotiator); session.setProtocolVersion(versionNegotiator.getVersion()); } catch (final HandshakeException e) { IOUtils.closeQuietly(session); throw new IOException(e); } return session; }
private CommsSession leaseCommsSession() throws IOException { CommsSession session = queue.poll(); if (session != null && !session.isClosed()) { return session; } session = createCommsSession(configContext); final VersionNegotiator versionNegotiator = new StandardVersionNegotiator(3, 2, 1); try { ProtocolHandshake.initiateHandshake(session.getInputStream(), session.getOutputStream(), versionNegotiator); session.setProtocolVersion(versionNegotiator.getVersion()); } catch (final HandshakeException e) { try { session.close(); } catch (final IOException ioe) { } throw new IOException(e); } return session; }
if (versionNegotiator.getVersion() >= 3) { String transitUriPrefix = dis.readUTF(); if (!transitUriPrefix.endsWith("/")) {
if (getVersionNegotiator().getVersion() > 1) { for (final Connection connection : port.getConnections()) { if (connection.getFlowFileQueue().isFull()) {
final String receivedCRC = transactionConfirmationResponse.getMessage(); if (getVersionNegotiator().getVersion() > 3) { String calculatedCRC = transaction.getCalculatedCRC(); if (!receivedCRC.equals(calculatedCRC)) {