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 all available sessions.
203 public TraceSessionComponent
[] getSessions() {
204 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
205 if (compenents
.size() > 0) {
206 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
207 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
208 return sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
210 return new TraceSessionComponent
[0];
214 * @return node version
216 public String
getNodeVersion() {
217 // Control service is null during connection to node
218 if (getControlService() != null) {
219 return getControlService().getVersion();
221 return ""; //$NON-NLS-1$
225 * Returns if node supports filtering of events
226 * @return <code>true</code> if node supports filtering else <code>false</code>
228 public boolean isEventFilteringSupported() {
229 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
233 * Returns if node supports networks streaming or not
234 * @return <code>true</code> if node supports filtering else <code>false</code>
237 public boolean isNetworkStreamingSupported() {
238 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
241 // ------------------------------------------------------------------------
243 // ------------------------------------------------------------------------
246 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
249 public void communicationsStateChange(CommunicationsEvent e
) {
250 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
251 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
252 handleDisconnected();
253 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
259 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
262 public boolean isPassiveCommunicationsListener() {
268 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceControlComponent#dispose()
271 public void dispose() {
272 fRemoteProxy
.removeCommunicationListener(this);
276 * Method to connect this node component to the remote target node.
278 public void connect() {
279 if (fState
== TargetNodeState
.DISCONNECTED
) {
281 setTargetNodeState(TargetNodeState
.CONNECTING
);
282 fRemoteProxy
.connect(new IRSECallback() {
284 public void done(IStatus status
, Object result
) {
285 // Note: result might be null!
289 handleDisconnected();
293 } catch (Exception e
) {
294 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
295 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
301 * Method to disconnect this node component to the remote target node.
303 public void disconnect() {
304 if (fState
== TargetNodeState
.CONNECTED
) {
306 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
307 fRemoteProxy
.disconnect();
308 } catch (Exception e
) {
309 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
311 handleDisconnected();
317 * Retrieves the trace configuration from the target node and populates the
318 * information in the tree model. The execution is done in a own job.
320 public void getConfigurationFromNode() {
321 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
323 protected IStatus
run(IProgressMonitor monitor
) {
326 // Get provider information from node
327 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
328 addChild(providerGroup
);
329 providerGroup
.getProviderFromNode(monitor
);
331 // Get session information from node
332 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
333 addChild(sessionGroup
);
334 sessionGroup
.getSessionsFromNode(monitor
);
335 } catch (ExecutionException e
) {
337 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
, e
);
340 return Status
.OK_STATUS
;
348 * Refresh the node configuration
350 public void refresh() {
352 getConfigurationFromNode();
356 * Deregisters host from registry.
358 public void deregister() {
359 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
360 registry
.deleteHost(fHost
);
363 // ------------------------------------------------------------------------
365 // ------------------------------------------------------------------------
367 * @return returns the control service for LTTng specific commands.
368 * @throws ExecutionException
370 private ILttngControlService
createControlService() throws ExecutionException
{
371 if (fShell
== null) {
372 fShell
= fRemoteProxy
.createCommandShell();
373 fRemoteProxy
.addCommunicationListener(this);
375 fService
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
380 * Handles the connected event.
382 private void handleConnected() {
383 setTargetNodeState(TargetNodeState
.CONNECTED
);
385 createControlService();
386 getConfigurationFromNode();
387 } catch (final ExecutionException e
) {
388 // Disconnect only if no control service, otherwise stay connected.
389 if (getControlService() == null) {
394 Display
.getDefault().asyncExec(new Runnable() {
397 ErrorDialog er
= new ErrorDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
398 Messages
.TraceControl_ErrorTitle
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
,
399 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.getMessage(), e
),
404 Activator
.getDefault().logError(Messages
.TraceControl_RetrieveNodeConfigurationFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
409 * Handles the disconnected event.
411 private void handleDisconnected() {
413 setTargetNodeState(TargetNodeState
.DISCONNECTED
);