1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 * Copyright (c) 2010, 2011 École Polytechnique de Montréal
4 * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
6 * All rights reserved. This program and the accompanying materials are
7 * made available under the terms of the Eclipse Public License v1.0 which
8 * accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.statesystem
;
15 import java
.io
.IOException
;
17 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.statesystem
.StateHistorySystem
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
26 * This is the high-level wrapper around the State History and its input and
27 * storage plugins. Just create the object using the constructor then .run()
29 * You can use one HistoryBuilder and it will instantiate everything underneath.
30 * If you need more fine-grained control you can still ignore this and
31 * instantiate everything manually.
36 public class HistoryBuilder
implements Runnable
{
38 private final IStateChangeInput sci
;
39 private final StateHistorySystem shs
;
40 private final IStateHistoryBackend hb
;
43 * Instantiate a new HistoryBuilder helper.
45 * @param stateChangeInput
46 * The input plugin to use. This is required.
48 * The backend storage to use. Use "null" here if you want a
49 * state system with no history.
51 * Is thrown if anything went wrong (usually with the storage
54 public HistoryBuilder(IStateChangeInput stateChangeInput
,
55 IStateHistoryBackend backend
) throws IOException
{
56 if (stateChangeInput
== null || backend
== null) {
57 throw new IllegalArgumentException();
60 sci
= stateChangeInput
;
62 shs
= new StateHistorySystem(hb
, true);
64 sci
.assignTargetStateSystem(shs
);
68 * Factory-style method to open an existing history, you only have to
69 * provide the already-instantiated IStateHistoryBackend object.
72 * The history-backend object
73 * @return A IStateSystemBuilder reference to the new state system. If you
74 * will only run queries on this history, you should *definitely*
75 * cast it to IStateSystemQuerier.
77 * If there was something wrong.
79 public static IStateSystemBuilder
openExistingHistory(
80 IStateHistoryBackend hb
) throws IOException
{
81 return new StateHistorySystem(hb
, false);
86 /* Send a TMF request for all the events in the trace */
87 final ITmfEventRequest
<CtfTmfEvent
> request
;
88 request
= new StateSystemBuildRequest(this);
90 /* Submit the request and wait for completion */
91 sci
.getTrace().sendRequest(request
);
93 request
.waitForCompletion();
94 } catch (InterruptedException e
) {
100 * Return a read/write reference to the state system object that was
103 * @return Reference to the state system, with access to everything.
105 public IStateSystemBuilder
getStateSystemBuilder() {
110 * Return a read-only reference to the state system object that was created.
112 * @return Reference to the state system, but only with the query methods
115 public IStateSystemQuerier
getStateSystemQuerier() {
120 * @name Methods reserved for the request object below
123 /** Get the input plugin object */
124 IStateChangeInput
getInputPlugin() {
128 /** Tell the backend to cleanup if the request is cancelled */
135 class StateSystemBuildRequest
extends TmfEventRequest
<CtfTmfEvent
> {
137 /** The amount of events queried at a time through the requests */
138 private final static int chunkSize
= 50000;
140 private final HistoryBuilder builder
;
141 private final IStateChangeInput sci
;
143 StateSystemBuildRequest(HistoryBuilder builder
) {
144 super((Class
<CtfTmfEvent
>) builder
.getInputPlugin().getExpectedEventType().getClass(),
145 TmfTimeRange
.ETERNITY
, TmfDataRequest
.ALL_DATA
, chunkSize
,
146 ITmfDataRequest
.ExecutionType
.BACKGROUND
);
147 this.builder
= builder
;
148 this.sci
= builder
.getInputPlugin();
152 public void handleData(final CtfTmfEvent event
) {
153 super.handleData(event
);
155 sci
.processEvent(event
);
160 public void handleSuccess() {
165 public void handleCancel() {
171 public void handleCompleted() {
172 super.handleCompleted();