General improvements:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / trace / TmfTraceContext.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.trace;
14
15 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
16
17 /**
18 * <b><u>TmfTraceContext</u></b>
19 * <p>
20 * Trace context keeper. It ties a trace location to an event index and
21 * timestamp. The context should be enough to restore the trace state
22 * so the corresponding event can be read.
23 *
24 * Used to handle conflicting, concurrent accesses to the trace.
25 */
26 public class TmfTraceContext {
27
28 private Object location;
29 private TmfTimestamp timestamp;
30 private long index;
31
32 public TmfTraceContext(Object loc, TmfTimestamp ts, long ind) {
33 location = loc;
34 timestamp = (ts != null) ? ts : TmfTimestamp.BigBang;
35 index = ind;
36 }
37
38 public TmfTraceContext(TmfTraceContext other) {
39 this(other.location, other.timestamp, other.index);
40 }
41
42 public Object getLocation() {
43 // validateLocation(location);
44 return location;
45 }
46
47 public void setLocation(Object loc) {
48 // validateLocation(loc);
49 location = loc;
50 }
51
52 public TmfTimestamp getTimestamp() {
53 return timestamp;
54 }
55
56 public void setTimestamp(TmfTimestamp ts) {
57 timestamp = ts;
58 }
59
60 public void setIndex(long value) {
61 index = value;
62 }
63
64 public long getIndex() {
65 return index;
66 }
67
68 public void incrIndex() {
69 index++;
70 }
71
72 // TODO: Generalize this code so an implementor can troubleshoot concurrency issues
73
74 // // ========================================================================
75 // // Toubleshooting code
76 // // ========================================================================
77 //
78 // static private DataInputStream in;
79 // static private int size = 100001;
80 // static private long offsets[] = new long[size];
81 // static public void init() {
82 // System.out.println("TmfTraceContext: Loading valid offsets...");
83 // try {
84 // in = new DataInputStream(new BufferedInputStream(new FileInputStream("Offsets.dat")));
85 // for (int i = 0; i < size; i++)
86 // offsets[i] = in.readLong();
87 // } catch (FileNotFoundException e) {
88 // // TODO Auto-generated catch block
89 // e.printStackTrace();
90 // } catch (IOException e) {
91 // // TODO Auto-generated catch block
92 // e.printStackTrace();
93 // }
94 // System.out.println("TmfTraceContext: Done.");
95 // }
96 //
97 // private boolean bsearch(long key) {
98 // int first = 0;
99 // int last = size;
100 // while (first < last) {
101 // int mid = (first + last) / 2;
102 // if (key < offsets[mid]) {
103 // last = mid;
104 // } else if (key > offsets[mid]) {
105 // first = mid + 1;
106 // } else {
107 // return true;
108 // }
109 // }
110 // return false;
111 // }
112 //
113 // private void validateLocation(Object loc) {
114 // long l = (Long) loc;
115 // if (!bsearch(l)) {
116 // System.out.println("TmfTraceContext: location is invalid!");
117 // }
118 // }
119
120 }
This page took 0.03394 seconds and 5 git commands to generate.