lttng: Add support for creating a live session in Control view
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core / src / org / eclipse / linuxtools / internal / lttng2 / control / core / model / impl / SessionInfo.java
1 /**********************************************************************
2 * Copyright (c) 2012, 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 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 * Marc-Andre Laperle - Support for creating a live session
13 **********************************************************************/
14 package org.eclipse.linuxtools.internal.lttng2.control.core.model.impl;
15
16 import java.util.ArrayList;
17 import java.util.Iterator;
18 import java.util.List;
19
20 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IDomainInfo;
21 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo;
22 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo;
23 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
24
25 /**
26 * <p>
27 * Implementation of the trace session interface (ISessionInfo) to store session
28 * related data.
29 * </p>
30 *
31 * @author Bernd Hufmann
32 */
33 public class SessionInfo extends TraceInfo implements ISessionInfo {
34
35 /**
36 * The default network URL when creating a live session
37 */
38 public static final String DEFAULT_LIVE_NETWORK_URK = "net://127.0.0.1"; //$NON-NLS-1$
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43 /**
44 * The trace session state.
45 */
46 private TraceSessionState fState = TraceSessionState.INACTIVE;
47 /**
48 * The trace session path for storing traces.
49 */
50 private String fSessionPath = ""; //$NON-NLS-1$
51 /**
52 * The domains information of this session.
53 */
54 private final List<IDomainInfo> fDomains = new ArrayList<>();
55 /**
56 * Flag to indicate whether trace is streamed over network or not.
57 */
58 private boolean fIsStreamedTrace = false;
59 /**
60 * Flag to indicate whether the session is a snapshot session or not.
61 */
62 private boolean fIsSnapshot = false;
63 /**
64 * The snapshot information of the session
65 */
66 private ISnapshotInfo fSnapshotInfo = null;
67 /**
68 * The network URL for the session (-U)
69 */
70 private String fNetworkUrl = null;
71 /**
72 * The control URL for the session (-C)
73 */
74 private String fControlUrl = null;
75 /**
76 * The data URL for the session (-D)
77 */
78 private String fDataUrl = null;
79
80 /**
81 * Flag to indicate whether trace is live or not.
82 */
83 private boolean fIsLive = false;
84
85 /**
86 * The delay in micro seconds before the data is flushed and streamed.
87 */
88 private int fLiveDelay = -1;
89
90 // ------------------------------------------------------------------------
91 // Constructors
92 // ------------------------------------------------------------------------
93 /**
94 * Constructor
95 * @param name - name of base event
96 */
97 public SessionInfo(String name) {
98 super(name);
99 }
100
101 /**
102 * Copy constructor
103 * @param other - the instance to copy
104 */
105 public SessionInfo(SessionInfo other) {
106 super(other);
107 fState = other.fState;
108 fSessionPath = other.fSessionPath;
109 fIsStreamedTrace = other.fIsStreamedTrace;
110 fIsSnapshot = other.fIsSnapshot;
111 fSnapshotInfo = other.fSnapshotInfo;
112 fNetworkUrl = other.fNetworkUrl;
113 fControlUrl = other.fControlUrl;
114 fDataUrl = other.fDataUrl;
115
116 for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) {
117 IDomainInfo domain = iterator.next();
118 if (domain instanceof DomainInfo) {
119 fDomains.add(new DomainInfo((DomainInfo)domain));
120 } else {
121 fDomains.add(domain);
122 }
123 }
124 }
125
126 // ------------------------------------------------------------------------
127 // Accessors
128 // ------------------------------------------------------------------------
129
130 @Override
131 public TraceSessionState getSessionState() {
132 return fState;
133 }
134
135 @Override
136 public void setSessionState(TraceSessionState state) {
137 fState = state;
138 }
139
140 @Override
141 public void setSessionState(String stateName) {
142 if (TraceSessionState.INACTIVE.getInName().equals(stateName)) {
143 fState = TraceSessionState.INACTIVE;
144 } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) {
145 fState = TraceSessionState.ACTIVE;
146 }
147 }
148
149 @Override
150 public String getSessionPath() {
151 if (isSnapshotSession() && fSnapshotInfo != null) {
152 return fSnapshotInfo.getSnapshotPath();
153 }
154 return fSessionPath;
155 }
156
157 @Override
158 public void setSessionPath(String path) {
159 fSessionPath = path;
160 }
161
162 @Override
163 public IDomainInfo[] getDomains() {
164 return fDomains.toArray(new IDomainInfo[fDomains.size()]);
165 }
166
167 @Override
168 public void setDomains(List<IDomainInfo> domains) {
169 fDomains.clear();
170 for (Iterator<IDomainInfo> iterator = domains.iterator(); iterator.hasNext();) {
171 IDomainInfo domainInfo = iterator.next();
172 fDomains.add(domainInfo);
173 }
174 }
175
176 @Override
177 public boolean isStreamedTrace() {
178 return fIsStreamedTrace;
179 }
180
181 @Override
182 public void setStreamedTrace(boolean isStreamedTrace) {
183 fIsStreamedTrace = isStreamedTrace;
184 }
185
186 @Override
187 public boolean isSnapshotSession() {
188 return fIsSnapshot || fSnapshotInfo != null;
189 }
190
191 @Override
192 public void setSnapshot(boolean isSnapshot) {
193 fIsSnapshot = isSnapshot;
194 }
195
196 @Override
197 public ISnapshotInfo getSnapshotInfo() {
198 return fSnapshotInfo;
199 }
200
201 @Override
202 public void setSnapshotInfo(ISnapshotInfo info) {
203 fSnapshotInfo = info;
204 }
205
206 @Override
207 public boolean isLive() {
208 return fIsLive;
209 }
210
211 @Override
212 public void setLive(boolean isLive) {
213 fIsLive = isLive;
214 }
215
216 @Override
217 public int getLiveDelay() {
218 return fLiveDelay;
219 }
220
221 @Override
222 public void setLiveDelay(int liveDelay) {
223 fLiveDelay = liveDelay;
224 }
225
226 // ------------------------------------------------------------------------
227 // Operations
228 // ------------------------------------------------------------------------
229
230 @Override
231 public void addDomain(IDomainInfo domainInfo) {
232 fDomains.add(domainInfo);
233 }
234
235
236 @SuppressWarnings("nls")
237 @Override
238 public String toString() {
239 StringBuffer output = new StringBuffer();
240 output.append("[SessionInfo(");
241 output.append(super.toString());
242 output.append(",Path=");
243 output.append(getSessionPath());
244 output.append(",State=");
245 output.append(fState);
246 output.append(",isStreamedTrace=");
247 output.append(fIsStreamedTrace);
248 output.append(",isSnapshot=");
249 output.append(fIsSnapshot);
250
251 if (fSnapshotInfo != null) {
252 output.append(",snapshotInfo=");
253 output.append(fSnapshotInfo.toString());
254 }
255 output.append(",Domains=");
256 for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) {
257 IDomainInfo domain = iterator.next();
258 output.append(domain.toString());
259 }
260
261 output.append(",NetworkUrl=");
262 output.append(getNetworkUrl());
263 output.append(",ControlUrl=");
264 output.append(getControlUrl());
265 output.append(",DataUrl=");
266 output.append(getDataUrl());
267
268 output.append(")]");
269 return output.toString();
270 }
271
272 @Override
273 public String getNetworkUrl() {
274 return fNetworkUrl;
275 }
276
277 @Override
278 public void setNetworkUrl(String networkUrl) {
279 fNetworkUrl = networkUrl;
280 }
281
282 @Override
283 public String getControlUrl() {
284 return fControlUrl;
285 }
286
287 @Override
288 public void setControlUrl(String controlUrl) {
289 fControlUrl = controlUrl;
290 }
291
292 @Override
293 public void setDataUrl(String datalUrl) {
294 fDataUrl = datalUrl;
295 }
296
297 @Override
298 public String getDataUrl() {
299 return fDataUrl;
300 }
301 }
This page took 0.036929 seconds and 5 git commands to generate.