Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 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 | ||
16 | /** | |
17 | * <b><u>TmfContext</u></b> | |
18 | * <p> | |
19 | * Trace context structure. It ties a trace location to an event rank. The | |
20 | * context should be enough to restore the trace state so the corresponding | |
21 | * event can be read. | |
9f584e4c FC |
22 | * <p> |
23 | * Used to handle conflicting, concurrent accesses to the trace. | |
8c8bf09f ASL |
24 | */ |
25 | public class TmfContext implements ITmfContext, Cloneable { | |
26 | ||
452ad365 | 27 | private ITmfLocation<?> fLocation; |
8c8bf09f ASL |
28 | private long fRank; |
29 | ||
30 | // ------------------------------------------------------------------------ | |
31 | // Constructors | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
452ad365 | 34 | public TmfContext(ITmfLocation<?> loc, long rank) { |
8c8bf09f ASL |
35 | fLocation = loc; |
36 | fRank = rank; | |
37 | } | |
38 | ||
452ad365 | 39 | public TmfContext(ITmfLocation<?> location) { |
9f584e4c | 40 | this(location, 0); |
8c8bf09f ASL |
41 | } |
42 | ||
43 | public TmfContext(TmfContext other) { | |
44 | this(other.fLocation, other.fRank); | |
45 | } | |
46 | ||
9f584e4c FC |
47 | protected TmfContext() { |
48 | this(null, 0); | |
49 | } | |
50 | ||
51 | // ------------------------------------------------------------------------ | |
52 | // Cloneable | |
53 | // ------------------------------------------------------------------------ | |
54 | ||
55 | @Override | |
56 | public TmfContext clone() { | |
57 | try { | |
58 | return (TmfContext) super.clone(); | |
59 | } catch (CloneNotSupportedException e) { | |
60 | e.printStackTrace(); | |
61 | } | |
62 | return null; | |
8c8bf09f ASL |
63 | } |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // ITmfContext | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
452ad365 FC |
69 | public void setLocation(ITmfLocation<?> location) { |
70 | fLocation = location; | |
8c8bf09f ASL |
71 | } |
72 | ||
452ad365 | 73 | public ITmfLocation<?> getLocation() { |
8c8bf09f ASL |
74 | return fLocation; |
75 | } | |
76 | ||
452ad365 FC |
77 | public void setRank(long rank) { |
78 | fRank = rank; | |
8c8bf09f ASL |
79 | } |
80 | ||
81 | public long getRank() { | |
82 | return fRank; | |
83 | } | |
84 | ||
452ad365 FC |
85 | public void updateRank(int delta) { |
86 | fRank += delta; | |
8c8bf09f ASL |
87 | } |
88 | ||
89 | } |