Search in sources :

Example 1 with Worker

use of co.cask.cdap.api.worker.Worker in project cdap by caskdata.

the class WorkerDriver method startUp.

@Override
protected void startUp() throws Exception {
    LoggingContextAccessor.setLoggingContext(context.getLoggingContext());
    // Instantiate worker instance
    Class<?> workerClass = program.getClassLoader().loadClass(spec.getClassName());
    @SuppressWarnings("unchecked") TypeToken<Worker> workerType = (TypeToken<Worker>) TypeToken.of(workerClass);
    worker = new InstantiatorFactory(false).get(workerType).create();
    // Fields injection
    Reflections.visit(worker, workerType.getType(), new MetricsFieldSetter(context.getMetrics()), new PropertyFieldSetter(spec.getProperties()));
    LOG.debug("Starting Worker Program {}", program.getId());
    // Initialize worker
    TransactionControl txControl = Transactions.getTransactionControl(TransactionControl.EXPLICIT, Worker.class, worker, "initialize", WorkerContext.class);
    try {
        context.initializeProgram(worker, context, txControl, false);
    } catch (LinkageError e) {
        // of the user program is missing dependencies (CDAP-2543)
        throw new Exception(e.getMessage(), e);
    }
}
Also used : InstantiatorFactory(co.cask.cdap.common.lang.InstantiatorFactory) PropertyFieldSetter(co.cask.cdap.common.lang.PropertyFieldSetter) MetricsFieldSetter(co.cask.cdap.internal.app.runtime.MetricsFieldSetter) TypeToken(com.google.common.reflect.TypeToken) TransactionControl(co.cask.cdap.api.annotation.TransactionControl) Worker(co.cask.cdap.api.worker.Worker)

Aggregations

TransactionControl (co.cask.cdap.api.annotation.TransactionControl)1 Worker (co.cask.cdap.api.worker.Worker)1 InstantiatorFactory (co.cask.cdap.common.lang.InstantiatorFactory)1 PropertyFieldSetter (co.cask.cdap.common.lang.PropertyFieldSetter)1 MetricsFieldSetter (co.cask.cdap.internal.app.runtime.MetricsFieldSetter)1 TypeToken (com.google.common.reflect.TypeToken)1