Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 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 | **********************************************************************/ | |
31a6a4e4 | 12 | package org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl; |
eb1bab5b BH |
13 | |
14 | import java.util.ArrayList; | |
15 | import java.util.Iterator; | |
16 | import java.util.List; | |
17 | ||
31a6a4e4 BH |
18 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo; |
19 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo; | |
20 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.TraceSessionState; | |
eb1bab5b BH |
21 | |
22 | /** | |
23 | * <b><u>SessionInfo</u></b> | |
24 | * <p> | |
25 | * Implementation of the trace session interface (ISessionInfo) to store session | |
26 | * related data. | |
27 | * </p> | |
28 | */ | |
29 | public class SessionInfo extends TraceInfo implements ISessionInfo { | |
30 | ||
31 | // ------------------------------------------------------------------------ | |
32 | // Attributes | |
33 | // ------------------------------------------------------------------------ | |
34 | /** | |
35 | * The trace session state. | |
36 | */ | |
37 | private TraceSessionState fState = TraceSessionState.INACTIVE; | |
38 | /** | |
39 | * The trace session path for storing traces. | |
40 | */ | |
41 | private String fSessionPath = ""; //$NON-NLS-1$ | |
42 | /** | |
43 | * The domains information of this session. | |
44 | */ | |
45 | private List<IDomainInfo> fDomains = new ArrayList<IDomainInfo>(); | |
46 | ||
47 | // ------------------------------------------------------------------------ | |
48 | // Constructors | |
49 | // ------------------------------------------------------------------------ | |
50 | /** | |
51 | * Constructor | |
52 | * @param name - name of base event | |
53 | */ | |
54 | public SessionInfo(String name) { | |
55 | super(name); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Copy constructor | |
60 | * @param other - the instance to copy | |
61 | */ | |
62 | public SessionInfo(SessionInfo other) { | |
63 | super(other); | |
64 | fState = other.fState; | |
65 | fSessionPath = other.fSessionPath; | |
66 | ||
67 | for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) { | |
68 | IDomainInfo domain = iterator.next(); | |
69 | if (domain instanceof DomainInfo) { | |
70 | fDomains.add(new DomainInfo((DomainInfo)domain)); | |
71 | } else { | |
72 | fDomains.add(domain); | |
73 | } | |
74 | } | |
75 | } | |
76 | ||
77 | // ------------------------------------------------------------------------ | |
78 | // Accessors | |
79 | // ------------------------------------------------------------------------ | |
80 | /* | |
81 | * (non-Javadoc) | |
31a6a4e4 | 82 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo#getSessionState() |
eb1bab5b BH |
83 | */ |
84 | @Override | |
85 | public TraceSessionState getSessionState() { | |
86 | return fState; | |
87 | } | |
88 | ||
89 | /* | |
90 | * (non-Javadoc) | |
31a6a4e4 | 91 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo#setSessionState(org.eclipse.linuxtools.internal.lttng.ui.views.control.model.TraceSessionState) |
eb1bab5b BH |
92 | */ |
93 | @Override | |
94 | public void setSessionState(TraceSessionState state) { | |
95 | fState = state; | |
96 | } | |
97 | ||
98 | /* | |
99 | * (non-Javadoc) | |
31a6a4e4 | 100 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo#setSessionState(java.lang.String) |
eb1bab5b BH |
101 | */ |
102 | @Override | |
103 | public void setSessionState(String stateName) { | |
104 | if (TraceSessionState.INACTIVE.getInName().equals(stateName)) { | |
105 | fState = TraceSessionState.INACTIVE; | |
106 | } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) { | |
107 | fState = TraceSessionState.ACTIVE; | |
108 | } | |
109 | } | |
110 | ||
111 | /* | |
112 | * (non-Javadoc) | |
31a6a4e4 | 113 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo#getSessionPath() |
eb1bab5b BH |
114 | */ |
115 | @Override | |
116 | public String getSessionPath() { | |
117 | return fSessionPath; | |
118 | } | |
119 | ||
120 | /* | |
121 | * (non-Javadoc) | |
31a6a4e4 | 122 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo#setSessionPath(java.lang.String) |
eb1bab5b BH |
123 | */ |
124 | @Override | |
125 | public void setSessionPath(String path) { | |
126 | fSessionPath = path; | |
127 | } | |
128 | ||
129 | /* | |
130 | * (non-Javadoc) | |
31a6a4e4 | 131 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo#getDomains() |
eb1bab5b BH |
132 | */ |
133 | @Override | |
134 | public IDomainInfo[] getDomains() { | |
135 | return fDomains.toArray(new IDomainInfo[fDomains.size()]); | |
136 | } | |
137 | ||
138 | /* | |
139 | * (non-Javadoc) | |
31a6a4e4 | 140 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo#setDomains(java.util.List) |
eb1bab5b BH |
141 | */ |
142 | @Override | |
143 | public void setDomains(List<IDomainInfo> domains) { | |
144 | for (Iterator<IDomainInfo> iterator = domains.iterator(); iterator.hasNext();) { | |
145 | IDomainInfo domainInfo = (IDomainInfo) iterator.next(); | |
146 | fDomains.add(domainInfo); | |
147 | } | |
148 | } | |
149 | ||
150 | // ------------------------------------------------------------------------ | |
151 | // Operations | |
152 | // ------------------------------------------------------------------------ | |
153 | /* | |
154 | * (non-Javadoc) | |
31a6a4e4 | 155 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ISessionInfo#addDomain(org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo) |
eb1bab5b BH |
156 | */ |
157 | @Override | |
158 | public void addDomain(IDomainInfo domainInfo) { | |
159 | fDomains.add(domainInfo); | |
160 | } | |
d132bcc7 | 161 | |
eb1bab5b BH |
162 | /* |
163 | * (non-Javadoc) | |
31a6a4e4 | 164 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ITraceInfo#formatString() |
eb1bab5b BH |
165 | */ |
166 | @Override | |
d132bcc7 BH |
167 | @SuppressWarnings("nls") |
168 | public String formatString() { | |
169 | StringBuffer output = new StringBuffer(); | |
170 | // Tracing session mysession: [active] | |
171 | output.append("Tracing session "); | |
172 | output.append(getName()); | |
173 | output.append(": ["); | |
174 | output.append(getSessionState().getInName()); | |
175 | output.append("]\n"); | |
176 | ||
177 | // Trace path: /home/user/lttng-traces/mysession-20120129-084256 | |
178 | output.append(" Trace path: "); | |
179 | output.append(getSessionPath()); | |
180 | output.append("\n"); | |
181 | ||
eb1bab5b BH |
182 | for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) { |
183 | IDomainInfo domain = (IDomainInfo) iterator.next(); | |
d132bcc7 | 184 | output.append(domain.formatString()); |
eb1bab5b | 185 | } |
d132bcc7 BH |
186 | return output.toString(); |
187 | } | |
188 | ||
189 | /* | |
190 | * (non-Javadoc) | |
31a6a4e4 | 191 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#hashCode() |
d132bcc7 BH |
192 | */ |
193 | @Override | |
194 | public int hashCode() { | |
195 | final int prime = 31; | |
196 | int result = super.hashCode(); | |
197 | result = prime * result + ((fDomains == null) ? 0 : fDomains.hashCode()); | |
198 | result = prime * result + ((fSessionPath == null) ? 0 : fSessionPath.hashCode()); | |
199 | result = prime * result + ((fState == null) ? 0 : (fState.ordinal() + 1)); | |
eb1bab5b BH |
200 | return result; |
201 | } | |
202 | ||
203 | /* | |
204 | * (non-Javadoc) | |
31a6a4e4 | 205 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) |
eb1bab5b BH |
206 | */ |
207 | @Override | |
d132bcc7 BH |
208 | public boolean equals(Object obj) { |
209 | if (this == obj) { | |
210 | return true; | |
eb1bab5b | 211 | } |
d132bcc7 | 212 | if (!super.equals(obj)) { |
eb1bab5b BH |
213 | return false; |
214 | } | |
d132bcc7 | 215 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
216 | return false; |
217 | } | |
d132bcc7 BH |
218 | SessionInfo other = (SessionInfo) obj; |
219 | if (fDomains == null) { | |
220 | if (other.fDomains != null) { | |
221 | return false; | |
222 | } | |
223 | } else if (!fDomains.equals(other.fDomains)) { | |
eb1bab5b BH |
224 | return false; |
225 | } | |
d132bcc7 BH |
226 | if (fSessionPath == null) { |
227 | if (other.fSessionPath != null) { | |
eb1bab5b BH |
228 | return false; |
229 | } | |
d132bcc7 BH |
230 | } else if (!fSessionPath.equals(other.fSessionPath)) { |
231 | return false; | |
232 | } | |
233 | if (fState != other.fState) { | |
234 | return false; | |
eb1bab5b BH |
235 | } |
236 | return true; | |
237 | } | |
d132bcc7 | 238 | |
eb1bab5b BH |
239 | /* |
240 | * (non-Javadoc) | |
31a6a4e4 | 241 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#toString() |
eb1bab5b BH |
242 | */ |
243 | @SuppressWarnings("nls") | |
244 | @Override | |
245 | public String toString() { | |
246 | StringBuffer output = new StringBuffer(); | |
247 | output.append("[SessionInfo("); | |
248 | output.append(super.toString()); | |
249 | output.append(",State="); | |
250 | output.append(fState); | |
251 | output.append(",Domains="); | |
252 | for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) { | |
d132bcc7 BH |
253 | IDomainInfo domain = (IDomainInfo) iterator.next(); |
254 | output.append(domain.toString()); | |
eb1bab5b BH |
255 | } |
256 | output.append(")]"); | |
257 | return output.toString(); | |
258 | } | |
259 | } |