--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * MinKee Lee <minkee.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.job;
+
+interface Job {
+ public void work();
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * MinKee Lee <minkee.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.job;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.logging.Level;
+
+import org.tizen.emulator.manager.logging.EMLogger;
+
+public class Overseer {
+ private final List<Class<? extends Job>> jobClasses = new ArrayList<Class<? extends Job>>();
+ private Thread overseerThread;
+ private CountDownLatch doneSignal;
+
+ private Overseer() {};
+
+ protected void startWorkInternal() throws InterruptedException {
+ doneSignal = new CountDownLatch(jobClasses.size());
+
+ for (Class<? extends Job> jobCls : jobClasses) {
+ new Thread(new JobRunnable(doneSignal, jobCls)).start();
+ }
+
+ doneSignal.await();
+ }
+
+ public void registerJob(Class<? extends Job> jobCls) {
+ jobClasses.add(jobCls);
+ }
+
+ @SafeVarargs
+ public static Overseer newOverseer(Class<? extends Job>... jobClasses) {
+ Overseer overseer = new Overseer();
+
+ for (Class<? extends Job> jobCls: jobClasses) {
+ overseer.registerJob(jobCls);
+ }
+
+ return overseer;
+ }
+
+ public void startWork() throws InterruptedException {
+ EMLogger.getLogger().log(Level.INFO, "is starting...");
+ if (overseerThread != null) {
+ // already started
+ assert false : "Already started !!!"; // for debugging...
+
+ return;
+ }
+
+ overseerThread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Overseer.this.startWorkInternal();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ overseerThread.start();
+ }
+
+ public void join() throws InterruptedException {
+ if (overseerThread == null) {
+ return;
+ }
+
+ if (overseerThread.isAlive()) {
+ overseerThread.join();
+
+ return;
+ }
+ }
+}
+
+class JobRunnable implements Runnable {
+ private final CountDownLatch doneSignal;
+ private final Class<? extends Job> jobCls;
+
+ JobRunnable(CountDownLatch doneSignal, Class<? extends Job> jobCls) {
+ this.doneSignal = doneSignal;
+ this.jobCls = jobCls;
+ }
+
+ @Override
+ public void run() {
+ Job job = null;
+ try {
+ job = jobCls.newInstance();
+ job.work();
+ doneSignal.countDown();
+ } catch (InstantiationException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+}