Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2012, 2014 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 |
81d5dc3a | 12 | * Marc-Andre Laperle - Support for creating a live session |
eb1bab5b | 13 | **********************************************************************/ |
8e8c0226 | 14 | package org.eclipse.linuxtools.internal.lttng2.control.core.model.impl; |
eb1bab5b BH |
15 | |
16 | import java.util.ArrayList; | |
17 | import java.util.Iterator; | |
18 | import java.util.List; | |
19 | ||
8e8c0226 AM |
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; | |
eb1bab5b BH |
24 | |
25 | /** | |
eb1bab5b BH |
26 | * <p> |
27 | * Implementation of the trace session interface (ISessionInfo) to store session | |
b0318660 | 28 | * related data. |
eb1bab5b | 29 | * </p> |
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 | |
105 | * @param name - name of base event | |
106 | */ | |
107 | public SessionInfo(String name) { | |
108 | super(name); | |
109 | } | |
110 | ||
111 | /** | |
112 | * Copy constructor | |
113 | * @param other - the instance to copy | |
114 | */ | |
115 | public SessionInfo(SessionInfo other) { | |
116 | super(other); | |
117 | fState = other.fState; | |
118 | fSessionPath = other.fSessionPath; | |
f3b33d40 | 119 | fIsStreamedTrace = other.fIsStreamedTrace; |
f7d4d450 | 120 | fIsSnapshot = other.fIsSnapshot; |
589d0d33 | 121 | fSnapshotInfo = other.fSnapshotInfo; |
f7d4d450 MAL |
122 | fNetworkUrl = other.fNetworkUrl; |
123 | fControlUrl = other.fControlUrl; | |
124 | fDataUrl = other.fDataUrl; | |
b0318660 | 125 | |
eb1bab5b BH |
126 | for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) { |
127 | IDomainInfo domain = iterator.next(); | |
128 | if (domain instanceof DomainInfo) { | |
129 | fDomains.add(new DomainInfo((DomainInfo)domain)); | |
130 | } else { | |
131 | fDomains.add(domain); | |
132 | } | |
133 | } | |
134 | } | |
b0318660 | 135 | |
eb1bab5b BH |
136 | // ------------------------------------------------------------------------ |
137 | // Accessors | |
138 | // ------------------------------------------------------------------------ | |
11252342 | 139 | |
eb1bab5b BH |
140 | @Override |
141 | public TraceSessionState getSessionState() { | |
142 | return fState; | |
143 | } | |
144 | ||
eb1bab5b BH |
145 | @Override |
146 | public void setSessionState(TraceSessionState state) { | |
147 | fState = state; | |
148 | } | |
149 | ||
eb1bab5b BH |
150 | @Override |
151 | public void setSessionState(String stateName) { | |
152 | if (TraceSessionState.INACTIVE.getInName().equals(stateName)) { | |
153 | fState = TraceSessionState.INACTIVE; | |
154 | } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) { | |
155 | fState = TraceSessionState.ACTIVE; | |
156 | } | |
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() { | |
188 | return fIsStreamedTrace; | |
189 | } | |
190 | ||
f3b33d40 BH |
191 | @Override |
192 | public void setStreamedTrace(boolean isStreamedTrace) { | |
193 | fIsStreamedTrace = isStreamedTrace; | |
194 | } | |
195 | ||
589d0d33 BH |
196 | @Override |
197 | public boolean isSnapshotSession() { | |
f7d4d450 MAL |
198 | return fIsSnapshot || fSnapshotInfo != null; |
199 | } | |
200 | ||
201 | @Override | |
202 | public void setSnapshot(boolean isSnapshot) { | |
203 | fIsSnapshot = isSnapshot; | |
589d0d33 | 204 | } |
11252342 | 205 | |
eb1bab5b | 206 | @Override |
589d0d33 BH |
207 | public ISnapshotInfo getSnapshotInfo() { |
208 | return fSnapshotInfo; | |
eb1bab5b | 209 | } |
b0318660 | 210 | |
d132bcc7 | 211 | @Override |
589d0d33 BH |
212 | public void setSnapshotInfo(ISnapshotInfo info) { |
213 | fSnapshotInfo = info; | |
eb1bab5b BH |
214 | } |
215 | ||
81d5dc3a MAL |
216 | @Override |
217 | public boolean isLive() { | |
218 | return fIsLive; | |
219 | } | |
220 | ||
221 | @Override | |
222 | public void setLive(boolean isLive) { | |
223 | fIsLive = isLive; | |
224 | } | |
225 | ||
226 | @Override | |
227 | public int getLiveDelay() { | |
228 | return fLiveDelay; | |
229 | } | |
230 | ||
231 | @Override | |
232 | public void setLiveDelay(int liveDelay) { | |
233 | fLiveDelay = liveDelay; | |
234 | } | |
235 | ||
589d0d33 BH |
236 | // ------------------------------------------------------------------------ |
237 | // Operations | |
238 | // ------------------------------------------------------------------------ | |
239 | ||
eb1bab5b | 240 | @Override |
589d0d33 BH |
241 | public void addDomain(IDomainInfo domainInfo) { |
242 | fDomains.add(domainInfo); | |
eb1bab5b | 243 | } |
d132bcc7 | 244 | |
589d0d33 | 245 | |
eb1bab5b BH |
246 | @SuppressWarnings("nls") |
247 | @Override | |
248 | public String toString() { | |
249 | StringBuffer output = new StringBuffer(); | |
250 | output.append("[SessionInfo("); | |
251 | output.append(super.toString()); | |
589d0d33 BH |
252 | output.append(",Path="); |
253 | output.append(getSessionPath()); | |
eb1bab5b BH |
254 | output.append(",State="); |
255 | output.append(fState); | |
a30e79fe BH |
256 | output.append(",isStreamedTrace="); |
257 | output.append(fIsStreamedTrace); | |
f7d4d450 MAL |
258 | output.append(",isSnapshot="); |
259 | output.append(fIsSnapshot); | |
260 | ||
589d0d33 BH |
261 | if (fSnapshotInfo != null) { |
262 | output.append(",snapshotInfo="); | |
263 | output.append(fSnapshotInfo.toString()); | |
264 | } | |
eb1bab5b BH |
265 | output.append(",Domains="); |
266 | for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) { | |
b0318660 | 267 | IDomainInfo domain = iterator.next(); |
d132bcc7 | 268 | output.append(domain.toString()); |
eb1bab5b | 269 | } |
f7d4d450 MAL |
270 | |
271 | output.append(",NetworkUrl="); | |
272 | output.append(getNetworkUrl()); | |
273 | output.append(",ControlUrl="); | |
274 | output.append(getControlUrl()); | |
275 | output.append(",DataUrl="); | |
276 | output.append(getDataUrl()); | |
277 | ||
eb1bab5b BH |
278 | output.append(")]"); |
279 | return output.toString(); | |
280 | } | |
f7d4d450 MAL |
281 | |
282 | @Override | |
283 | public String getNetworkUrl() { | |
284 | return fNetworkUrl; | |
285 | } | |
286 | ||
287 | @Override | |
288 | public void setNetworkUrl(String networkUrl) { | |
289 | fNetworkUrl = networkUrl; | |
290 | } | |
291 | ||
292 | @Override | |
293 | public String getControlUrl() { | |
294 | return fControlUrl; | |
295 | } | |
296 | ||
297 | @Override | |
298 | public void setControlUrl(String controlUrl) { | |
299 | fControlUrl = controlUrl; | |
300 | } | |
301 | ||
302 | @Override | |
303 | public void setDataUrl(String datalUrl) { | |
304 | fDataUrl = datalUrl; | |
305 | } | |
306 | ||
307 | @Override | |
308 | public String getDataUrl() { | |
309 | return fDataUrl; | |
310 | } | |
6fd3c6e9 MAL |
311 | |
312 | @Override | |
313 | public void setLiveUrl(String liveUrl) { | |
314 | fLiveUrl = liveUrl; | |
315 | } | |
316 | ||
317 | @Override | |
318 | public void setLivePort(Integer livePort) { | |
319 | fLivePort = livePort; | |
320 | } | |
321 | ||
322 | @Override | |
323 | public String getLiveUrl() { | |
324 | return fLiveUrl; | |
325 | } | |
326 | ||
327 | @Override | |
328 | public Integer getLivePort() { | |
329 | return fLivePort; | |
330 | } | |
eb1bab5b | 331 | } |