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(); }
@Override public String getDistinguishedName() { return commsSession.getUserDn(); }
@Override public void close() throws IOException { taskExecutor.shutdown(); peerSelector.clear(); for (final HttpClientTransaction transaction : activeTransactions) { transaction.getCommunicant().getCommunicationsSession().interrupt(); } } }
@Override public void shutdown(final Peer peer) throws IOException { readyForFileTransfer = false; final CommunicationsSession commsSession = peer.getCommunicationsSession(); final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream()); logger.debug("{} Shutting down with {}", this, peer); // Indicate that we would like to have some data RequestType.SHUTDOWN.writeRequestType(dos); dos.flush(); }
String remoteDn = commsSession.getUserDn(); if (remoteDn == null) { remoteDn = "none"; final long startNanos = System.nanoTime(); String calculatedCRC = ""; OutputStream os = new DataOutputStream(commsSession.getOutput().getOutputStream()); while (continueTransaction) { final boolean useGzip = handshakeProperties.isUseGzip();
commsSession.setTimeout(timeoutMillis); final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream()); final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream());
final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream()); final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream()); try { logger.debug("{} Negotiating protocol", this); } catch (final HandshakeException e) { try { commsSession.close(); } catch (final IOException ioe) { throw e; if (commsSession != null) { try { commsSession.close(); } catch (final IOException ioe) {
protected Response readTransactionResponse(boolean isTransfer, CommunicationsSession commsSession) throws IOException { final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream()); return Response.read(dis); }
@Override public String createTransitUri(String sourceFlowFileIdentifier) { return commsSession.createTransitUri(url, sourceFlowFileIdentifier); } }
try { transactionUrl = apiClient.initiateTransaction(direction, portId); commSession.setUserDn(apiClient.getTrustedPeerDn()); } catch (final Exception e) { apiClient.close();
@Override public HttpRequest generateRequest() throws IOException, HttpException { // Pass the output stream so that Site-to-Site client thread can send // data packet through this connection. logger.debug("sending data to {} has started...", flowFilesPath); ((HttpOutput) commSession.getOutput()).setOutputStream(outputStream); initConnectionLatch.countDown(); final BasicHttpEntity entity = new BasicHttpEntity(); entity.setChunked(true); entity.setContentType("application/octet-stream"); post.setEntity(entity); return post; }
String remoteDn = commsSession.getUserDn(); if (remoteDn == null) { remoteDn = "none"; final long startNanos = System.nanoTime(); String calculatedCRC = ""; OutputStream os = new DataOutputStream(commsSession.getOutput().getOutputStream()); while (continueTransaction) { final boolean useGzip = handshakeProperties.isUseGzip();
@Override public RequestType getRequestType(final Peer peer) throws IOException { if (!handshakeCompleted) { throw new IllegalStateException("Handshake has not been completed"); } if (shutdown) { throw new IllegalStateException("Protocol is shutdown"); } logger.debug("{} Reading Request Type from {} using {}", new Object[]{this, peer, peer.getCommunicationsSession()}); final RequestType requestType = RequestType.readRequestType(new DataInputStream(peer.getCommunicationsSession().getInput().getInputStream())); logger.debug("{} Got Request Type {} from {}", new Object[]{this, requestType, peer}); return requestType; }
@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; }
protected void writeTransactionResponse(boolean isTransfer, ResponseCode response, CommunicationsSession commsSession, String explanation) throws IOException { final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream()); if (explanation == null) { response.writeResponse(dos); } else { response.writeResponse(dos, explanation); } }
@Override public void shutdown() { super.shutdown(); requestLock.lock(); try { this.shutdown = true; for (final FlowFileRequest request : activeRequests) { final CommunicationsSession commsSession = request.getPeer().getCommunicationsSession(); if (commsSession != null) { commsSession.interrupt(); } } } finally { requestLock.unlock(); } }