1 /*******************************************************************************
2 * Copyright (c) 2011 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 * Polytechnique Montréal - Initial API and implementation
11 * Bernd Hufmann - Productification, enhancements and fixes
13 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.actions
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
19 import java
.util
.concurrent
.TimeUnit
;
21 import org
.eclipse
.jface
.action
.IAction
;
22 import org
.eclipse
.jface
.viewers
.ISelection
;
23 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
24 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.TraceResource
;
25 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.TraceResource
.TraceState
;
26 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.config
.TraceConfig
;
27 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.service
.ILttControllerService
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.Messages
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.TraceControlConstants
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.subsystems
.TraceSubSystem
;
32 import org
.eclipse
.rse
.core
.events
.ISystemRemoteChangeEvents
;
33 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
34 import org
.eclipse
.rse
.core
.model
.SystemStartHere
;
35 import org
.eclipse
.rse
.services
.clientserver
.messages
.SystemMessageException
;
36 import org
.eclipse
.rse
.ui
.SystemBasePlugin
;
37 import org
.eclipse
.swt
.widgets
.Shell
;
38 import org
.eclipse
.tm
.tcf
.protocol
.IToken
;
39 import org
.eclipse
.tm
.tcf
.util
.TCFTask
;
40 import org
.eclipse
.ui
.IObjectActionDelegate
;
41 import org
.eclipse
.ui
.IViewActionDelegate
;
42 import org
.eclipse
.ui
.IViewPart
;
43 import org
.eclipse
.ui
.IWorkbenchPart
;
44 import org
.eclipse
.ui
.IWorkbenchWindow
;
45 import org
.eclipse
.ui
.IWorkbenchWindowActionDelegate
;
48 * <b><u>StopTrace</u></b>
50 * Action implementation to stop a trace which deallocates all resources on the remote system.
53 public class StopTrace
implements IObjectActionDelegate
, IWorkbenchWindowActionDelegate
, IViewActionDelegate
{
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 private List
<TraceResource
> fSelectedTraces
;
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
66 fSelectedTraces
= new ArrayList
<TraceResource
>();
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
75 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
78 public void setActivePart(IAction arg0
, IWorkbenchPart arg1
) {
83 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
86 public void run(IAction arg0
) {
87 int size
= fSelectedTraces
.size();
88 for (int i
= 0; i
< size
; i
++) {
90 final TraceResource trace
= (TraceResource
) fSelectedTraces
.get(i
);
91 TraceSubSystem subSystem
= (TraceSubSystem
)trace
.getSubSystem();
94 final ILttControllerService service
= subSystem
.getControllerService();
96 TraceConfig traceConfig
= trace
.getTraceConfig();
97 if (traceConfig
!= null && traceConfig
.getMode() == TraceConfig
.FLIGHT_RECORDER_MODE
) {
98 setupLocation(service
, trace
, traceConfig
);
101 // Create future task
102 @SuppressWarnings("unused")
103 Boolean success
= new TCFTask
<Boolean
>() {
107 // Setup trace using Lttng controller service proxy
108 service
.destroyTrace(trace
.getParent().getParent().getName(), trace
.getParent().getName(), trace
.getName(), new ILttControllerService
.DoneDestroyTrace() {
111 public void doneDestroyTrace(IToken token
, Exception error
, Object str
) {
118 // Notify about success
119 done(Boolean
.valueOf(true));
122 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
124 trace
.setTraceState(TraceState
.STOPPED
);
126 ISystemRegistry registry
= SystemStartHere
.getSystemRegistry();
127 registry
.fireRemoteResourceChangeEvent(ISystemRemoteChangeEvents
.SYSTEM_REMOTE_RESOURCE_CHANGED
, trace
, trace
.getParent(), subSystem
, null);
129 } catch (Exception e
) {
130 SystemMessageException sysExp
;
131 if (e
instanceof SystemMessageException
) {
132 sysExp
= (SystemMessageException
)e
;
134 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
136 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorStop
+ " (" + //$NON-NLS-1$
137 Messages
.Lttng_Resource_Trace
+ ": " + trace
.getName() + ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
144 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
146 @SuppressWarnings("unchecked")
148 public void selectionChanged(IAction action
, ISelection selection
) {
150 if (selection
instanceof IStructuredSelection
) {
151 fSelectedTraces
.clear();
153 // store the selected targets to be used when running
154 Iterator
<IStructuredSelection
> theSet
= ((IStructuredSelection
) selection
).iterator();
155 while (theSet
.hasNext()) {
156 Object obj
= theSet
.next();
157 if (obj
instanceof TraceResource
) {
158 fSelectedTraces
.add((TraceResource
)obj
);
166 * Returns the active workbench shell of this plug-in.
168 * @return active workbench shell.
170 protected Shell
getShell() {
171 return SystemBasePlugin
.getActiveWorkbenchShell();
176 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
179 public void init(IWorkbenchWindow window
) {
184 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
187 public void dispose() {
192 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
195 public void init(IViewPart view
) {
199 * Setup the trace location. Only flight recorder channels are written when trace is stopped.
201 private void setupLocation(final ILttControllerService service
, final TraceResource trace
, final TraceConfig traceConfig
) throws Exception
{
202 boolean success
= false;
204 if (traceConfig
.isNetworkTrace()) {
206 // Create future task
207 success
= new TCFTask
<Boolean
>() {
211 // Setup trace transport using Lttng controller service proxy
212 service
.writeTraceNetwork(trace
.getParent().getParent().getName(),
213 trace
.getParent().getName(),
214 traceConfig
.getTraceName(),
215 traceConfig
.getNumChannel(),
216 traceConfig
.getIsAppend(),
217 true, // write only flight recorder channels
219 new ILttControllerService
.DoneWriteTraceNetwork() {
222 public void doneWriteTraceNetwork(IToken token
, Exception error
, Object str
) {
229 // Notify about success
230 done(Boolean
.valueOf(true));
233 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
237 // Create future task
238 success
= new TCFTask
<Boolean
>() {
242 // Setup trace transport using Lttng controller service proxy
243 service
.writeTraceLocal(trace
.getParent().getParent().getName(),
244 trace
.getParent().getName(),
245 traceConfig
.getTraceName(),
246 traceConfig
.getTracePath(),
247 traceConfig
.getNumChannel(),
248 traceConfig
.getIsAppend(),
249 true, // write only flight recorder channels
251 new ILttControllerService
.DoneWriteTraceLocal() {
254 public void doneWriteTraceLocal(IToken token
, Exception error
, Object str
) {
261 // Notify about success
262 done(Boolean
.valueOf(true));
265 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
269 //FIXME: wait 2 seconds to allow time for channels to be written before destroying the trace
272 } catch (InterruptedException e
) {