Search in sources :

Example 66 with RowProducer

use of org.pentaho.di.trans.RowProducer in project pdi-dataservice-server-plugin by pentaho.

the class CachedServiceLoader method replay.

ListenableFuture<Integer> replay(DataServiceExecutor dataServiceExecutor) throws KettleException {
    final Trans serviceTrans = dataServiceExecutor.getServiceTrans(), genTrans = dataServiceExecutor.getGenTrans();
    final CountDownLatch startReplay = new CountDownLatch(1);
    final RowProducer rowProducer = dataServiceExecutor.addRowProducer();
    List<Runnable> startTrans = dataServiceExecutor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.START), postOptimization = dataServiceExecutor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.READY);
    Iterables.removeIf(postOptimization, Predicates.instanceOf(DefaultTransWiring.class));
    Iterables.removeIf(startTrans, new Predicate<Runnable>() {

        @Override
        public boolean apply(Runnable runnable) {
            return runnable instanceof TransStarter && ((TransStarter) runnable).getTrans().equals(serviceTrans);
        }
    });
    postOptimization.add(new Runnable() {

        @Override
        public void run() {
            serviceTrans.stopAll();
            for (StepMetaDataCombi stepMetaDataCombi : serviceTrans.getSteps()) {
                stepMetaDataCombi.step.setOutputDone();
                stepMetaDataCombi.step.dispose(stepMetaDataCombi.meta, stepMetaDataCombi.data);
                stepMetaDataCombi.step.markStop();
            }
        }
    });
    startTrans.add(new Runnable() {

        @Override
        public void run() {
            startReplay.countDown();
        }
    });
    ListenableFutureTask<Integer> replay = ListenableFutureTask.create(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            Preconditions.checkState(startReplay.await(30, TimeUnit.SECONDS), "Cache replay did not start");
            int rowCount = 0;
            for (Iterator<RowMetaAndData> iterator = rowSupplier.get(); iterator.hasNext() && genTrans.isRunning(); ) {
                RowMetaAndData metaAndData = iterator.next();
                boolean rowAdded = false;
                RowMetaInterface rowMeta = metaAndData.getRowMeta();
                Object[] rowData = rowMeta.cloneRow(metaAndData.getData());
                while (!rowAdded && genTrans.isRunning()) {
                    rowAdded = rowProducer.putRowWait(rowMeta, rowData, 10, TimeUnit.SECONDS);
                }
                if (rowAdded) {
                    rowCount += 1;
                }
            }
            rowProducer.finished();
            return rowCount;
        }
    });
    executor.execute(replay);
    return replay;
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) CountDownLatch(java.util.concurrent.CountDownLatch) KettleException(org.pentaho.di.core.exception.KettleException) TransStarter(org.pentaho.di.trans.dataservice.execution.TransStarter) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Iterator(java.util.Iterator) Trans(org.pentaho.di.trans.Trans) DefaultTransWiring(org.pentaho.di.trans.dataservice.execution.DefaultTransWiring)

Aggregations

RowProducer (org.pentaho.di.trans.RowProducer)66 Trans (org.pentaho.di.trans.Trans)58 StepInterface (org.pentaho.di.trans.step.StepInterface)57 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)56 StepMeta (org.pentaho.di.trans.step.StepMeta)51 RowStepCollector (org.pentaho.di.trans.RowStepCollector)50 TransHopMeta (org.pentaho.di.trans.TransHopMeta)49 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)48 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)47 TransMeta (org.pentaho.di.trans.TransMeta)47 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)45 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)35 Test (org.junit.Test)22 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)12 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)9 KettleException (org.pentaho.di.core.exception.KettleException)7 UniqueRowsMeta (org.pentaho.di.trans.steps.uniquerows.UniqueRowsMeta)7 ArrayList (java.util.ArrayList)5 Database (org.pentaho.di.core.database.Database)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3