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 |
eb1bab5b | 12 | **********************************************************************/ |
8e8c0226 | 13 | package org.eclipse.linuxtools.internal.lttng2.control.core.model.impl; |
eb1bab5b BH |
14 | |
15 | import java.util.ArrayList; | |
16 | import java.util.Iterator; | |
17 | import java.util.List; | |
18 | ||
8e8c0226 AM |
19 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.IDomainInfo; |
20 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo; | |
21 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo; | |
22 | import org.eclipse.linuxtools.internal.lttng2.control.core.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 | */ |
32 | public 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 | */ | |
f7d4d450 MAL |
56 | private boolean fIsSnapshot = false; |
57 | /** | |
58 | * The snapshot information of the session | |
59 | */ | |
589d0d33 | 60 | private ISnapshotInfo fSnapshotInfo = null; |
f7d4d450 MAL |
61 | /** |
62 | * The network URL for the session (-U) | |
63 | */ | |
64 | private String fNetworkUrl = null; | |
65 | /** | |
66 | * The control URL for the session (-C) | |
67 | */ | |
68 | private String fControlUrl = null; | |
69 | /** | |
70 | * The data URL for the session (-D) | |
71 | */ | |
72 | private String fDataUrl = null; | |
589d0d33 | 73 | |
eb1bab5b BH |
74 | |
75 | // ------------------------------------------------------------------------ | |
76 | // Constructors | |
77 | // ------------------------------------------------------------------------ | |
78 | /** | |
79 | * Constructor | |
80 | * @param name - name of base event | |
81 | */ | |
82 | public SessionInfo(String name) { | |
83 | super(name); | |
84 | } | |
85 | ||
86 | /** | |
87 | * Copy constructor | |
88 | * @param other - the instance to copy | |
89 | */ | |
90 | public SessionInfo(SessionInfo other) { | |
91 | super(other); | |
92 | fState = other.fState; | |
93 | fSessionPath = other.fSessionPath; | |
f3b33d40 | 94 | fIsStreamedTrace = other.fIsStreamedTrace; |
f7d4d450 | 95 | fIsSnapshot = other.fIsSnapshot; |
589d0d33 | 96 | fSnapshotInfo = other.fSnapshotInfo; |
f7d4d450 MAL |
97 | fNetworkUrl = other.fNetworkUrl; |
98 | fControlUrl = other.fControlUrl; | |
99 | fDataUrl = other.fDataUrl; | |
b0318660 | 100 | |
eb1bab5b BH |
101 | for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) { |
102 | IDomainInfo domain = iterator.next(); | |
103 | if (domain instanceof DomainInfo) { | |
104 | fDomains.add(new DomainInfo((DomainInfo)domain)); | |
105 | } else { | |
106 | fDomains.add(domain); | |
107 | } | |
108 | } | |
109 | } | |
b0318660 | 110 | |
eb1bab5b BH |
111 | // ------------------------------------------------------------------------ |
112 | // Accessors | |
113 | // ------------------------------------------------------------------------ | |
11252342 | 114 | |
eb1bab5b BH |
115 | @Override |
116 | public TraceSessionState getSessionState() { | |
117 | return fState; | |
118 | } | |
119 | ||
eb1bab5b BH |
120 | @Override |
121 | public void setSessionState(TraceSessionState state) { | |
122 | fState = state; | |
123 | } | |
124 | ||
eb1bab5b BH |
125 | @Override |
126 | public void setSessionState(String stateName) { | |
127 | if (TraceSessionState.INACTIVE.getInName().equals(stateName)) { | |
128 | fState = TraceSessionState.INACTIVE; | |
129 | } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) { | |
130 | fState = TraceSessionState.ACTIVE; | |
131 | } | |
132 | } | |
b0318660 | 133 | |
eb1bab5b BH |
134 | @Override |
135 | public String getSessionPath() { | |
f7d4d450 | 136 | if (isSnapshotSession() && fSnapshotInfo != null) { |
589d0d33 BH |
137 | return fSnapshotInfo.getSnapshotPath(); |
138 | } | |
eb1bab5b BH |
139 | return fSessionPath; |
140 | } | |
141 | ||
eb1bab5b BH |
142 | @Override |
143 | public void setSessionPath(String path) { | |
144 | fSessionPath = path; | |
145 | } | |
146 | ||
eb1bab5b BH |
147 | @Override |
148 | public IDomainInfo[] getDomains() { | |
149 | return fDomains.toArray(new IDomainInfo[fDomains.size()]); | |
150 | } | |
151 | ||
eb1bab5b BH |
152 | @Override |
153 | public void setDomains(List<IDomainInfo> domains) { | |
a6702bfa | 154 | fDomains.clear(); |
eb1bab5b | 155 | for (Iterator<IDomainInfo> iterator = domains.iterator(); iterator.hasNext();) { |
b0318660 | 156 | IDomainInfo domainInfo = iterator.next(); |
eb1bab5b BH |
157 | fDomains.add(domainInfo); |
158 | } | |
159 | } | |
160 | ||
f3b33d40 BH |
161 | @Override |
162 | public boolean isStreamedTrace() { | |
163 | return fIsStreamedTrace; | |
164 | } | |
165 | ||
f3b33d40 BH |
166 | @Override |
167 | public void setStreamedTrace(boolean isStreamedTrace) { | |
168 | fIsStreamedTrace = isStreamedTrace; | |
169 | } | |
170 | ||
589d0d33 BH |
171 | @Override |
172 | public boolean isSnapshotSession() { | |
f7d4d450 MAL |
173 | return fIsSnapshot || fSnapshotInfo != null; |
174 | } | |
175 | ||
176 | @Override | |
177 | public void setSnapshot(boolean isSnapshot) { | |
178 | fIsSnapshot = isSnapshot; | |
589d0d33 | 179 | } |
11252342 | 180 | |
eb1bab5b | 181 | @Override |
589d0d33 BH |
182 | public ISnapshotInfo getSnapshotInfo() { |
183 | return fSnapshotInfo; | |
eb1bab5b | 184 | } |
b0318660 | 185 | |
d132bcc7 | 186 | @Override |
589d0d33 BH |
187 | public void setSnapshotInfo(ISnapshotInfo info) { |
188 | fSnapshotInfo = info; | |
eb1bab5b BH |
189 | } |
190 | ||
589d0d33 BH |
191 | // ------------------------------------------------------------------------ |
192 | // Operations | |
193 | // ------------------------------------------------------------------------ | |
194 | ||
eb1bab5b | 195 | @Override |
589d0d33 BH |
196 | public void addDomain(IDomainInfo domainInfo) { |
197 | fDomains.add(domainInfo); | |
eb1bab5b | 198 | } |
d132bcc7 | 199 | |
589d0d33 | 200 | |
eb1bab5b BH |
201 | @SuppressWarnings("nls") |
202 | @Override | |
203 | public String toString() { | |
204 | StringBuffer output = new StringBuffer(); | |
205 | output.append("[SessionInfo("); | |
206 | output.append(super.toString()); | |
589d0d33 BH |
207 | output.append(",Path="); |
208 | output.append(getSessionPath()); | |
eb1bab5b BH |
209 | output.append(",State="); |
210 | output.append(fState); | |
a30e79fe BH |
211 | output.append(",isStreamedTrace="); |
212 | output.append(fIsStreamedTrace); | |
f7d4d450 MAL |
213 | output.append(",isSnapshot="); |
214 | output.append(fIsSnapshot); | |
215 | ||
589d0d33 BH |
216 | if (fSnapshotInfo != null) { |
217 | output.append(",snapshotInfo="); | |
218 | output.append(fSnapshotInfo.toString()); | |
219 | } | |
eb1bab5b BH |
220 | output.append(",Domains="); |
221 | for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) { | |
b0318660 | 222 | IDomainInfo domain = iterator.next(); |
d132bcc7 | 223 | output.append(domain.toString()); |
eb1bab5b | 224 | } |
f7d4d450 MAL |
225 | |
226 | output.append(",NetworkUrl="); | |
227 | output.append(getNetworkUrl()); | |
228 | output.append(",ControlUrl="); | |
229 | output.append(getControlUrl()); | |
230 | output.append(",DataUrl="); | |
231 | output.append(getDataUrl()); | |
232 | ||
eb1bab5b BH |
233 | output.append(")]"); |
234 | return output.toString(); | |
235 | } | |
f7d4d450 MAL |
236 | |
237 | @Override | |
238 | public String getNetworkUrl() { | |
239 | return fNetworkUrl; | |
240 | } | |
241 | ||
242 | @Override | |
243 | public void setNetworkUrl(String networkUrl) { | |
244 | fNetworkUrl = networkUrl; | |
245 | } | |
246 | ||
247 | @Override | |
248 | public String getControlUrl() { | |
249 | return fControlUrl; | |
250 | } | |
251 | ||
252 | @Override | |
253 | public void setControlUrl(String controlUrl) { | |
254 | fControlUrl = controlUrl; | |
255 | } | |
256 | ||
257 | @Override | |
258 | public void setDataUrl(String datalUrl) { | |
259 | fDataUrl = datalUrl; | |
260 | } | |
261 | ||
262 | @Override | |
263 | public String getDataUrl() { | |
264 | return fDataUrl; | |
265 | } | |
eb1bab5b | 266 | } |