use of org.pentaho.di.trans.step.RowAdapter in project pdi-dataservice-server-plugin by pentaho.
the class StreamingServiceTransExecutor method startService.
/**
* Starts the Service transformation and its row event listener.
*/
private void startService() {
try {
lastCacheCleanupMillis = System.currentTimeMillis();
serviceTrans.startThreads();
StepInterface serviceStep = serviceTrans.findRunThread(serviceStepName);
if (serviceStep == null) {
throw Throwables.propagate(new KettleException("Service step is not accessible"));
}
serviceStep.addRowListener(new RowAdapter() {
/**
* Listener for the service transformation output rows.
* If the stepStream has any valid registered listeners it writes the output row to the stepStream,
* otherwise stops the service transformation and kills its running thread.
*
* @param rowMeta The metadata of the written row.
* @param row The data of the written row.
* @throws KettleStepException
*/
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
// Simply pass along the row to the other transformation (to the Injector step)
LogChannelInterface log = serviceTrans.getLogChannel();
try {
if (log.isRowLevel()) {
log.logRowlevel(DataServiceConstants.PASSING_ALONG_ROW + rowMeta.getString(row));
}
} catch (KettleValueException e) {
// Ignore error
}
serviceCacheCleanup();
if (serviceListeners.size() > 0) {
RowMetaAndData rowData = new RowMetaAndData();
rowData.setRowMeta(rowMeta);
rowData.setData(row);
stepStream.add(rowData);
} else if (isRunning.compareAndSet(true, false)) {
serviceTrans.stopAll();
stepStream = null;
log.logDetailed(DataServiceConstants.STREAMING_TRANSFORMATION_STOPPED);
}
}
});
} catch (KettleException e) {
throw Throwables.propagate(e);
}
}
use of org.pentaho.di.trans.step.RowAdapter in project pdi-dataservice-server-plugin by pentaho.
the class ServiceObserverTest method cloneErrorIsPropogated.
@Test
public void cloneErrorIsPropogated() throws KettleValueException, ExecutionException, InterruptedException, KettleStepException {
when(rowMeta.cloneRow(row)).thenThrow(exception);
observer.run();
verify(stepInterface).addRowListener(rowAdapterCaptor.capture());
RowAdapter rowAdapter = rowAdapterCaptor.getValue();
rowAdapter.rowWrittenEvent(rowMeta, row);
try {
observer.get();
fail("Expected exception");
} catch (Exception e) {
assertThat(e.getCause(), is(exception));
}
}
use of org.pentaho.di.trans.step.RowAdapter in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceExecutor method executeQuery.
public DataServiceExecutor executeQuery(final DataOutputStream dos) throws IOException {
writeMetadata(dos, getServiceName(), calculateTransname(getSql(), true), getServiceTrans().getContainerObjectId(), calculateTransname(getSql(), false), getGenTrans().getContainerObjectId());
final AtomicBoolean rowMetaWritten = new AtomicBoolean(false);
// When done, check if no row metadata was written. The client is still going to expect it...
// Since we know it, we'll pass it.
//
getGenTrans().addTransListener(new TransAdapter() {
@Override
public void transFinished(Trans trans) throws KettleException {
if (rowMetaWritten.compareAndSet(false, true)) {
RowMetaInterface stepFields = trans.getTransMeta().getStepFields(getResultStepName());
stepFields.writeMeta(dos);
}
}
});
// Now execute the query transformation(s) and pass the data to the output stream...
return executeQuery(new RowAdapter() {
@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
//
try {
if (rowMetaWritten.compareAndSet(false, true)) {
rowMeta.writeMeta(dos);
}
rowMeta.writeData(dos, row);
} catch (Exception e) {
if (!getServiceTrans().isStopped()) {
throw new KettleStepException(e);
}
}
}
});
}
use of org.pentaho.di.trans.step.RowAdapter in project pdi-dataservice-server-plugin by pentaho.
the class ServiceObserver method run.
@Override
public void run() {
StepInterface serviceStep = executor.getServiceTrans().findRunThread(executor.getService().getStepname());
serviceStep.addRowListener(new RowAdapter() {
@Override
public synchronized void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) {
Object[] clonedRow;
try {
clonedRow = rowMeta.cloneRow(row);
} catch (KettleValueException e) {
setException(e);
return;
}
rowMetaAndData.add(new RowMetaAndData(rowMeta, clonedRow));
latch.countDown();
}
});
serviceStep.addStepListener(new StepAdapter() {
@Override
public void stepFinished(Trans trans, StepMeta stepMeta, StepInterface step) {
isRunning = false;
if (executor.getGenTrans().getErrors() > 0) {
setException(new KettleException("Dynamic transformation finished with errors, could not cache results"));
} else if (step.isStopped()) {
set(CachedService.partial(rowMetaAndData, executor));
} else {
set(CachedService.complete(rowMetaAndData));
}
}
});
}
Aggregations