Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
cfdb727a | 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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
eb1bab5b BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
115b4a01 | 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; |
eb1bab5b | 13 | |
6503ae0f BH |
14 | import java.util.List; |
15 | ||
eb1bab5b BH |
16 | import org.eclipse.core.commands.ExecutionException; |
17 | import org.eclipse.core.runtime.IProgressMonitor; | |
18 | import org.eclipse.core.runtime.IStatus; | |
19 | import org.eclipse.core.runtime.Status; | |
20 | import org.eclipse.core.runtime.jobs.Job; | |
9315aeee | 21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState; |
115b4a01 | 22 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
9315aeee | 23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
115b4a01 | 24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
115b4a01 | 25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TargetNodePropertySource; |
9315aeee | 26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandShell; |
115b4a01 BH |
27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy; |
28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.RemoteSystemProxy; | |
115b4a01 | 29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService; |
276c17e7 | 30 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory; |
8577ed1e | 31 | import org.eclipse.rse.core.RSECorePlugin; |
eb1bab5b BH |
32 | import org.eclipse.rse.core.model.IHost; |
33 | import org.eclipse.rse.core.model.IRSECallback; | |
8577ed1e | 34 | import org.eclipse.rse.core.model.ISystemRegistry; |
eb1bab5b BH |
35 | import org.eclipse.rse.core.subsystems.CommunicationsEvent; |
36 | import org.eclipse.rse.core.subsystems.ICommunicationsListener; | |
37 | import org.eclipse.swt.graphics.Image; | |
38 | import org.eclipse.ui.views.properties.IPropertySource; | |
39 | ||
40 | /** | |
eb1bab5b BH |
41 | * <p> |
42 | * Implementation of the trace node component. | |
43 | * </p> | |
cfdb727a | 44 | * |
dbd4432d | 45 | * @author Bernd Hufmann |
eb1bab5b BH |
46 | */ |
47 | public class TargetNodeComponent extends TraceControlComponent implements ICommunicationsListener { | |
48 | ||
49 | // ------------------------------------------------------------------------ | |
50 | // Constants | |
51 | // ------------------------------------------------------------------------ | |
52 | /** | |
53 | * Path to icon file for this component (state connected). | |
54 | */ | |
55 | public static final String TARGET_NODE_CONNECTED_ICON_FILE = "icons/obj16/target_connected.gif"; //$NON-NLS-1$ | |
56 | /** | |
57 | * Path to icon file for this component (state disconnected). | |
58 | */ | |
59 | public static final String TARGET_NODE_DISCONNECTED_ICON_FILE = "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$ | |
60 | ||
61 | // ------------------------------------------------------------------------ | |
62 | // Attributes | |
63 | // ------------------------------------------------------------------------ | |
64 | /** | |
65 | * The node connection state. | |
66 | */ | |
67 | private TargetNodeState fState = TargetNodeState.DISCONNECTED; | |
68 | /** | |
69 | * The image to be displayed in state disconnected. | |
70 | */ | |
71 | private Image fDisconnectedImage = null; | |
72 | /** | |
73 | * The connection implementation. | |
74 | */ | |
75 | private IHost fHost = null; | |
76 | /** | |
77 | * The remote proxy implementation. | |
78 | */ | |
79 | private IRemoteSystemProxy fRemoteProxy = null; | |
80 | /** | |
81 | * The control service for LTTng specific commands. | |
82 | */ | |
83 | private ILttngControlService fService = null; | |
84 | /** | |
85 | * The command shell for issuing commands. | |
86 | */ | |
87 | private ICommandShell fShell = null; | |
88 | ||
89 | // ------------------------------------------------------------------------ | |
90 | // Constructors | |
91 | // ------------------------------------------------------------------------ | |
92 | /** | |
cfdb727a | 93 | * Constructor |
eb1bab5b BH |
94 | * @param name - the name of the component |
95 | * @param parent - the parent of the component | |
96 | * @param host - the host connection implementation | |
97 | * @param proxy - the remote proxy implementation | |
98 | */ | |
99 | public TargetNodeComponent(String name, ITraceControlComponent parent, IHost host, IRemoteSystemProxy proxy) { | |
100 | super(name, parent); | |
101 | setImage(TARGET_NODE_CONNECTED_ICON_FILE); | |
31a6a4e4 | 102 | fDisconnectedImage = Activator.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE); |
eb1bab5b BH |
103 | fHost = host; |
104 | fRemoteProxy = proxy; | |
105 | setToolTip(fHost.getHostName()); | |
106 | } | |
107 | ||
108 | /** | |
cfdb727a | 109 | * Constructor (using default proxy) |
eb1bab5b BH |
110 | * @param name - the name of the component |
111 | * @param parent - the parent of the component | |
112 | * @param host - the host connection implementation | |
113 | */ | |
114 | public TargetNodeComponent(String name, ITraceControlComponent parent, IHost host) { | |
115 | this(name, parent, host, new RemoteSystemProxy(host)); | |
116 | } | |
117 | ||
118 | // ------------------------------------------------------------------------ | |
119 | // Accessors | |
120 | // ------------------------------------------------------------------------ | |
121 | /* | |
122 | * (non-Javadoc) | |
115b4a01 | 123 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage() |
eb1bab5b BH |
124 | */ |
125 | @Override | |
126 | public Image getImage() { | |
127 | if (fState == TargetNodeState.CONNECTED) { | |
128 | return super.getImage(); | |
129 | } | |
130 | return fDisconnectedImage; | |
131 | } | |
cfdb727a | 132 | |
eb1bab5b BH |
133 | /* |
134 | * (non-Javadoc) | |
115b4a01 | 135 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState() |
eb1bab5b BH |
136 | */ |
137 | @Override | |
138 | public TargetNodeState getTargetNodeState() { | |
139 | return fState; | |
140 | } | |
cfdb727a | 141 | |
eb1bab5b BH |
142 | /* |
143 | * (non-Javadoc) | |
115b4a01 | 144 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent.TargetNodeState) |
eb1bab5b BH |
145 | */ |
146 | @Override | |
147 | public void setTargetNodeState(TargetNodeState state) { | |
148 | fState = state; | |
4775bcbf | 149 | fireComponentChanged(TargetNodeComponent.this); |
eb1bab5b | 150 | } |
cfdb727a | 151 | |
eb1bab5b BH |
152 | /* |
153 | * (non-Javadoc) | |
115b4a01 | 154 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getControlService() |
eb1bab5b BH |
155 | */ |
156 | @Override | |
157 | public ILttngControlService getControlService() { | |
158 | return fService; | |
159 | } | |
160 | ||
161 | /* | |
162 | * (non-Javadoc) | |
115b4a01 | 163 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setControlService(org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService) |
eb1bab5b BH |
164 | */ |
165 | @Override | |
166 | public void setControlService(ILttngControlService service) { | |
cfdb727a | 167 | fService = service; |
eb1bab5b BH |
168 | } |
169 | ||
170 | /* | |
171 | * (non-Javadoc) | |
115b4a01 | 172 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) |
eb1bab5b | 173 | */ |
eb1bab5b BH |
174 | @Override |
175 | public Object getAdapter(Class adapter) { | |
176 | if (adapter == IPropertySource.class) { | |
177 | return new TargetNodePropertySource(this); | |
178 | } | |
179 | return null; | |
cfdb727a AM |
180 | } |
181 | ||
bbb3538a BH |
182 | /** |
183 | * @return remote host name | |
184 | */ | |
eb1bab5b BH |
185 | public String getHostName() { |
186 | return fHost.getHostName(); | |
187 | } | |
188 | ||
bbb3538a BH |
189 | /** |
190 | * @return remote system proxy implementation | |
191 | */ | |
192 | public IRemoteSystemProxy getRemoteSystemProxy() { | |
193 | return fRemoteProxy; | |
194 | } | |
195 | ||
6503ae0f BH |
196 | /** |
197 | * @return all available sessions. | |
198 | */ | |
199 | public TraceSessionComponent[] getSessions() { | |
200 | List<ITraceControlComponent> compenents = getChildren(TraceSessionGroup.class); | |
201 | if (compenents.size() > 0) { | |
cfdb727a | 202 | TraceSessionGroup group = (TraceSessionGroup)compenents.get(0); |
6503ae0f | 203 | List<ITraceControlComponent> sessions = group.getChildren(TraceSessionComponent.class); |
cfdb727a | 204 | return sessions.toArray(new TraceSessionComponent[sessions.size()]); |
6503ae0f BH |
205 | } |
206 | return new TraceSessionComponent[0]; | |
207 | } | |
cfdb727a | 208 | |
cfe737e4 BH |
209 | /** |
210 | * @return node version | |
211 | */ | |
212 | public String getNodeVersion() { | |
213 | // Control service is null during connection to node | |
214 | if (getControlService() != null) { | |
215 | return getControlService().getVersion(); | |
216 | } | |
217 | return ""; //$NON-NLS-1$ | |
218 | } | |
219 | ||
d4514365 BH |
220 | /** |
221 | * Returns if node supports filtering of events | |
222 | * @return <code>true</code> if node supports filtering else <code>false</code> | |
223 | */ | |
224 | public boolean isEventFilteringSupported() { | |
225 | return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$ | |
226 | } | |
227 | ||
eb1bab5b BH |
228 | // ------------------------------------------------------------------------ |
229 | // Operations | |
230 | // ------------------------------------------------------------------------ | |
cfdb727a | 231 | |
eb1bab5b BH |
232 | /* |
233 | * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent) | |
234 | */ | |
235 | @Override | |
236 | public void communicationsStateChange(CommunicationsEvent e) { | |
237 | if (e.getState() == CommunicationsEvent.AFTER_DISCONNECT || | |
238 | e.getState() == CommunicationsEvent.CONNECTION_ERROR) { | |
239 | handleDisconnected(); | |
240 | } if ((e.getState() == CommunicationsEvent.AFTER_CONNECT) && (fState != TargetNodeState.CONNECTING)) { | |
241 | handleConnected(); | |
242 | } | |
243 | } | |
244 | ||
245 | /* (non-Javadoc) | |
246 | * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener() | |
247 | */ | |
248 | @Override | |
249 | public boolean isPassiveCommunicationsListener() { | |
250 | return true; | |
251 | } | |
252 | ||
253 | /* | |
254 | * (non-Javadoc) | |
115b4a01 | 255 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceControlComponent#dispose() |
eb1bab5b BH |
256 | */ |
257 | @Override | |
258 | public void dispose() { | |
259 | fRemoteProxy.removeCommunicationListener(this); | |
260 | } | |
261 | ||
262 | /** | |
263 | * Method to connect this node component to the remote target node. | |
264 | */ | |
265 | public void connect() { | |
266 | if (fState == TargetNodeState.DISCONNECTED) { | |
267 | try { | |
268 | setTargetNodeState(TargetNodeState.CONNECTING); | |
269 | fRemoteProxy.connect(new IRSECallback() { | |
270 | @Override | |
271 | public void done(IStatus status, Object result) { | |
272 | // Note: result might be null! | |
273 | if(status.isOK()) { | |
274 | handleConnected(); | |
06b9339e BH |
275 | } else { |
276 | handleDisconnected(); | |
eb1bab5b BH |
277 | } |
278 | } | |
279 | }); | |
280 | } catch (Exception e) { | |
281 | setTargetNodeState(TargetNodeState.DISCONNECTED); | |
9fa32496 | 282 | Activator.getDefault().logError(Messages.TraceControl_ConnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ |
eb1bab5b BH |
283 | } |
284 | } | |
285 | } | |
286 | ||
287 | /** | |
288 | * Method to disconnect this node component to the remote target node. | |
289 | */ | |
290 | public void disconnect() { | |
291 | if (fState == TargetNodeState.CONNECTED) { | |
292 | try { | |
293 | setTargetNodeState(TargetNodeState.DISCONNECTING); | |
294 | fRemoteProxy.disconnect(); | |
295 | } catch (Exception e) { | |
9fa32496 | 296 | Activator.getDefault().logError(Messages.TraceControl_DisconnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ |
eb1bab5b | 297 | } finally { |
cfdb727a | 298 | handleDisconnected(); |
eb1bab5b BH |
299 | } |
300 | } | |
301 | } | |
302 | ||
303 | /** | |
cfdb727a AM |
304 | * Retrieves the trace configuration from the target node and populates the |
305 | * information in the tree model. The execution is done in a own job. | |
eb1bab5b | 306 | */ |
d132bcc7 | 307 | public void getConfigurationFromNode() { |
eb1bab5b BH |
308 | Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) { |
309 | @Override | |
310 | protected IStatus run(IProgressMonitor monitor) { | |
311 | ||
312 | try { | |
313 | // Get provider information from node | |
314 | TraceProviderGroup providerGroup = new TraceProviderGroup(Messages.TraceControl_ProviderDisplayName, TargetNodeComponent.this); | |
315 | addChild(providerGroup); | |
316 | providerGroup.getProviderFromNode(monitor); | |
cfdb727a | 317 | |
eb1bab5b BH |
318 | // Get session information from node |
319 | TraceSessionGroup sessionGroup = new TraceSessionGroup(Messages.TraceControl_AllSessionsDisplayName, TargetNodeComponent.this); | |
320 | addChild(sessionGroup); | |
321 | sessionGroup.getSessionsFromNode(monitor); | |
322 | } catch (ExecutionException e) { | |
323 | removeAllChildren(); | |
cfdb727a AM |
324 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ListSessionFailure, e); |
325 | } | |
eb1bab5b BH |
326 | |
327 | return Status.OK_STATUS; | |
328 | } | |
329 | }; | |
330 | job.setUser(true); | |
331 | job.schedule(); | |
d132bcc7 | 332 | } |
eb1bab5b | 333 | |
8577ed1e BH |
334 | /** |
335 | * Refresh the node configuration | |
336 | */ | |
d132bcc7 BH |
337 | public void refresh() { |
338 | removeAllChildren(); | |
339 | getConfigurationFromNode(); | |
eb1bab5b | 340 | } |
cfdb727a | 341 | |
8577ed1e BH |
342 | /** |
343 | * Deregisters host from registry. | |
344 | */ | |
345 | public void deregister() { | |
346 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); | |
347 | registry.deleteHost(fHost); | |
348 | } | |
eb1bab5b BH |
349 | |
350 | // ------------------------------------------------------------------------ | |
351 | // Helper function | |
352 | // ------------------------------------------------------------------------ | |
353 | /** | |
354 | * @return returns the control service for LTTng specific commands. | |
355 | * @throws ExecutionException | |
356 | */ | |
357 | private ILttngControlService createControlService() throws ExecutionException { | |
358 | if (fShell == null) { | |
359 | fShell = fRemoteProxy.createCommandShell(); | |
360 | fRemoteProxy.addCommunicationListener(this); | |
361 | } | |
276c17e7 | 362 | fService = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell); |
eb1bab5b BH |
363 | return fService; |
364 | } | |
365 | ||
366 | /** | |
cfdb727a | 367 | * Handles the connected event. |
eb1bab5b BH |
368 | */ |
369 | private void handleConnected() { | |
370 | setTargetNodeState(TargetNodeState.CONNECTED); | |
371 | try { | |
372 | createControlService(); | |
373 | getConfigurationFromNode(); | |
374 | } catch (ExecutionException e) { | |
9fa32496 | 375 | Activator.getDefault().logError(Messages.TraceControl_ListSessionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ |
eb1bab5b BH |
376 | } |
377 | } | |
378 | ||
379 | /** | |
cfdb727a | 380 | * Handles the disconnected event. |
eb1bab5b BH |
381 | */ |
382 | private void handleDisconnected() { | |
383 | removeAllChildren(); | |
384 | setTargetNodeState(TargetNodeState.DISCONNECTED); | |
385 | fShell = null; | |
386 | fService = null; | |
387 | } | |
388 | } |