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
.core
.tracecontrol
.utility
.LiveTraceManager
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.Messages
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.TraceControlConstants
;
32 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.subsystems
.TraceSubSystem
;
33 import org
.eclipse
.rse
.core
.events
.ISystemRemoteChangeEvents
;
34 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
35 import org
.eclipse
.rse
.core
.model
.SystemStartHere
;
36 import org
.eclipse
.rse
.services
.clientserver
.messages
.SystemMessageException
;
37 import org
.eclipse
.rse
.ui
.SystemBasePlugin
;
38 import org
.eclipse
.swt
.widgets
.Shell
;
39 import org
.eclipse
.tm
.tcf
.protocol
.IToken
;
40 import org
.eclipse
.tm
.tcf
.util
.TCFTask
;
41 import org
.eclipse
.ui
.IObjectActionDelegate
;
42 import org
.eclipse
.ui
.IViewActionDelegate
;
43 import org
.eclipse
.ui
.IViewPart
;
44 import org
.eclipse
.ui
.IWorkbenchPart
;
45 import org
.eclipse
.ui
.IWorkbenchWindow
;
46 import org
.eclipse
.ui
.IWorkbenchWindowActionDelegate
;
49 * <b><u>StopTrace</u></b>
51 * Action implementation to stop a trace which deallocates all resources on the remote system.
54 public class StopTrace
implements IObjectActionDelegate
, IWorkbenchWindowActionDelegate
, IViewActionDelegate
{
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 private List
<TraceResource
> fSelectedTraces
;
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
67 fSelectedTraces
= new ArrayList
<TraceResource
>();
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
76 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
79 public void setActivePart(IAction arg0
, IWorkbenchPart arg1
) {
84 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
87 public void run(IAction arg0
) {
88 int size
= fSelectedTraces
.size();
89 for (int i
= 0; i
< size
; i
++) {
91 final TraceResource trace
= (TraceResource
) fSelectedTraces
.get(i
);
92 TraceSubSystem subSystem
= (TraceSubSystem
)trace
.getSubSystem();
95 final ILttControllerService service
= subSystem
.getControllerService();
97 TraceConfig traceConfig
= trace
.getTraceConfig();
98 if (traceConfig
!= null && traceConfig
.getMode() == TraceConfig
.FLIGHT_RECORDER_MODE
) {
99 setupLocation(service
, trace
, traceConfig
);
102 // Create future task
103 @SuppressWarnings("unused")
104 Boolean success
= new TCFTask
<Boolean
>() {
108 // Setup trace using Lttng controller service proxy
109 service
.destroyTrace(trace
.getParent().getParent().getName(), trace
.getParent().getName(), trace
.getName(), new ILttControllerService
.DoneDestroyTrace() {
112 public void doneDestroyTrace(IToken token
, Exception error
, Object str
) {
119 // Notify about success
120 done(Boolean
.valueOf(true));
123 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
125 trace
.setTraceState(TraceState
.STOPPED
);
127 if (trace
.getTraceConfig() != null) {
128 LiveTraceManager
.setLiveTrace(trace
.getTraceConfig().getTracePath(), false);
131 ISystemRegistry registry
= SystemStartHere
.getSystemRegistry();
132 registry
.fireRemoteResourceChangeEvent(ISystemRemoteChangeEvents
.SYSTEM_REMOTE_RESOURCE_CHANGED
, trace
, trace
.getParent(), subSystem
, null);
134 } catch (Exception e
) {
135 SystemMessageException sysExp
;
136 if (e
instanceof SystemMessageException
) {
137 sysExp
= (SystemMessageException
)e
;
139 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
141 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorStop
+ " (" + //$NON-NLS-1$
142 Messages
.Lttng_Resource_Trace
+ ": " + trace
.getName() + ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
149 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
151 @SuppressWarnings("unchecked")
153 public void selectionChanged(IAction action
, ISelection selection
) {
155 if (selection
instanceof IStructuredSelection
) {
156 fSelectedTraces
.clear();
158 // store the selected targets to be used when running
159 Iterator
<IStructuredSelection
> theSet
= ((IStructuredSelection
) selection
).iterator();
160 while (theSet
.hasNext()) {
161 Object obj
= theSet
.next();
162 if (obj
instanceof TraceResource
) {
163 fSelectedTraces
.add((TraceResource
)obj
);
171 * Returns the active workbench shell of this plug-in.
173 * @return active workbench shell.
175 protected Shell
getShell() {
176 return SystemBasePlugin
.getActiveWorkbenchShell();
181 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
184 public void init(IWorkbenchWindow window
) {
189 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
192 public void dispose() {
197 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
200 public void init(IViewPart view
) {
204 * Setup the trace location. Only flight recorder channels are written when trace is stopped.
206 private void setupLocation(final ILttControllerService service
, final TraceResource trace
, final TraceConfig traceConfig
) throws Exception
{
207 boolean success
= false;
209 if (traceConfig
.isNetworkTrace()) {
211 // Create future task
212 success
= new TCFTask
<Boolean
>() {
216 // Setup trace transport using Lttng controller service proxy
217 service
.writeTraceNetwork(trace
.getParent().getParent().getName(),
218 trace
.getParent().getName(),
219 traceConfig
.getTraceName(),
220 traceConfig
.getTracePath(),
221 traceConfig
.getNumChannel(),
222 traceConfig
.getIsAppend(),
223 true, // write only flight recorder channels
225 new ILttControllerService
.DoneWriteTraceNetwork() {
228 public void doneWriteTraceNetwork(IToken token
, Exception error
, Object str
) {
235 // Notify about success
236 done(Boolean
.valueOf(true));
239 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
243 // Create future task
244 success
= new TCFTask
<Boolean
>() {
248 // Setup trace transport using Lttng controller service proxy
249 service
.writeTraceLocal(trace
.getParent().getParent().getName(),
250 trace
.getParent().getName(),
251 traceConfig
.getTraceName(),
252 traceConfig
.getTracePath(),
253 traceConfig
.getNumChannel(),
254 traceConfig
.getIsAppend(),
255 true, // write only flight recorder channels
257 new ILttControllerService
.DoneWriteTraceLocal() {
260 public void doneWriteTraceLocal(IToken token
, Exception error
, Object str
) {
267 // Notify about success
268 done(Boolean
.valueOf(true));
271 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
275 //FIXME: wait 2 seconds to allow time for channels to be written before destroying the trace
278 } catch (InterruptedException e
) {