/*******************************************************************************
- * Copyright (c) 2009, 2013 Ericsson
+ * Copyright (c) 2009, 2013 Ericsson, École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* Francois Chouinard - Updated as per TMF Trace Model 1.0
* Patrick Tasse - Updated for removal of context clone
* Patrick Tasse - Updated for ranks in experiment location
+ * Geneviève Bastien - Added support of experiment synchronization
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.trace;
+import java.io.File;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext;
import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation;
import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSynchronizedSignal;
+import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationAlgorithm;
+import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationManager;
import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
// Constants
// ------------------------------------------------------------------------
+ /**
+ * The file name of the Synchronization
+ *
+ * @since 3.0
+ */
+ public final static String SYNCHRONIZATION_FILE_NAME = "synchronization.bin"; //$NON-NLS-1$
+
/**
* The default index page size
*/
// ------------------------------------------------------------------------
/**
- * @param type the event type
- * @param id the experiment id
- * @param traces the experiment set of traces
+ * @param type
+ * the event type
+ * @param id
+ * the experiment id
+ * @param traces
+ * the experiment set of traces
*/
public TmfExperiment(final Class<? extends ITmfEvent> type, final String id, final ITmfTrace[] traces) {
this(type, id, traces, DEFAULT_INDEX_PAGE_SIZE, null);
this(type, id, traces, DEFAULT_INDEX_PAGE_SIZE, resource);
}
-
/**
- * @param type the event type
- * @param path the experiment path
- * @param traces the experiment set of traces
- * @param indexPageSize the experiment index page size
+ * @param type
+ * the event type
+ * @param path
+ * the experiment path
+ * @param traces
+ * the experiment set of traces
+ * @param indexPageSize
+ * the experiment index page size
*/
public TmfExperiment(final Class<? extends ITmfEvent> type, final String path, final ITmfTrace[] traces, final int indexPageSize) {
this(type, path, traces, indexPageSize, null);
}
fTraces = traces;
+
+ if (resource != null) {
+ try {
+ this.synchronizeTraces();
+ } catch (TmfTraceException e) {
+ Activator.logError("Error synchronizing experiment", e); //$NON-NLS-1$
+ }
+ }
}
/**
* Returns the timestamp of the event at the requested index. If none,
* returns null.
*
- * @param index the event index (rank)
+ * @param index
+ * the event index (rank)
* @return the corresponding event timestamp
* @since 2.0
*/
/**
* Set the file to be used for bookmarks on this experiment
*
- * @param file the bookmarks file
+ * @param file
+ * the bookmarks file
*/
public void setBookmarksFile(final IFile file) {
fBookmarksFile = file;
}
if (request instanceof ITmfEventRequest
- && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
- && request.getIndex() == 0)
+ && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
+ && request.getIndex() == 0)
{
final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
((ITmfEventRequest) request).setStartIndex((int) context.getRank());
TmfExperimentContext expContext = (TmfExperimentContext) context;
- // If an event was consumed previously, first get the next one from that trace
+ // If an event was consumed previously, first get the next one from that
+ // trace
final int lastTrace = expContext.getLastTrace();
if (lastTrace != TmfExperimentContext.NO_TRACE) {
final ITmfContext traceContext = expContext.getContexts()[lastTrace];
return initTs;
}
+ /**
+ * Synchronizes the traces of an experiment. By default it only tries to
+ * read a synchronization file if it exists
+ *
+ * @return The synchronization object
+ * @throws TmfTraceException
+ * propagate TmfTraceExceptions
+ * @since 3.0
+ */
+ public synchronized SynchronizationAlgorithm synchronizeTraces() throws TmfTraceException {
+ return synchronizeTraces(false);
+ }
+
+ /**
+ * Synchronizes the traces of an experiment.
+ *
+ * @param doSync
+ * Whether to actually synchronize or just try opening a sync
+ * file
+ * @return The synchronization object
+ * @throws TmfTraceException
+ * propagate TmfTraceExceptions
+ * @since 3.0
+ */
+ public synchronized SynchronizationAlgorithm synchronizeTraces(boolean doSync) throws TmfTraceException {
+
+ /* Set up the path to the synchronization file we'll use */
+ IResource resource = this.getResource();
+ String supplDirectory = null;
+
+ try {
+ /* get the directory where the file will be stored. */
+ if (resource != null) {
+ supplDirectory = resource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
+ }
+ } catch (CoreException e) {
+ throw new TmfTraceException(e.toString(), e);
+ }
+
+ final File syncFile = (supplDirectory != null) ? new File(supplDirectory + File.separator + SYNCHRONIZATION_FILE_NAME) : null;
+
+ final SynchronizationAlgorithm syncAlgo = SynchronizationManager.synchronizeTraces(syncFile, fTraces, doSync);
+
+ final TmfTraceSynchronizedSignal signal = new TmfTraceSynchronizedSignal(this, syncAlgo);
+
+ /* Broadcast in separate thread to prevent deadlock */
+ new Thread() {
+ @Override
+ public void run() {
+ broadcast(signal);
+ }
+ }.start();
+
+ return syncAlgo;
+ }
+
@Override
@SuppressWarnings("nls")
public synchronized String toString() {