Search in sources :

Example 1 with LocalClassLoader

use of edu.iu.dsc.tws.local.util.LocalClassLoader in project twister2 by DSC-SPIDAL.

the class LocalSubmitter method startWorker.

/**
 * This method starts a new worker instance on a separate thread.
 */
private static Thread startWorker(Twister2Job twister2Job, Config config, int workerId, CyclicBarrier cyclicBarrier) {
    Thread.UncaughtExceptionHandler hndler = (th, ex) -> {
        failed = true;
        fault = ex;
    };
    LocalClassLoader localClassLoader = new LocalClassLoader(LocalSubmitter.class.getClassLoader());
    localClassLoader.addJobClass(twister2Job.getWorkerClass());
    try {
        Object o = localClassLoader.loadClass(MockWorker.class.getName()).getConstructor(twister2Job.getClass(), config.getClass(), Integer.class, CyclicBarrier.class).newInstance(twister2Job, config, workerId, cyclicBarrier);
        Thread thread = new Thread((Runnable) o);
        thread.setName("worker-" + workerId);
        thread.setUncaughtExceptionHandler(hndler);
        thread.start();
        return thread;
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new Twister2RuntimeException("Failed to start the worker thread", e);
    }
}
Also used : Twister2Job(edu.iu.dsc.tws.api.Twister2Job) CyclicBarrier(java.util.concurrent.CyclicBarrier) Files(java.nio.file.Files) Twister2JobState(edu.iu.dsc.tws.api.scheduler.Twister2JobState) LogManager(java.util.logging.LogManager) IOException(java.io.IOException) Config(edu.iu.dsc.tws.api.config.Config) FileInputStream(java.io.FileInputStream) UUID(java.util.UUID) Logger(java.util.logging.Logger) File(java.io.File) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) List(java.util.List) DriverJobState(edu.iu.dsc.tws.api.driver.DriverJobState) LocalClassLoader(edu.iu.dsc.tws.local.util.LocalClassLoader) FileConstants(edu.iu.dsc.tws.local.util.FileConstants) MockWorker(edu.iu.dsc.tws.local.mock.MockWorker) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CyclicBarrier(java.util.concurrent.CyclicBarrier) MockWorker(edu.iu.dsc.tws.local.mock.MockWorker) LocalClassLoader(edu.iu.dsc.tws.local.util.LocalClassLoader)

Aggregations

Twister2Job (edu.iu.dsc.tws.api.Twister2Job)1 Config (edu.iu.dsc.tws.api.config.Config)1 DriverJobState (edu.iu.dsc.tws.api.driver.DriverJobState)1 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)1 Twister2JobState (edu.iu.dsc.tws.api.scheduler.Twister2JobState)1 MockWorker (edu.iu.dsc.tws.local.mock.MockWorker)1 FileConstants (edu.iu.dsc.tws.local.util.FileConstants)1 LocalClassLoader (edu.iu.dsc.tws.local.util.LocalClassLoader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Level (java.util.logging.Level)1 LogManager (java.util.logging.LogManager)1 Logger (java.util.logging.Logger)1