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 // ------------------------------------------------------------------------
58 * Path to icon file for this component (state connected).
60 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
62 * Path to icon file for this component (state disconnected).
64 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
71 * The node connection state.
73 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
75 * The image to be displayed in state disconnected.
77 private Image fDisconnectedImage
= null;
79 * The connection implementation.
81 private IHost fHost
= null;
83 * The remote proxy implementation.
85 private IRemoteSystemProxy fRemoteProxy
= null;
87 * The control service for LTTng specific commands.
89 private ILttngControlService fService
= null;
91 * The command shell for issuing commands.
93 private ICommandShell fShell
= null;
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
101 * @param name - the name of the component
102 * @param parent - the parent of the component
103 * @param host - the host connection implementation
104 * @param proxy - the remote proxy implementation
106 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
, IRemoteSystemProxy proxy
) {
108 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
109 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
111 fRemoteProxy
= proxy
;
112 setToolTip(fHost
.getHostName());
116 * Constructor (using default proxy)
117 * @param name - the name of the component
118 * @param parent - the parent of the component
119 * @param host - the host connection implementation
121 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
) {
122 this(name
, parent
, host
, new RemoteSystemProxy(host
));
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
130 public Image
getImage() {
131 if (fState
== TargetNodeState
.CONNECTED
) {
132 return super.getImage();
134 return fDisconnectedImage
;
138 public TargetNodeState
getTargetNodeState() {
143 public void setTargetNodeState(TargetNodeState state
) {
145 fireComponentChanged(TargetNodeComponent
.this);
149 public ILttngControlService
getControlService() {
154 public void setControlService(ILttngControlService service
) {
159 public Object
getAdapter(Class adapter
) {
160 if (adapter
== IPropertySource
.class) {
161 return new TargetNodePropertySource(this);
167 * @return remote host name
169 public String
getHostName() {
170 return fHost
.getHostName();
174 * @return remote system proxy implementation
176 public IRemoteSystemProxy
getRemoteSystemProxy() {
181 * @return port of IP connection (shell) to be used
183 public int getPort() {
184 return fRemoteProxy
.getPort();
188 * Sets the port of the IP connections of the shell
189 * @param port - the IP port to set
191 public void setPort(int port
) {
192 fRemoteProxy
.setPort(port
);
196 * @return all available sessions.
198 public TraceSessionComponent
[] getSessions() {
199 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
200 if (compenents
.size() > 0) {
201 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
202 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
203 return sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
205 return new TraceSessionComponent
[0];
209 * @return node version
211 public String
getNodeVersion() {
212 // Control service is null during connection to node
213 if (getControlService() != null) {
214 return getControlService().getVersion();
216 return ""; //$NON-NLS-1$
220 * Returns if node supports filtering of events
221 * @return <code>true</code> if node supports filtering else <code>false</code>
223 public boolean isEventFilteringSupported() {
224 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
228 * Returns if node supports networks streaming or not
229 * @return <code>true</code> if node supports filtering else <code>false</code>
232 public boolean isNetworkStreamingSupported() {
233 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
237 * Returns if node supports configuring buffer type or not
238 * @return <code>true</code> if node supports buffer type configuration else <code>false</code>
240 public boolean isBufferTypeConfigSupported() {
241 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
245 * Returns if node supports trace file rotation or not
246 * @return <code>true</code> if node supports trace file rotation else <code>false</code>
248 public boolean isTraceFileRotationSupported() {
249 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
253 * Returns if node supports periodical flush for metadata or not
254 * @return <code>true</code> if node supports periodical flush for metadata else <code>false</code>
256 public boolean isPeriodicalMetadataFlushSupported() {
257 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
260 // ------------------------------------------------------------------------
262 // ------------------------------------------------------------------------
265 public void communicationsStateChange(CommunicationsEvent e
) {
266 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
267 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
268 handleDisconnected();
269 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
275 public boolean isPassiveCommunicationsListener() {
280 public void dispose() {
281 fRemoteProxy
.removeCommunicationListener(this);
285 * Method to connect this node component to the remote target node.
287 public void connect() {
288 if (fState
== TargetNodeState
.DISCONNECTED
) {
290 setTargetNodeState(TargetNodeState
.CONNECTING
);
291 fRemoteProxy
.connect(new IRSECallback() {
293 public void done(IStatus status
, Object result
) {
294 // Note: result might be null!
298 handleDisconnected();
302 } catch (Exception e
) {
303 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
304 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
310 * Method to disconnect this node component to the remote target node.
312 public void disconnect() {
313 if (fState
== TargetNodeState
.CONNECTED
) {
315 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
316 fRemoteProxy
.disconnect();
317 } catch (Exception e
) {
318 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
320 handleDisconnected();
326 * Retrieves the trace configuration from the target node and populates the
327 * information in the tree model. The execution is done in a own job.
329 public void getConfigurationFromNode() {
330 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
332 protected IStatus
run(IProgressMonitor monitor
) {
335 // Get provider information from node
336 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
337 addChild(providerGroup
);
338 providerGroup
.getProviderFromNode(monitor
);
340 // Get session information from node
341 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
342 addChild(sessionGroup
);
343 sessionGroup
.getSessionsFromNode(monitor
);
344 } catch (ExecutionException e
) {
346 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
, e
);
349 return Status
.OK_STATUS
;
357 * Refresh the node configuration
359 public void refresh() {
361 getConfigurationFromNode();
365 * Deregisters host from registry.
367 public void deregister() {
368 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
369 registry
.deleteHost(fHost
);
372 // ------------------------------------------------------------------------
374 // ------------------------------------------------------------------------
377 * @return returns the control service for LTTng specific commands.
378 * @throws ExecutionException
380 private ILttngControlService
createControlService() throws ExecutionException
{
381 if (fShell
== null) {
382 fShell
= fRemoteProxy
.createCommandShell();
383 fRemoteProxy
.addCommunicationListener(this);
385 fService
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
390 * Handles the connected event.
392 private void handleConnected() {
393 setTargetNodeState(TargetNodeState
.CONNECTED
);
395 createControlService();
396 getConfigurationFromNode();
397 } catch (final ExecutionException e
) {
398 // Disconnect only if no control service, otherwise stay connected.
399 if (getControlService() == null) {
404 Display
.getDefault().asyncExec(new Runnable() {
407 ErrorDialog er
= new ErrorDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
408 Messages
.TraceControl_ErrorTitle
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
,
409 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.getMessage(), e
),
414 Activator
.getDefault().logError(Messages
.TraceControl_RetrieveNodeConfigurationFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
419 * Handles the disconnected event.
421 private void handleDisconnected() {
423 setTargetNodeState(TargetNodeState
.DISCONNECTED
);