@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); }
SocketClientTransaction(final int protocolVersion, final String destinationId, final Peer peer, final FlowFileCodec codec, final TransferDirection direction, final boolean useCompression, final int penaltyMillis, final EventReporter eventReporter) throws IOException { super(peer, direction, useCompression, codec, eventReporter, protocolVersion, penaltyMillis, destinationId); this.dis = new DataInputStream(peer.getCommunicationsSession().getInput().getInputStream()); this.dos = new DataOutputStream(peer.getCommunicationsSession().getOutput().getOutputStream()); initialize(); }
private void initialize() throws IOException { try { if (direction == TransferDirection.RECEIVE) { // Indicate that we would like to have some data RequestType.RECEIVE_FLOWFILES.writeRequestType(dos); dos.flush(); final Response dataAvailableCode = Response.read(dis); switch (dataAvailableCode.getCode()) { case MORE_DATA: logger.debug("{} {} Indicates that data is available", this, peer); this.dataAvailable = true; break; case NO_MORE_DATA: logger.debug("{} No data available from {}", peer); this.dataAvailable = false; return; default: throw new ProtocolException("Got unexpected response when asking for data: " + dataAvailableCode); } } else { // Indicate that we would like to have some data RequestType.SEND_FLOWFILES.writeRequestType(dos); dos.flush(); } } catch (final Exception e) { error(); throw e; } }