| 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. |
| 22 | * <p> |
| 23 | * Used to handle conflicting, concurrent accesses to the trace. |
| 24 | */ |
| 25 | public class TmfContext implements ITmfContext { |
| 26 | |
| 27 | private ITmfLocation<?> fLocation; |
| 28 | private long fRank; |
| 29 | |
| 30 | // ------------------------------------------------------------------------ |
| 31 | // Constructors |
| 32 | // ------------------------------------------------------------------------ |
| 33 | |
| 34 | public TmfContext(ITmfLocation<?> loc, long rank) { |
| 35 | fLocation = loc; |
| 36 | fRank = rank; |
| 37 | } |
| 38 | |
| 39 | public TmfContext(ITmfLocation<?> location) { |
| 40 | this(location, 0); |
| 41 | } |
| 42 | |
| 43 | public TmfContext(TmfContext other) { |
| 44 | this(other.fLocation, other.fRank); |
| 45 | } |
| 46 | |
| 47 | public 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; |
| 63 | } |
| 64 | |
| 65 | // ------------------------------------------------------------------------ |
| 66 | // ITmfContext |
| 67 | // ------------------------------------------------------------------------ |
| 68 | |
| 69 | public void setLocation(ITmfLocation<?> location) { |
| 70 | fLocation = location; |
| 71 | } |
| 72 | |
| 73 | public ITmfLocation<?> getLocation() { |
| 74 | return fLocation; |
| 75 | } |
| 76 | |
| 77 | public void setRank(long rank) { |
| 78 | fRank = rank; |
| 79 | } |
| 80 | |
| 81 | public long getRank() { |
| 82 | return fRank; |
| 83 | } |
| 84 | |
| 85 | public void updateRank(int delta) { |
| 86 | fRank += delta; |
| 87 | } |
| 88 | |
| 89 | } |