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