lttng: Move to Java 7 and fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core / src / org / eclipse / linuxtools / internal / lttng2 / core / control / model / impl / SessionInfo.java
CommitLineData
eb1bab5b 1/**********************************************************************
ba3a9bd2 2 * Copyright (c) 2012, 2013 Ericsson
b0318660 3 *
eb1bab5b
BH
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
b0318660
AM
8 *
9 * Contributors:
eb1bab5b 10 * Bernd Hufmann - Initial API and implementation
ba3a9bd2 11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
eb1bab5b 12 **********************************************************************/
9315aeee 13package org.eclipse.linuxtools.internal.lttng2.core.control.model.impl;
eb1bab5b
BH
14
15import java.util.ArrayList;
16import java.util.Iterator;
17import java.util.List;
18
9315aeee
BH
19import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
20import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
589d0d33 21import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISnapshotInfo;
9315aeee 22import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
eb1bab5b
BH
23
24/**
eb1bab5b
BH
25 * <p>
26 * Implementation of the trace session interface (ISessionInfo) to store session
b0318660 27 * related data.
eb1bab5b 28 * </p>
b0318660 29 *
dbd4432d 30 * @author Bernd Hufmann
eb1bab5b
BH
31 */
32public class SessionInfo extends TraceInfo implements ISessionInfo {
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37 /**
38 * The trace session state.
39 */
40 private TraceSessionState fState = TraceSessionState.INACTIVE;
b0318660 41 /**
eb1bab5b
BH
42 * The trace session path for storing traces.
43 */
44 private String fSessionPath = ""; //$NON-NLS-1$
45 /**
46 * The domains information of this session.
47 */
e0838ca1 48 private final List<IDomainInfo> fDomains = new ArrayList<>();
f3b33d40
BH
49 /**
50 * Flag to indicate whether trace is streamed over network or not.
51 */
52 private boolean fIsStreamedTrace = false;
589d0d33
BH
53 /**
54 * Flag to indicate whether the session is a snapshot session or not.
55 */
56 private ISnapshotInfo fSnapshotInfo = null;
57
eb1bab5b
BH
58
59 // ------------------------------------------------------------------------
60 // Constructors
61 // ------------------------------------------------------------------------
62 /**
63 * Constructor
64 * @param name - name of base event
65 */
66 public SessionInfo(String name) {
67 super(name);
68 }
69
70 /**
71 * Copy constructor
72 * @param other - the instance to copy
73 */
74 public SessionInfo(SessionInfo other) {
75 super(other);
76 fState = other.fState;
77 fSessionPath = other.fSessionPath;
f3b33d40 78 fIsStreamedTrace = other.fIsStreamedTrace;
589d0d33 79 fSnapshotInfo = other.fSnapshotInfo;
b0318660 80
eb1bab5b
BH
81 for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) {
82 IDomainInfo domain = iterator.next();
83 if (domain instanceof DomainInfo) {
84 fDomains.add(new DomainInfo((DomainInfo)domain));
85 } else {
86 fDomains.add(domain);
87 }
88 }
89 }
b0318660 90
eb1bab5b
BH
91 // ------------------------------------------------------------------------
92 // Accessors
93 // ------------------------------------------------------------------------
11252342 94
eb1bab5b
BH
95 @Override
96 public TraceSessionState getSessionState() {
97 return fState;
98 }
99
eb1bab5b
BH
100 @Override
101 public void setSessionState(TraceSessionState state) {
102 fState = state;
103 }
104
eb1bab5b
BH
105 @Override
106 public void setSessionState(String stateName) {
107 if (TraceSessionState.INACTIVE.getInName().equals(stateName)) {
108 fState = TraceSessionState.INACTIVE;
109 } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) {
110 fState = TraceSessionState.ACTIVE;
111 }
112 }
b0318660 113
eb1bab5b
BH
114 @Override
115 public String getSessionPath() {
589d0d33
BH
116 if(isSnapshotSession()) {
117 return fSnapshotInfo.getSnapshotPath();
118 }
eb1bab5b
BH
119 return fSessionPath;
120 }
121
eb1bab5b
BH
122 @Override
123 public void setSessionPath(String path) {
124 fSessionPath = path;
125 }
126
eb1bab5b
BH
127 @Override
128 public IDomainInfo[] getDomains() {
129 return fDomains.toArray(new IDomainInfo[fDomains.size()]);
130 }
131
eb1bab5b
BH
132 @Override
133 public void setDomains(List<IDomainInfo> domains) {
a6702bfa 134 fDomains.clear();
eb1bab5b 135 for (Iterator<IDomainInfo> iterator = domains.iterator(); iterator.hasNext();) {
b0318660 136 IDomainInfo domainInfo = iterator.next();
eb1bab5b
BH
137 fDomains.add(domainInfo);
138 }
139 }
140
f3b33d40
BH
141 @Override
142 public boolean isStreamedTrace() {
589d0d33
BH
143 if (isSnapshotSession()) {
144 return fSnapshotInfo.isStreamedSnapshot();
145 }
f3b33d40
BH
146 return fIsStreamedTrace;
147 }
148
f3b33d40
BH
149 @Override
150 public void setStreamedTrace(boolean isStreamedTrace) {
151 fIsStreamedTrace = isStreamedTrace;
152 }
153
589d0d33
BH
154 @Override
155 public boolean isSnapshotSession() {
156 return fSnapshotInfo != null;
157 }
11252342 158
eb1bab5b 159 @Override
589d0d33
BH
160 public ISnapshotInfo getSnapshotInfo() {
161 return fSnapshotInfo;
eb1bab5b 162 }
b0318660 163
d132bcc7 164 @Override
589d0d33
BH
165 public void setSnapshotInfo(ISnapshotInfo info) {
166 fSnapshotInfo = info;
eb1bab5b
BH
167 }
168
589d0d33
BH
169 // ------------------------------------------------------------------------
170 // Operations
171 // ------------------------------------------------------------------------
172
eb1bab5b 173 @Override
589d0d33
BH
174 public void addDomain(IDomainInfo domainInfo) {
175 fDomains.add(domainInfo);
eb1bab5b 176 }
d132bcc7 177
589d0d33 178
eb1bab5b
BH
179 @SuppressWarnings("nls")
180 @Override
181 public String toString() {
182 StringBuffer output = new StringBuffer();
183 output.append("[SessionInfo(");
184 output.append(super.toString());
589d0d33
BH
185 output.append(",Path=");
186 output.append(getSessionPath());
eb1bab5b
BH
187 output.append(",State=");
188 output.append(fState);
a30e79fe
BH
189 output.append(",isStreamedTrace=");
190 output.append(fIsStreamedTrace);
589d0d33
BH
191 if (fSnapshotInfo != null) {
192 output.append(",snapshotInfo=");
193 output.append(fSnapshotInfo.toString());
194 }
eb1bab5b
BH
195 output.append(",Domains=");
196 for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) {
b0318660 197 IDomainInfo domain = iterator.next();
d132bcc7 198 output.append(domain.toString());
eb1bab5b
BH
199 }
200 output.append(")]");
201 return output.toString();
202 }
203}
This page took 0.060666 seconds and 5 git commands to generate.