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
.ui
.Activator
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TargetNodeState
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.property
.TargetNodePropertySource
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.IRemoteSystemProxy
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.RemoteSystemProxy
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ICommandShell
;
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
;
41 * <b><u>TargetNodeComponent</u></b>
43 * Implementation of the trace node component.
46 public class TargetNodeComponent
extends TraceControlComponent
implements ICommunicationsListener
{
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * Path to icon file for this component (state connected).
54 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
56 * Path to icon file for this component (state disconnected).
58 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 * The node connection state.
66 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
68 * The image to be displayed in state disconnected.
70 private Image fDisconnectedImage
= null;
72 * The connection implementation.
74 private IHost fHost
= null;
76 * The remote proxy implementation.
78 private IRemoteSystemProxy fRemoteProxy
= null;
80 * The control service for LTTng specific commands.
82 private ILttngControlService fService
= null;
84 * The command shell for issuing commands.
86 private ICommandShell fShell
= null;
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
93 * @param name - the name of the component
94 * @param parent - the parent of the component
95 * @param host - the host connection implementation
96 * @param proxy - the remote proxy implementation
98 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
, IRemoteSystemProxy proxy
) {
100 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
101 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
103 fRemoteProxy
= proxy
;
104 setToolTip(fHost
.getHostName());
108 * Constructor (using default proxy)
109 * @param name - the name of the component
110 * @param parent - the parent of the component
111 * @param host - the host connection implementation
113 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
) {
114 this(name
, parent
, host
, new RemoteSystemProxy(host
));
117 // ------------------------------------------------------------------------
119 // ------------------------------------------------------------------------
122 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
125 public Image
getImage() {
126 if (fState
== TargetNodeState
.CONNECTED
) {
127 return super.getImage();
129 return fDisconnectedImage
;
134 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState()
137 public TargetNodeState
getTargetNodeState() {
143 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent.TargetNodeState)
146 public void setTargetNodeState(TargetNodeState state
) {
148 fireComponentChanged(TargetNodeComponent
.this);
153 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getControlService()
156 public ILttngControlService
getControlService() {
162 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setControlService(org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService)
165 public void setControlService(ILttngControlService service
) {
166 fService
= (ILttngControlService
)service
;
171 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
173 @SuppressWarnings("rawtypes")
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 (TraceSessionComponent
[])sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
206 return new TraceSessionComponent
[0];
209 // ------------------------------------------------------------------------
211 // ------------------------------------------------------------------------
214 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
217 public void communicationsStateChange(CommunicationsEvent e
) {
218 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
219 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
220 handleDisconnected();
221 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
227 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
230 public boolean isPassiveCommunicationsListener() {
236 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceControlComponent#dispose()
239 public void dispose() {
240 fRemoteProxy
.removeCommunicationListener(this);
244 * Method to connect this node component to the remote target node.
246 public void connect() {
247 if (fState
== TargetNodeState
.DISCONNECTED
) {
249 setTargetNodeState(TargetNodeState
.CONNECTING
);
250 fRemoteProxy
.connect(new IRSECallback() {
252 public void done(IStatus status
, Object result
) {
253 // Note: result might be null!
257 handleDisconnected();
261 } catch (Exception e
) {
262 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
263 Activator
.getDefault().getLog().log(
264 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
)); //$NON-NLS-1$ //$NON-NLS-2$
270 * Method to disconnect this node component to the remote target node.
272 public void disconnect() {
273 if (fState
== TargetNodeState
.CONNECTED
) {
275 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
276 fRemoteProxy
.disconnect();
277 } catch (Exception e
) {
278 Activator
.getDefault().getLog().log(
279 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
)); //$NON-NLS-1$ //$NON-NLS-2$
281 handleDisconnected();
287 * Retrieves the trace configuration from the target node and populates the information
288 * in the tree model. The execution is done in a own job.
290 * @throws ExecutionException
292 public void getConfigurationFromNode() {
293 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
295 protected IStatus
run(IProgressMonitor monitor
) {
298 // Get provider information from node
299 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
300 addChild(providerGroup
);
301 providerGroup
.getProviderFromNode(monitor
);
303 // Get session information from node
304 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
305 addChild(sessionGroup
);
306 sessionGroup
.getSessionsFromNode(monitor
);
307 } catch (ExecutionException e
) {
309 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ListSessionFailure
, e
);
312 return Status
.OK_STATUS
;
320 * Refresh the node configuration
322 public void refresh() {
324 getConfigurationFromNode();
328 * Deregisters host from registry.
330 public void deregister() {
331 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
332 registry
.deleteHost(fHost
);
335 // ------------------------------------------------------------------------
337 // ------------------------------------------------------------------------
339 * @return returns the control service for LTTng specific commands.
340 * @throws ExecutionException
342 private ILttngControlService
createControlService() throws ExecutionException
{
343 if (fShell
== null) {
344 fShell
= fRemoteProxy
.createCommandShell();
345 fRemoteProxy
.addCommunicationListener(this);
347 fService
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
352 * Handles the connected event.
354 private void handleConnected() {
355 setTargetNodeState(TargetNodeState
.CONNECTED
);
357 createControlService();
358 getConfigurationFromNode();
359 } catch (ExecutionException e
) {
360 Activator
.getDefault().getLog().log(
361 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ListSessionFailure
+ " (" + getName() + "). \n", e
)); //$NON-NLS-1$ //$NON-NLS-2$
366 * Handles the disconnected event.
368 private void handleDisconnected() {
370 setTargetNodeState(TargetNodeState
.DISCONNECTED
);