tmf: Add an ID to each state system that gets built
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statesystem / StateSystemManager.java
index 3af75ee28f050ba9ef56b9bd7c4fa7a80264c357..f7a62c20434627192d38a7760e3403c484d7e342 100644 (file)
@@ -2,12 +2,12 @@
  * Copyright (c) 2012 Ericsson
  * Copyright (c) 2010, 2011 École Polytechnique de Montréal
  * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
- * 
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.statesystem;
@@ -15,26 +15,19 @@ package org.eclipse.linuxtools.tmf.core.statesystem;
 import java.io.File;
 import java.io.IOException;
 
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.HistoryBuilder;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.IStateHistoryBackend;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree.HistoryTreeBackend;
 import org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree.ThreadedHistoryTreeBackend;
 import org.eclipse.linuxtools.tmf.core.component.TmfComponent;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
-import org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 
 /**
  * This abstract manager class handles loading or creating state history files
  * for use in TMF's generic state system.
- * 
- * @author alexmont
- * 
+ *
+ * @version 1.0
+ * @author Alexandre Montplaisir
  */
 public abstract class StateSystemManager extends TmfComponent {
 
@@ -46,7 +39,7 @@ public abstract class StateSystemManager extends TmfComponent {
      * exists, it will be opened directly. If not, it will be created from
      * scratch. In the case the history has to be built, it's possible to block
      * the calling thread until construction is complete.
-     * 
+     *
      * @param htFile
      *            The target name of the history file we want to use. If it
      *            exists it will be opened. If it doesn't, a new file will be
@@ -55,17 +48,26 @@ public abstract class StateSystemManager extends TmfComponent {
      *            The IStateChangeInput to use for building the history file. It
      *            may be required even if we are opening an already-existing
      *            history (ie, for partial histories).
-     * @param waitForCompletion
-     *            Should we block the calling thread until the construction is
-     *            complete? It has no effect if the file already exists.
+     * @param id
+     *            The ID, or name, to give to the state system we will build.
+     *            The signal that when be sent when the construction is finished
+     *            will carry this ID. It has no effect if the file already
+     *            exists.
+     * @param buildManually
+     *            If false, the construction will wait for a signal before
+     *            starting. If true, it will build everything right now and
+     *            block the caller. It has no effect if the file already exists.
      * @return A IStateSystemQuerier handler to the state system, with which you
      *         can then run queries on the history.
      * @throws TmfTraceException
+     *             If there was a problem reading or writing one of the files.
+     *             See the contents of this exception for more info.
+     * @since 2.0
      */
-    public static IStateSystemQuerier loadStateHistory(File htFile,
-            IStateChangeInput htInput, boolean waitForCompletion)
+    public static ITmfStateSystem loadStateHistory(File htFile,
+            IStateChangeInput htInput, String id, boolean buildManually)
             throws TmfTraceException {
-        IStateSystemQuerier ss;
+        ITmfStateSystem ss;
         IStateHistoryBackend htBackend;
 
         /* If the target file already exists, do not rebuild it uselessly */
@@ -95,7 +97,7 @@ public abstract class StateSystemManager extends TmfComponent {
         try {
             htBackend = new ThreadedHistoryTreeBackend(htFile,
                     htInput.getStartTime(), QUEUE_SIZE);
-            builder = new HistoryBuilder(htInput, htBackend);
+            builder = new HistoryBuilder(htInput, htBackend, id, buildManually);
         } catch (IOException e) {
             /*
              * If it fails here however, it means there was a problem writing to
@@ -103,35 +105,6 @@ public abstract class StateSystemManager extends TmfComponent {
              */
             throw new TmfTraceException(e.toString(), e);
         }
-        startBuilderJob(builder, htInput.getTrace(), waitForCompletion);
         return builder.getStateSystemQuerier();
     }
-
-    private static void startBuilderJob(final HistoryBuilder builder,
-            final ITmfTrace<?> trace, boolean waitForCompletion) {
-
-        final Job job = new Job("Building state history for " +
-                trace.getName() + "...") { //$NON-NLS-1$
-            @Override
-            protected IStatus run(final IProgressMonitor monitor) {
-                builder.run();
-                monitor.done();
-
-                /* Broadcast the signal saying the history is done building */
-                TmfSignalManager.dispatchSignal(new TmfStateSystemBuildCompleted(
-                        this, trace));
-
-                return Status.OK_STATUS;
-            }
-        };
-
-        job.schedule();
-        if (waitForCompletion) {
-            try {
-                job.join();
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-        }
-    }
 }
This page took 0.027737 seconds and 5 git commands to generate.