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
.lttng
.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
.lttng
.ui
.LTTngUiPlugin
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TargetNodeState
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.property
.TargetNodePropertySource
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.remote
.IRemoteSystemProxy
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.remote
.RemoteSystemProxy
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.ICommandShell
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.ILttngControlService
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.LTTngControlService
;
31 import org
.eclipse
.rse
.core
.model
.IHost
;
32 import org
.eclipse
.rse
.core
.model
.IRSECallback
;
33 import org
.eclipse
.rse
.core
.subsystems
.CommunicationsEvent
;
34 import org
.eclipse
.rse
.core
.subsystems
.ICommunicationsListener
;
35 import org
.eclipse
.swt
.graphics
.Image
;
36 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
39 * <b><u>TargetNodeComponent</u></b>
41 * Implementation of the trace node component.
44 public class TargetNodeComponent
extends TraceControlComponent
implements ICommunicationsListener
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 * Path to icon file for this component (state connected).
52 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
54 * Path to icon file for this component (state disconnected).
56 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 * The node connection state.
64 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
66 * The image to be displayed in state disconnected.
68 private Image fDisconnectedImage
= null;
70 * The connection implementation.
72 private IHost fHost
= null;
74 * The remote proxy implementation.
76 private IRemoteSystemProxy fRemoteProxy
= null;
78 * The control service for LTTng specific commands.
80 private ILttngControlService fService
= null;
82 * The command shell for issuing commands.
84 private ICommandShell fShell
= null;
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
91 * @param name - the name of the component
92 * @param parent - the parent of the component
93 * @param host - the host connection implementation
94 * @param proxy - the remote proxy implementation
96 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
, IRemoteSystemProxy proxy
) {
98 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
99 fDisconnectedImage
= LTTngUiPlugin
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
101 fRemoteProxy
= proxy
;
102 setToolTip(fHost
.getHostName());
106 * Constructor (using default proxy)
107 * @param name - the name of the component
108 * @param parent - the parent of the component
109 * @param host - the host connection implementation
111 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
) {
112 this(name
, parent
, host
, new RemoteSystemProxy(host
));
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
120 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage()
123 public Image
getImage() {
124 if (fState
== TargetNodeState
.CONNECTED
) {
125 return super.getImage();
127 return fDisconnectedImage
;
132 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState()
135 public TargetNodeState
getTargetNodeState() {
141 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent.TargetNodeState)
144 public void setTargetNodeState(TargetNodeState state
) {
146 fireComponentChanged(TargetNodeComponent
.this);
151 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getControlService()
154 public ILttngControlService
getControlService() {
160 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#setControlService(org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService)
163 public void setControlService(ILttngControlService service
) {
164 fService
= (ILttngControlService
)service
;
169 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
171 @SuppressWarnings("rawtypes")
173 public Object
getAdapter(Class adapter
) {
174 if (adapter
== IPropertySource
.class) {
175 return new TargetNodePropertySource(this);
181 * @return remote host name
183 public String
getHostName() {
184 return fHost
.getHostName();
188 * @return remote system proxy implementation
190 public IRemoteSystemProxy
getRemoteSystemProxy() {
195 * @return all available sessions.
197 public TraceSessionComponent
[] getSessions() {
198 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
199 if (compenents
.size() > 0) {
200 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
201 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
202 return (TraceSessionComponent
[])sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
204 return new TraceSessionComponent
[0];
207 // ------------------------------------------------------------------------
209 // ------------------------------------------------------------------------
212 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
215 public void communicationsStateChange(CommunicationsEvent e
) {
216 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
217 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
218 handleDisconnected();
219 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
225 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
228 public boolean isPassiveCommunicationsListener() {
234 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.TraceControlComponent#dispose()
237 public void dispose() {
238 fRemoteProxy
.removeCommunicationListener(this);
242 * Method to connect this node component to the remote target node.
244 public void connect() {
245 if (fState
== TargetNodeState
.DISCONNECTED
) {
247 setTargetNodeState(TargetNodeState
.CONNECTING
);
248 fRemoteProxy
.connect(new IRSECallback() {
250 public void done(IStatus status
, Object result
) {
251 // Note: result might be null!
255 handleDisconnected();
259 } catch (Exception e
) {
260 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
261 LTTngUiPlugin
.logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + ").", e
); //$NON-NLS-1$ //$NON-NLS-2$
267 * Method to disconnect this node component to the remote target node.
269 public void disconnect() {
270 if (fState
== TargetNodeState
.CONNECTED
) {
272 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
273 fRemoteProxy
.disconnect();
274 } catch (Exception e
) {
275 LTTngUiPlugin
.logError(Messages
.TraceControl_DisconnectionFailure
+ getName(), e
);
277 handleDisconnected();
283 * Retrieves the trace configuration from the target node and populates the information
284 * in the tree model. The execution is done in a own job.
286 * @throws ExecutionException
288 public void getConfigurationFromNode() throws ExecutionException
{
289 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
291 protected IStatus
run(IProgressMonitor monitor
) {
294 // Get provider information from node
295 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
296 addChild(providerGroup
);
297 providerGroup
.getProviderFromNode(monitor
);
299 // Get session information from node
300 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
301 addChild(sessionGroup
);
302 sessionGroup
.getSessionsFromNode(monitor
);
303 } catch (ExecutionException e
) {
305 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, e
.toString());
308 return Status
.OK_STATUS
;
316 // ------------------------------------------------------------------------
318 // ------------------------------------------------------------------------
320 * @return returns the control service for LTTng specific commands.
321 * @throws ExecutionException
323 private ILttngControlService
createControlService() throws ExecutionException
{
324 if (fShell
== null) {
325 fShell
= fRemoteProxy
.createCommandShell();
326 fRemoteProxy
.addCommunicationListener(this);
328 fService
= new LTTngControlService(fShell
);
333 * Handles the connected event.
335 private void handleConnected() {
336 setTargetNodeState(TargetNodeState
.CONNECTED
);
338 createControlService();
339 getConfigurationFromNode();
340 } catch (ExecutionException e
) {
341 LTTngUiPlugin
.logError(Messages
.TraceControl_ListSessionFailure
, e
);
346 * Handles the disconnected event.
348 private void handleDisconnected() {
350 setTargetNodeState(TargetNodeState
.DISCONNECTED
);