@Override public TransactionCompletion complete() throws IOException { try { return transaction.complete(); } finally { final EndpointConnection state = connectionStateRef.get(); if (state != null) { pool.offer(connectionState); connectionStateRef.set(null); } } }
public TransactionCompletion sendFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.SEND); try { DataPacketDto.getDataPacketStream(input).forEachOrdered(d -> { try { transaction.send(d); } catch (IOException e) { throw new RuntimeException(e); } }); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } throw new IOException(e.getMessage(), e); } transaction.confirm(); return transaction.complete(); } }
public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); } }
@Override public void invoke(T value) throws Exception { final NiFiDataPacket niFiDataPacket = builder.createNiFiDataPacket(value, getRuntimeContext()); final Transaction transaction = client.createTransaction(TransferDirection.SEND); if (transaction == null) { throw new IllegalStateException("Unable to create a NiFi Transaction to send data"); } transaction.send(niFiDataPacket.getContent(), niFiDataPacket.getAttributes()); transaction.confirm(); transaction.complete(); }
transaction.complete();
transaction.complete();
transaction.complete();
sendData(context, transaction, attributes, jsonBatchArray); transaction.confirm(); transaction.complete();
transaction.complete();
transaction.complete();
final String dataSize = FormatUtils.formatDataSize(bytesSent); transaction.complete(); session.commit();
public TransactionCompletion sendFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.SEND); try { DataPacketDto.getDataPacketStream(input).forEachOrdered(d -> { try { transaction.send(d); } catch (IOException e) { throw new RuntimeException(e); } }); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } throw new IOException(e.getMessage(), e); } transaction.confirm(); return transaction.complete(); } }
public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); } }
/** * Send the given batch of tuples to NiFi in a transaction, using the provided builder to * first convert each tuple into a NiFiDataPacket. * * @param tuples a list of tuples to process */ protected void processTuples(List<T> tuples) { if (tuples == null || tuples.size() == 0) { return; } // create a transaction and send the data packets try { final Transaction transaction = client.createTransaction(TransferDirection.SEND); if (transaction == null) { throw new IllegalStateException("Unable to create a NiFi Transaction to send data"); } // convert each tuple to a NiFiDataPacket using the provided builder for (T tuple : tuples) { NiFiDataPacket dp = dataPacketBuilder.createNiFiDataPacket(tuple); transaction.send(dp.getContent(), dp.getAttributes()); } transaction.confirm(); transaction.complete(); } catch (IOException ioe) { DTThrowable.rethrow(ioe); } }
/** * Send the given batch of tuples to NiFi in a transaction, using the provided builder to * first convert each tuple into a NiFiDataPacket. * * @param tuples a list of tuples to process */ protected void processTuples(List<T> tuples) { if (tuples == null || tuples.size() == 0) { return; } // create a transaction and send the data packets try { final Transaction transaction = client.createTransaction(TransferDirection.SEND); if (transaction == null) { throw new IllegalStateException("Unable to create a NiFi Transaction to send data"); } // convert each tuple to a NiFiDataPacket using the provided builder for (T tuple : tuples) { NiFiDataPacket dp = dataPacketBuilder.createNiFiDataPacket(tuple); transaction.send(dp.getContent(), dp.getAttributes()); } transaction.confirm(); transaction.complete(); } catch (IOException ioe) { DTThrowable.rethrow(ioe); } }