1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
;
15 import java
.util
.List
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
20 import org
.eclipse
.core
.runtime
.Status
;
21 import org
.eclipse
.core
.runtime
.jobs
.Job
;
22 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TargetNodeState
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.property
.TargetNodePropertySource
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandShell
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.IRemoteSystemProxy
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.RemoteSystemProxy
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ILttngControlService
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.LTTngControlServiceFactory
;
33 import org
.eclipse
.rse
.core
.RSECorePlugin
;
34 import org
.eclipse
.rse
.core
.model
.IHost
;
35 import org
.eclipse
.rse
.core
.model
.IRSECallback
;
36 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
37 import org
.eclipse
.rse
.core
.subsystems
.CommunicationsEvent
;
38 import org
.eclipse
.rse
.core
.subsystems
.ICommunicationsListener
;
39 import org
.eclipse
.swt
.graphics
.Image
;
40 import org
.eclipse
.swt
.widgets
.Display
;
41 import org
.eclipse
.ui
.PlatformUI
;
42 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
46 * Implementation of the trace node component.
49 * @author Bernd Hufmann
51 public class TargetNodeComponent
extends TraceControlComponent
implements ICommunicationsListener
{
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 * Path to icon file for this component (state connected).
59 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
61 * Path to icon file for this component (state disconnected).
63 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 * The node connection state.
71 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
73 * The image to be displayed in state disconnected.
75 private Image fDisconnectedImage
= null;
77 * The connection implementation.
79 private IHost fHost
= null;
81 * The remote proxy implementation.
83 private IRemoteSystemProxy fRemoteProxy
= null;
85 * The control service for LTTng specific commands.
87 private ILttngControlService fService
= null;
89 * The command shell for issuing commands.
91 private ICommandShell fShell
= null;
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * @param name - the name of the component
99 * @param parent - the parent of the component
100 * @param host - the host connection implementation
101 * @param proxy - the remote proxy implementation
103 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
, IRemoteSystemProxy proxy
) {
105 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
106 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
108 fRemoteProxy
= proxy
;
109 setToolTip(fHost
.getHostName());
113 * Constructor (using default proxy)
114 * @param name - the name of the component
115 * @param parent - the parent of the component
116 * @param host - the host connection implementation
118 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
) {
119 this(name
, parent
, host
, new RemoteSystemProxy(host
));
122 // ------------------------------------------------------------------------
124 // ------------------------------------------------------------------------
127 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
130 public Image
getImage() {
131 if (fState
== TargetNodeState
.CONNECTED
) {
132 return super.getImage();
134 return fDisconnectedImage
;
139 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState()
142 public TargetNodeState
getTargetNodeState() {
148 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent.TargetNodeState)
151 public void setTargetNodeState(TargetNodeState state
) {
153 fireComponentChanged(TargetNodeComponent
.this);
158 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getControlService()
161 public ILttngControlService
getControlService() {
167 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setControlService(org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService)
170 public void setControlService(ILttngControlService service
) {
176 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
179 public Object
getAdapter(Class adapter
) {
180 if (adapter
== IPropertySource
.class) {
181 return new TargetNodePropertySource(this);
187 * @return remote host name
189 public String
getHostName() {
190 return fHost
.getHostName();
194 * @return remote system proxy implementation
196 public IRemoteSystemProxy
getRemoteSystemProxy() {
201 * @return port of IP connection (shell) to be used
203 public int getPort() {
204 return fRemoteProxy
.getPort();
208 * Sets the port of the IP connections of the shell
209 * @param port - the IP port to set
211 public void setPort(int port
) {
212 fRemoteProxy
.setPort(port
);
216 * @return all available sessions.
218 public TraceSessionComponent
[] getSessions() {
219 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
220 if (compenents
.size() > 0) {
221 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
222 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
223 return sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
225 return new TraceSessionComponent
[0];
229 * @return node version
231 public String
getNodeVersion() {
232 // Control service is null during connection to node
233 if (getControlService() != null) {
234 return getControlService().getVersion();
236 return ""; //$NON-NLS-1$
240 * Returns if node supports filtering of events
241 * @return <code>true</code> if node supports filtering else <code>false</code>
243 public boolean isEventFilteringSupported() {
244 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
248 * Returns if node supports networks streaming or not
249 * @return <code>true</code> if node supports filtering else <code>false</code>
252 public boolean isNetworkStreamingSupported() {
253 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
256 // ------------------------------------------------------------------------
258 // ------------------------------------------------------------------------
261 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
264 public void communicationsStateChange(CommunicationsEvent e
) {
265 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
266 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
267 handleDisconnected();
268 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
274 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
277 public boolean isPassiveCommunicationsListener() {
283 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceControlComponent#dispose()
286 public void dispose() {
287 fRemoteProxy
.removeCommunicationListener(this);
291 * Method to connect this node component to the remote target node.
293 public void connect() {
294 if (fState
== TargetNodeState
.DISCONNECTED
) {
296 setTargetNodeState(TargetNodeState
.CONNECTING
);
297 fRemoteProxy
.connect(new IRSECallback() {
299 public void done(IStatus status
, Object result
) {
300 // Note: result might be null!
304 handleDisconnected();
308 } catch (Exception e
) {
309 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
310 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
316 * Method to disconnect this node component to the remote target node.
318 public void disconnect() {
319 if (fState
== TargetNodeState
.CONNECTED
) {
321 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
322 fRemoteProxy
.disconnect();
323 } catch (Exception e
) {
324 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
326 handleDisconnected();
332 * Retrieves the trace configuration from the target node and populates the
333 * information in the tree model. The execution is done in a own job.
335 public void getConfigurationFromNode() {
336 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
338 protected IStatus
run(IProgressMonitor monitor
) {
341 // Get provider information from node
342 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
343 addChild(providerGroup
);
344 providerGroup
.getProviderFromNode(monitor
);
346 // Get session information from node
347 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
348 addChild(sessionGroup
);
349 sessionGroup
.getSessionsFromNode(monitor
);
350 } catch (ExecutionException e
) {
352 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
, e
);
355 return Status
.OK_STATUS
;
363 * Refresh the node configuration
365 public void refresh() {
367 getConfigurationFromNode();
371 * Deregisters host from registry.
373 public void deregister() {
374 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
375 registry
.deleteHost(fHost
);
378 // ------------------------------------------------------------------------
380 // ------------------------------------------------------------------------
382 * @return returns the control service for LTTng specific commands.
383 * @throws ExecutionException
385 private ILttngControlService
createControlService() throws ExecutionException
{
386 if (fShell
== null) {
387 fShell
= fRemoteProxy
.createCommandShell();
388 fRemoteProxy
.addCommunicationListener(this);
390 fService
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
395 * Handles the connected event.
397 private void handleConnected() {
398 setTargetNodeState(TargetNodeState
.CONNECTED
);
400 createControlService();
401 getConfigurationFromNode();
402 } catch (final ExecutionException e
) {
403 // Disconnect only if no control service, otherwise stay connected.
404 if (getControlService() == null) {
409 Display
.getDefault().asyncExec(new Runnable() {
412 ErrorDialog er
= new ErrorDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
413 Messages
.TraceControl_ErrorTitle
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
,
414 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.getMessage(), e
),
419 Activator
.getDefault().logError(Messages
.TraceControl_RetrieveNodeConfigurationFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
424 * Handles the disconnected event.
426 private void handleDisconnected() {
428 setTargetNodeState(TargetNodeState
.DISCONNECTED
);