1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
;
14 import java
.util
.List
;
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
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TargetNodeState
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.property
.TargetNodePropertySource
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandShell
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.IRemoteSystemProxy
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.RemoteSystemProxy
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ILttngControlService
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.LTTngControlServiceFactory
;
31 import org
.eclipse
.rse
.core
.RSECorePlugin
;
32 import org
.eclipse
.rse
.core
.model
.IHost
;
33 import org
.eclipse
.rse
.core
.model
.IRSECallback
;
34 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
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
;
42 * Implementation of the trace node component.
45 * @author Bernd Hufmann
47 public class TargetNodeComponent
extends TraceControlComponent
implements ICommunicationsListener
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 * Path to icon file for this component (state connected).
55 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
57 * Path to icon file for this component (state disconnected).
59 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 * The node connection state.
67 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
69 * The image to be displayed in state disconnected.
71 private Image fDisconnectedImage
= null;
73 * The connection implementation.
75 private IHost fHost
= null;
77 * The remote proxy implementation.
79 private IRemoteSystemProxy fRemoteProxy
= null;
81 * The control service for LTTng specific commands.
83 private ILttngControlService fService
= null;
85 * The command shell for issuing commands.
87 private ICommandShell fShell
= null;
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
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
99 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
, IRemoteSystemProxy proxy
) {
101 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
102 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
104 fRemoteProxy
= proxy
;
105 setToolTip(fHost
.getHostName());
109 * Constructor (using default proxy)
110 * @param name - the name of the component
111 * @param parent - the parent of the component
112 * @param host - the host connection implementation
114 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
) {
115 this(name
, parent
, host
, new RemoteSystemProxy(host
));
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
123 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
126 public Image
getImage() {
127 if (fState
== TargetNodeState
.CONNECTED
) {
128 return super.getImage();
130 return fDisconnectedImage
;
135 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState()
138 public TargetNodeState
getTargetNodeState() {
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)
147 public void setTargetNodeState(TargetNodeState state
) {
149 fireComponentChanged(TargetNodeComponent
.this);
154 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getControlService()
157 public ILttngControlService
getControlService() {
163 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setControlService(org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService)
166 public void setControlService(ILttngControlService service
) {
172 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
175 public Object
getAdapter(Class adapter
) {
176 if (adapter
== IPropertySource
.class) {
177 return new TargetNodePropertySource(this);
183 * @return remote host name
185 public String
getHostName() {
186 return fHost
.getHostName();
190 * @return remote system proxy implementation
192 public IRemoteSystemProxy
getRemoteSystemProxy() {
197 * @return all available sessions.
199 public TraceSessionComponent
[] getSessions() {
200 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
201 if (compenents
.size() > 0) {
202 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
203 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
204 return sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
206 return new TraceSessionComponent
[0];
210 * @return node version
212 public String
getNodeVersion() {
213 // Control service is null during connection to node
214 if (getControlService() != null) {
215 return getControlService().getVersion();
217 return ""; //$NON-NLS-1$
221 * Returns if node supports filtering of events
222 * @return <code>true</code> if node supports filtering else <code>false</code>
224 public boolean isEventFilteringSupported() {
225 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
229 * Returns if node supports networks streaming or not
230 * @return <code>true</code> if node supports filtering else <code>false</code>
233 public boolean isNetworkStreamingSupported() {
234 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
237 // ------------------------------------------------------------------------
239 // ------------------------------------------------------------------------
242 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
245 public void communicationsStateChange(CommunicationsEvent e
) {
246 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
247 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
248 handleDisconnected();
249 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
255 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
258 public boolean isPassiveCommunicationsListener() {
264 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceControlComponent#dispose()
267 public void dispose() {
268 fRemoteProxy
.removeCommunicationListener(this);
272 * Method to connect this node component to the remote target node.
274 public void connect() {
275 if (fState
== TargetNodeState
.DISCONNECTED
) {
277 setTargetNodeState(TargetNodeState
.CONNECTING
);
278 fRemoteProxy
.connect(new IRSECallback() {
280 public void done(IStatus status
, Object result
) {
281 // Note: result might be null!
285 handleDisconnected();
289 } catch (Exception e
) {
290 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
291 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
297 * Method to disconnect this node component to the remote target node.
299 public void disconnect() {
300 if (fState
== TargetNodeState
.CONNECTED
) {
302 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
303 fRemoteProxy
.disconnect();
304 } catch (Exception e
) {
305 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
307 handleDisconnected();
313 * Retrieves the trace configuration from the target node and populates the
314 * information in the tree model. The execution is done in a own job.
316 public void getConfigurationFromNode() {
317 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
319 protected IStatus
run(IProgressMonitor monitor
) {
322 // Get provider information from node
323 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
324 addChild(providerGroup
);
325 providerGroup
.getProviderFromNode(monitor
);
327 // Get session information from node
328 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
329 addChild(sessionGroup
);
330 sessionGroup
.getSessionsFromNode(monitor
);
331 } catch (ExecutionException e
) {
333 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ListSessionFailure
, e
);
336 return Status
.OK_STATUS
;
344 * Refresh the node configuration
346 public void refresh() {
348 getConfigurationFromNode();
352 * Deregisters host from registry.
354 public void deregister() {
355 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
356 registry
.deleteHost(fHost
);
359 // ------------------------------------------------------------------------
361 // ------------------------------------------------------------------------
363 * @return returns the control service for LTTng specific commands.
364 * @throws ExecutionException
366 private ILttngControlService
createControlService() throws ExecutionException
{
367 if (fShell
== null) {
368 fShell
= fRemoteProxy
.createCommandShell();
369 fRemoteProxy
.addCommunicationListener(this);
371 fService
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
376 * Handles the connected event.
378 private void handleConnected() {
379 setTargetNodeState(TargetNodeState
.CONNECTED
);
381 createControlService();
382 getConfigurationFromNode();
383 } catch (ExecutionException e
) {
384 Activator
.getDefault().logError(Messages
.TraceControl_ListSessionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
389 * Handles the disconnected event.
391 private void handleDisconnected() {
393 setTargetNodeState(TargetNodeState
.DISCONNECTED
);