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