Use the NonNull utility methods where we can
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.core / src / org / eclipse / tracecompass / tmf / ctf / core / trace / CtfTmfTrace.java
CommitLineData
b1baa808 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal
b1baa808
MK
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
ea271da6
PT
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 * Patrick Tasse - Updated for removal of context clone
e73a4ba5 12 * Geneviève Bastien - Added the createTimestamp function
b1baa808
MK
13 *******************************************************************************/
14
9722e5d7 15package org.eclipse.tracecompass.tmf.ctf.core.trace;
a3fc8213 16
5db5a3a4
AM
17import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
18
96c0f2af 19import java.nio.BufferOverflowException;
032ecd45 20import java.nio.ByteBuffer;
409bea20 21import java.util.ArrayList;
f9ff7d40 22import java.util.Collection;
e600c338 23import java.util.Collections;
2db2b43a 24import java.util.HashMap;
409bea20 25import java.util.List;
299e494e 26import java.util.Map;
409bea20 27import java.util.Set;
299e494e 28
a3fc8213
AM
29import org.eclipse.core.resources.IProject;
30import org.eclipse.core.resources.IResource;
6fd3c6e9 31import org.eclipse.core.runtime.CoreException;
a94410d9
MK
32import org.eclipse.core.runtime.IStatus;
33import org.eclipse.core.runtime.Status;
8192209b 34import org.eclipse.jdt.annotation.NonNull;
f357bcd4
AM
35import org.eclipse.tracecompass.ctf.core.event.CTFClock;
36import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
37import org.eclipse.tracecompass.ctf.core.trace.CTFReaderException;
38import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
39import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader;
2bdf0193
AM
40import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator;
41import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
42import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
2bdf0193 43import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
f9ff7d40 44import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
2bdf0193
AM
45import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
46import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
47import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
48import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
49import org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser;
50import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
51import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
52import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
53import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
54import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
55import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
56import org.eclipse.tracecompass.tmf.core.trace.indexer.TmfBTreeTraceIndexer;
57import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
58import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpoint;
59import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
9722e5d7
AM
60import org.eclipse.tracecompass.tmf.ctf.core.CtfConstants;
61import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
62import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
63import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
64import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
65import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType;
f9ff7d40
AM
66import org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfChannelAspect;
67import org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfCpuAspect;
9722e5d7
AM
68import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
69import org.eclipse.tracecompass.tmf.ctf.core.trace.iterator.CtfIterator;
70import org.eclipse.tracecompass.tmf.ctf.core.trace.iterator.CtfIteratorManager;
a3fc8213 71
f9ff7d40 72import com.google.common.collect.ImmutableList;
409bea20
GB
73import com.google.common.collect.ImmutableSet;
74
9ac2eb62 75/**
d09f973b
FC
76 * The CTf trace handler
77 *
78 * @version 1.0
79 * @author Matthew khouzam
9ac2eb62 80 */
22307af3 81public class CtfTmfTrace extends TmfTrace
090c006e 82 implements ITmfEventParser, ITmfTraceProperties, ITmfPersistentlyIndexable,
409bea20 83 ITmfTraceWithPreDefinedEvents, AutoCloseable {
a3fc8213 84
a94410d9
MK
85 // -------------------------------------------
86 // Constants
87 // -------------------------------------------
f9ff7d40 88
324a6a4a
BH
89 /**
90 * Default cache size for CTF traces
91 */
92 protected static final int DEFAULT_CACHE_SIZE = 50000;
64c2cb4c 93
f9ff7d40
AM
94 /**
95 * Event aspects available for all CTF traces
96 */
8192209b 97 private static final @NonNull Collection<ITmfEventAspect> CTF_ASPECTS =
5db5a3a4 98 checkNotNull(ImmutableList.of(
f9ff7d40
AM
99 ITmfEventAspect.BaseAspects.TIMESTAMP,
100 new CtfChannelAspect(),
101 new CtfCpuAspect(),
102 ITmfEventAspect.BaseAspects.EVENT_TYPE,
103 ITmfEventAspect.BaseAspects.CONTENTS
5db5a3a4 104 ));
f9ff7d40
AM
105
106 /**
bb52f9bc
GB
107 * The Ctf clock unique identifier field
108 */
109 private static final String CLOCK_HOST_PROPERTY = "uuid"; //$NON-NLS-1$
cd43d683 110 private static final int CONFIDENCE = 10;
bb52f9bc 111
a94410d9
MK
112 // -------------------------------------------
113 // Fields
114 // -------------------------------------------
a3fc8213 115
e600c338
AM
116 private final Map<String, CtfTmfEventType> fContainedEventTypes =
117 Collections.synchronizedMap(new HashMap<String, CtfTmfEventType>());
118
6a0ec7bc
AM
119 private final CtfIteratorManager fIteratorManager =
120 new CtfIteratorManager(this);
121
4b7c469f
MK
122 /* Reference to the CTF Trace */
123 private CTFTrace fTrace;
a3fc8213 124
a94410d9
MK
125 // -------------------------------------------
126 // TmfTrace Overrides
127 // -------------------------------------------
b1baa808
MK
128 /**
129 * Method initTrace.
063f0d27
AM
130 *
131 * @param resource
132 * The resource associated with this trace
133 * @param path
134 * The path to the trace file
135 * @param eventType
136 * The type of events that will be read from this trace
b1baa808 137 * @throws TmfTraceException
07804639 138 * If something went wrong while reading the trace
b1baa808 139 */
a3fc8213 140 @Override
6256d8ad 141 public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType)
b4f71e4a 142 throws TmfTraceException {
4a110860
AM
143 /*
144 * Set the cache size. This has to be done before the call to super()
145 * because the super needs to know the cache size.
146 */
147 setCacheSize();
324a6a4a 148
32c16b50
GB
149 super.initTrace(resource, path, eventType);
150
a3fc8213
AM
151 try {
152 this.fTrace = new CTFTrace(path);
81a2d02e 153 CtfTmfContext ctx;
99b483fe 154 /* Set the start and (current) end times for this trace */
81a2d02e 155 ctx = (CtfTmfContext) seekEvent(0L);
132a02b0 156 CtfTmfEvent event = getNext(ctx);
a94410d9 157 if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
99b483fe
AM
158 /* Handle the case where the trace is empty */
159 this.setStartTime(TmfTimestamp.BIG_BANG);
160 } else {
132a02b0 161 final ITmfTimestamp curTime = event.getTimestamp();
21fb02fa
MK
162 this.setStartTime(curTime);
163 this.setEndTime(curTime);
99b483fe 164 }
409bea20
GB
165 /*
166 * Register every event type. When you call getType, it will
167 * register a trace to that type in the TmfEventTypeManager
168 */
6a0ec7bc 169 try (CtfIterator iter = fIteratorManager.getIterator(ctx)) {
409bea20 170 for (IEventDeclaration ied : iter.getEventDeclarations()) {
e600c338 171 CtfTmfEventType ctfTmfEventType = fContainedEventTypes.get(ied.getName());
409bea20
GB
172 if (ctfTmfEventType == null) {
173 List<ITmfEventField> content = new ArrayList<>();
174 /* Should only return null the first time */
175 for (String fieldName : ied.getFields().getFieldsList()) {
176 content.add(new TmfEventField(fieldName, null, null));
177 }
178 ITmfEventField contentTree = new TmfEventField(
179 ITmfEventField.ROOT_FIELD_ID,
180 null,
181 content.toArray(new ITmfEventField[content.size()])
182 );
183
e600c338
AM
184 ctfTmfEventType = new CtfTmfEventType(ied.getName(), contentTree);
185 fContainedEventTypes.put(ctfTmfEventType.getName(), ctfTmfEventType);
409bea20
GB
186 }
187 }
188 }
25e48683 189 } catch (final CTFReaderException e) {
a3fc8213
AM
190 /*
191 * If it failed at the init(), we can assume it's because the file
192 * was not found or was not recognized as a CTF trace. Throw into
193 * the new type of exception expected by the rest of TMF.
194 */
9fa32496 195 throw new TmfTraceException(e.getMessage(), e);
a3fc8213 196 }
a3fc8213
AM
197 }
198
6a0ec7bc
AM
199 /**
200 * Return the iterator manager of this trace
201 *
202 * @return The iterator manager
203 */
204 public CtfIteratorManager getIteratorManager() {
205 return fIteratorManager;
206 }
207
090c006e
AM
208 @Override
209 public void close() {
210 dispose();
211 }
212
53b235e1
MK
213 @Override
214 public synchronized void dispose() {
6a0ec7bc 215 fIteratorManager.dispose();
5d1c6919 216 if (fTrace != null) {
5d1c6919
PT
217 fTrace = null;
218 }
53b235e1
MK
219 super.dispose();
220 }
221
b1baa808 222 /**
cd43d683
PT
223 * {@inheritDoc}
224 * <p>
225 * The default implementation sets the confidence to 10 if the trace is a
226 * valid CTF trace.
b1baa808 227 */
a3fc8213 228 @Override
a94410d9 229 public IStatus validate(final IProject project, final String path) {
dd9752d5 230 IStatus status = new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
b562a24f
MK
231 try {
232 final CTFTrace temp = new CTFTrace(path);
07804639 233 if (!temp.majorIsSet()) {
dd9752d5 234 status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
b5354daa 235 } else {
dd9752d5
AM
236 try (CTFTraceReader ctfTraceReader = new CTFTraceReader(temp);) {
237 if (!ctfTraceReader.hasMoreEvents()) {
238 // TODO: This will need an additional check when we
239 // support live traces
240 // because having no event is valid for a live trace
241 status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_NoEvent);
242 }
b5354daa 243 }
a94410d9 244 }
25e48683 245 } catch (final CTFReaderException e) {
dd9752d5
AM
246 status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + e.toString()); //$NON-NLS-1$
247 } catch (final BufferOverflowException e) {
248 status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError + ": " + Messages.CtfTmfTrace_BufferOverflowErrorMessage); //$NON-NLS-1$
a3fc8213 249 }
96c0f2af 250
dd9752d5 251 return status;
a3fc8213
AM
252 }
253
f9ff7d40
AM
254 @Override
255 public Iterable<ITmfEventAspect> getEventAspects() {
256 return CTF_ASPECTS;
257 }
258
b1baa808 259 /**
f474d36b 260 * Method getCurrentLocation. This is not applicable in CTF
a94410d9 261 *
f474d36b 262 * @return null, since the trace has no knowledge of the current location
2bdf0193 263 * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getCurrentLocation()
a3db8436 264 * @since 3.0
b1baa808 265 */
a3fc8213 266 @Override
1e1bef82 267 public ITmfLocation getCurrentLocation() {
f474d36b 268 return null;
a3fc8213
AM
269 }
270
a3db8436
AM
271 /**
272 * @since 3.0
273 */
a3fc8213 274 @Override
1e1bef82 275 public double getLocationRatio(ITmfLocation location) {
4b7c469f 276 final CtfLocation curLocation = (CtfLocation) location;
81a2d02e 277 final CtfTmfContext context = new CtfTmfContext(this);
53b235e1 278 context.setLocation(curLocation);
5976d44a 279 context.seek(curLocation.getLocationInfo());
a94410d9 280 final CtfLocationInfo currentTime = ((CtfLocationInfo) context.getLocation().getLocationInfo());
6a0ec7bc
AM
281 final long startTime = fIteratorManager.getIterator(context).getStartTime();
282 final long endTime = fIteratorManager.getIterator(context).getEndTime();
132a02b0 283 return ((double) currentTime.getTimestamp() - startTime)
53b235e1 284 / (endTime - startTime);
a3fc8213
AM
285 }
286
b1baa808
MK
287 /**
288 * Method seekEvent.
a94410d9
MK
289 *
290 * @param location
291 * ITmfLocation<?>
b1baa808 292 * @return ITmfContext
a3db8436 293 * @since 3.0
b1baa808 294 */
a3fc8213 295 @Override
76643eb7 296 public synchronized ITmfContext seekEvent(final ITmfLocation location) {
ce2388e0 297 CtfLocation currentLocation = (CtfLocation) location;
81a2d02e 298 CtfTmfContext context = new CtfTmfContext(this);
76643eb7
BH
299 if (fTrace == null) {
300 context.setLocation(null);
301 context.setRank(ITmfContext.UNKNOWN_RANK);
302 return context;
303 }
4a110860
AM
304 /*
305 * The rank is set to 0 if the iterator seeks the beginning. If not, it
306 * will be set to UNKNOWN_RANK, since CTF traces don't support seeking
307 * by rank for now.
308 */
11d6f468 309 if (currentLocation == null) {
f5df94f8 310 currentLocation = new CtfLocation(new CtfLocationInfo(0L, 0L));
4a110860 311 context.setRank(0);
11d6f468 312 }
5976d44a 313 if (currentLocation.getLocationInfo() == CtfLocation.INVALID_LOCATION) {
962fb72f 314 currentLocation = new CtfLocation(getCTFTrace().getCurrentEndTime() + 1, 0L);
1191a574 315 }
f474d36b 316 context.setLocation(currentLocation);
7f0bab07 317 if (location == null) {
6a0ec7bc 318 long timestamp = fIteratorManager.getIterator(context).getCurrentTimestamp();
962fb72f 319 currentLocation = new CtfLocation(timestamp, 0);
7f0bab07 320 }
a94410d9 321 if (context.getRank() != 0) {
3bd44ac8 322 context.setRank(ITmfContext.UNKNOWN_RANK);
64c2cb4c 323 }
f474d36b 324 return context;
a3fc8213
AM
325 }
326
a3fc8213 327 @Override
76643eb7 328 public synchronized ITmfContext seekEvent(double ratio) {
81a2d02e 329 CtfTmfContext context = new CtfTmfContext(this);
76643eb7
BH
330 if (fTrace == null) {
331 context.setLocation(null);
332 context.setRank(ITmfContext.UNKNOWN_RANK);
333 return context;
334 }
962fb72f
PT
335 final long end = getCTFTrace().getCurrentEndTime();
336 final long start = getCTFTrace().getCurrentStartTime();
b2dc9e02 337 final long diff = end - start;
15e89960 338 final long ratioTs = Math.round(diff * ratio) + start;
b2dc9e02 339 context.seek(ratioTs);
f474d36b
PT
340 context.setRank(ITmfContext.UNKNOWN_RANK);
341 return context;
a3fc8213
AM
342 }
343
b1baa808
MK
344 /**
345 * Method readNextEvent.
a94410d9
MK
346 *
347 * @param context
348 * ITmfContext
b1baa808 349 * @return CtfTmfEvent
2bdf0193 350 * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
b1baa808 351 */
a3fc8213 352 @Override
4b7c469f 353 public synchronized CtfTmfEvent getNext(final ITmfContext context) {
faa38350
PT
354 if (fTrace == null) {
355 return null;
356 }
f474d36b 357 CtfTmfEvent event = null;
81a2d02e 358 if (context instanceof CtfTmfContext) {
575beffc 359 if (context.getLocation() == null || CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocationInfo())) {
ae09313d
PT
360 return null;
361 }
81a2d02e 362 CtfTmfContext ctfContext = (CtfTmfContext) context;
788ddcbc 363 event = ctfContext.getCurrentEvent();
4a110860 364
324a6a4a
BH
365 if (event != null) {
366 updateAttributes(context, event.getTimestamp());
788ddcbc
MK
367 ctfContext.advance();
368 ctfContext.increaseRank();
324a6a4a 369 }
f474d36b 370 }
4a110860 371
aa572e22 372 return event;
a3fc8213
AM
373 }
374
4b7c469f
MK
375 /**
376 * gets the CTFtrace that this is wrapping
a94410d9 377 *
4b7c469f
MK
378 * @return the CTF trace
379 */
380 public CTFTrace getCTFTrace() {
a3fc8213
AM
381 return fTrace;
382 }
a1a24d68 383
bb52f9bc
GB
384 /**
385 * Ctf traces have a clock with a unique uuid that will be used to identify
386 * the host. Traces with the same clock uuid will be known to have been made
387 * on the same machine.
388 *
389 * Note: uuid is an optional field, it may not be there for a clock.
390 */
391 @Override
392 public String getHostId() {
393 CTFClock clock = getCTFTrace().getClock();
394 if (clock != null) {
395 String clockHost = (String) clock.getProperty(CLOCK_HOST_PROPERTY);
396 if (clockHost != null) {
397 return clockHost;
398 }
399 }
400 return super.getHostId();
401 }
402
a94410d9 403 // -------------------------------------------
22307af3 404 // ITmfTraceProperties
a94410d9 405 // -------------------------------------------
4b7c469f
MK
406
407 /**
299e494e 408 * @since 2.0
4b7c469f 409 */
22307af3
AM
410 @Override
411 public Map<String, String> getTraceProperties() {
2db2b43a
GB
412 Map<String, String> properties = new HashMap<>();
413 properties.putAll(fTrace.getEnvironment());
414 properties.put(Messages.CtfTmfTrace_HostID, getHostId());
415 return properties;
4b7c469f
MK
416 }
417
a94410d9
MK
418 // -------------------------------------------
419 // Clocks
420 // -------------------------------------------
bfe038ff 421
9ac2eb62
MK
422 /**
423 * gets the clock offset
a94410d9 424 *
9ac2eb62
MK
425 * @return the clock offset in ns
426 */
a94410d9
MK
427 public long getOffset() {
428 if (fTrace != null) {
bfe038ff
MK
429 return fTrace.getOffset();
430 }
431 return 0;
432 }
433
3480bf12 434 /**
409bea20 435 * Gets the list of declared events
3480bf12 436 *
409bea20 437 * @since 3.0
3480bf12 438 */
409bea20 439 @Override
e600c338
AM
440 public Set<CtfTmfEventType> getContainedEventTypes() {
441 return ImmutableSet.copyOf(fContainedEventTypes.values());
442 }
443
444 /**
445 * Register an event type to this trace.
446 *
9722e5d7 447 * Public visibility so that {@link CtfTmfEvent#getType} can call it.
e600c338
AM
448 *
449 * FIXME This could probably be made cleaner?
9722e5d7
AM
450 *
451 * @param eventType
452 * The event type to register
e600c338 453 */
9722e5d7 454 public void registerEventType(CtfTmfEventType eventType) {
e600c338 455 fContainedEventTypes.put(eventType.getName(), eventType);
3480bf12
GB
456 }
457
a94410d9
MK
458 // -------------------------------------------
459 // Parser
460 // -------------------------------------------
4b7c469f
MK
461
462 @Override
bfe038ff 463 public CtfTmfEvent parseEvent(ITmfContext context) {
4b7c469f 464 CtfTmfEvent event = null;
ea271da6
PT
465 if (context instanceof CtfTmfContext) {
466 final ITmfContext tmpContext = seekEvent(context.getLocation());
467 event = getNext(tmpContext);
4b7c469f
MK
468 }
469 return event;
11d6f468 470 }
64c2cb4c 471
324a6a4a 472 /**
64c2cb4c 473 * Sets the cache size for a CtfTmfTrace.
324a6a4a
BH
474 */
475 protected void setCacheSize() {
476 setCacheSize(DEFAULT_CACHE_SIZE);
477 }
ce2388e0 478
a94410d9
MK
479 // -------------------------------------------
480 // Helpers
481 // -------------------------------------------
53b235e1 482
36dd544c
MK
483 /**
484 * Get an iterator to the trace
485 *
486 * @return an iterator to the trace
ed59ab27 487 * @since 2.0
36dd544c 488 */
a94410d9 489 public CtfIterator createIterator() {
db8e8f7d
AM
490 try {
491 return new CtfIterator(this);
492 } catch (CTFReaderException e) {
91e7f946 493 Activator.getDefault().logError(e.getMessage(), e);
db8e8f7d
AM
494 }
495 return null;
36dd544c 496 }
e73a4ba5
GB
497
498 // ------------------------------------------------------------------------
499 // Timestamp transformation functions
500 // ------------------------------------------------------------------------
501
502 /**
503 * @since 3.0
504 */
505 @Override
506 public CtfTmfTimestamp createTimestamp(long ts) {
507 return new CtfTmfTimestamp(getTimestampTransform().transform(ts));
508 }
032ecd45
MAL
509
510 private static int fCheckpointSize = -1;
511
c4767854
AM
512 /**
513 * @since 3.0
514 */
032ecd45
MAL
515 @Override
516 public synchronized int getCheckpointSize() {
517 if (fCheckpointSize == -1) {
518 TmfCheckpoint c = new TmfCheckpoint(new CtfTmfTimestamp(0), new CtfLocation(0, 0), 0);
519 ByteBuffer b = ByteBuffer.allocate(ITmfCheckpoint.MAX_SERIALIZE_SIZE);
520 b.clear();
521 c.serialize(b);
522 fCheckpointSize = b.position();
523 }
524
525 return fCheckpointSize;
526 }
527
528 @Override
529 protected ITmfTraceIndexer createIndexer(int interval) {
530 return new TmfBTreeTraceIndexer(this, interval);
531 }
532
c4767854
AM
533 /**
534 * @since 3.0
535 */
032ecd45
MAL
536 @Override
537 public ITmfLocation restoreLocation(ByteBuffer bufferIn) {
538 return new CtfLocation(bufferIn);
539 }
6fd3c6e9
MAL
540
541 @Override
542 public boolean isComplete() {
543 if (getResource() == null) {
544 return true;
545 }
546
547 String host = null;
548 String port = null;
549 String sessionName = null;
550 try {
551 host = getResource().getPersistentProperty(CtfConstants.LIVE_HOST);
552 port = getResource().getPersistentProperty(CtfConstants.LIVE_PORT);
553 sessionName = getResource().getPersistentProperty(CtfConstants.LIVE_SESSION_NAME);
554 } catch (CoreException e) {
555 Activator.getDefault().logError(e.getMessage(), e);
b562a24f
MK
556 // Something happened to the resource, assume we won't get any more
557 // data from it
6fd3c6e9
MAL
558 return true;
559 }
560 return host == null || port == null || sessionName == null;
561 }
562
563 @Override
564 public void setComplete(final boolean isComplete) {
565 super.setComplete(isComplete);
566 try {
567 if (isComplete) {
568 getResource().setPersistentProperty(CtfConstants.LIVE_HOST, null);
569 getResource().setPersistentProperty(CtfConstants.LIVE_PORT, null);
570 getResource().setPersistentProperty(CtfConstants.LIVE_SESSION_NAME, null);
571 }
572 } catch (CoreException e) {
573 Activator.getDefault().logError(e.getMessage(), e);
574 }
575 }
a3fc8213 576}
This page took 0.121345 seconds and 5 git commands to generate.