| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2013, 2014 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 | * Alexandre Montplaisir - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.tracecompass.internal.statesystem.core.backend; |
| 14 | |
| 15 | import java.io.File; |
| 16 | import java.io.FileInputStream; |
| 17 | import java.io.PrintWriter; |
| 18 | import java.util.List; |
| 19 | |
| 20 | import org.eclipse.jdt.annotation.NonNull; |
| 21 | import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend; |
| 22 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; |
| 23 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; |
| 24 | |
| 25 | /** |
| 26 | * An implement of a state history back-end to simply discards *all* the |
| 27 | * intervals it receives. Obviously, no queries can be done on it. It is useful |
| 28 | * for using with a StateSystem on which you will only want to do "ongoing" |
| 29 | * requests. |
| 30 | * |
| 31 | * @author Alexandre Montplaisir |
| 32 | */ |
| 33 | public class NullBackend implements IStateHistoryBackend { |
| 34 | |
| 35 | private final @NonNull String ssid; |
| 36 | |
| 37 | /** |
| 38 | * Constructor |
| 39 | * |
| 40 | * @param ssid |
| 41 | * The state system's id |
| 42 | */ |
| 43 | public NullBackend(@NonNull String ssid) { |
| 44 | this.ssid = ssid; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public String getSSID() { |
| 49 | return ssid; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public long getStartTime() { |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public long getEndTime() { |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * The interval will be discarded when using a null backend. |
| 64 | */ |
| 65 | @Override |
| 66 | public void insertPastState(long stateStartTime, long stateEndTime, |
| 67 | int quark, ITmfStateValue value) { |
| 68 | /* The interval is always discarded. */ |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void finishedBuilding(long endTime) { |
| 73 | /* Nothing to do */ |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public FileInputStream supplyAttributeTreeReader() { |
| 78 | return null; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public File supplyAttributeTreeWriterFile() { |
| 83 | return null; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public long supplyAttributeTreeWriterFilePosition() { |
| 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public void removeFiles() { |
| 93 | /* Nothing to do */ |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void dispose() { |
| 98 | /* Nothing to do */ |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Null back-ends cannot run queries. Nothing will be put in |
| 103 | * currentStateInfo. |
| 104 | */ |
| 105 | @Override |
| 106 | public void doQuery(List<ITmfStateInterval> currentStateInfo, long t) { |
| 107 | /* Cannot do past queries */ |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Null back-ends cannot run queries. 'null' will be returned. |
| 112 | * |
| 113 | * @return Always returns null. |
| 114 | */ |
| 115 | @Override |
| 116 | public ITmfStateInterval doSingularQuery(long t, int attributeQuark) { |
| 117 | /* Cannot do past queries */ |
| 118 | return null; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void debugPrint(PrintWriter writer) { |
| 123 | writer.println("Null history backend"); //$NON-NLS-1$ |
| 124 | } |
| 125 | } |