Fix for streaming and reconnection. Added standalone releng for lttng.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / tracecontrol / subsystems / TraceSubSystem.java
1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Polytechnique Montréal - Initial API and implementation
11 * Bernd Hufmann - Productification, enhancements and fixes
12 *
13 *******************************************************************************/
14 package org.eclipse.linuxtools.lttng.ui.tracecontrol.subsystems;
15
16 import java.io.File;
17 import java.util.ArrayList;
18 import java.util.Arrays;
19 import java.util.Vector;
20 import java.util.concurrent.TimeUnit;
21
22 import org.eclipse.core.runtime.IProgressMonitor;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.linuxtools.lttng.core.LttngConstants;
25 import org.eclipse.linuxtools.lttng.core.tracecontrol.model.ProviderResource;
26 import org.eclipse.linuxtools.lttng.core.tracecontrol.model.TargetResource;
27 import org.eclipse.linuxtools.lttng.core.tracecontrol.model.TraceResource;
28 import org.eclipse.linuxtools.lttng.core.tracecontrol.model.TraceResource.TraceState;
29 import org.eclipse.linuxtools.lttng.core.tracecontrol.model.config.TraceConfig;
30 import org.eclipse.linuxtools.lttng.core.tracecontrol.service.ILttControllerService;
31 import org.eclipse.linuxtools.lttng.core.tracecontrol.service.LttControllerServiceProxy;
32 import org.eclipse.linuxtools.lttng.core.tracecontrol.utility.LiveTraceManager;
33 import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
34 import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages;
35 import org.eclipse.linuxtools.lttng.ui.tracecontrol.TraceControlConstants;
36 import org.eclipse.linuxtools.lttng.ui.tracecontrol.actions.ImportToProject;
37 import org.eclipse.linuxtools.lttng.ui.tracecontrol.actions.PauseTrace;
38 import org.eclipse.linuxtools.lttng.ui.tracecontrol.connectorservice.TraceConnectorService;
39 import org.eclipse.rse.core.events.ISystemResourceChangeEvents;
40 import org.eclipse.rse.core.events.SystemResourceChangeEvent;
41 import org.eclipse.rse.core.filters.ISystemFilter;
42 import org.eclipse.rse.core.filters.ISystemFilterPoolReference;
43 import org.eclipse.rse.core.model.IHost;
44 import org.eclipse.rse.core.model.ISystemMessageObject;
45 import org.eclipse.rse.core.model.ISystemRegistry;
46 import org.eclipse.rse.core.model.SystemMessageObject;
47 import org.eclipse.rse.core.model.SystemStartHere;
48 import org.eclipse.rse.core.subsystems.CommunicationsEvent;
49 import org.eclipse.rse.core.subsystems.ICommunicationsListener;
50 import org.eclipse.rse.core.subsystems.IConnectorService;
51 import org.eclipse.rse.core.subsystems.SubSystem;
52 import org.eclipse.rse.services.clientserver.NamePatternMatcher;
53 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
54 import org.eclipse.rse.ui.SystemBasePlugin;
55 import org.eclipse.swt.widgets.Display;
56 import org.eclipse.tm.tcf.protocol.IToken;
57 import org.eclipse.tm.tcf.util.TCFTask;
58
59 /**
60 * <b><u>TraceSubSystem</u></b>
61 * <p>
62 * Implementation of the trace subsystem. Provides methods to initialize connections
63 * to the remote system, connection handling, filtering and retrival of remote
64 * system configuration.
65 * </p>
66 */
67 public class TraceSubSystem extends SubSystem implements ICommunicationsListener {
68
69 // ------------------------------------------------------------------------
70 // Attributes
71 // ------------------------------------------------------------------------
72 private ProviderResource[] fProviders; // master list of Providers
73
74 // ------------------------------------------------------------------------
75 // Constructors
76 // ------------------------------------------------------------------------
77 /**
78 * @param host
79 * @param connectorService
80 */
81 public TraceSubSystem(IHost host, IConnectorService connectorService) {
82 super(host, connectorService);
83 }
84
85 // ------------------------------------------------------------------------
86 // Operations
87 // ------------------------------------------------------------------------
88
89 /*
90 * (non-Javadoc)
91 * @see org.eclipse.rse.core.subsystems.SubSystem#initializeSubSystem(org.eclipse.core.runtime.IProgressMonitor)
92 */
93 @Override
94 public void initializeSubSystem(IProgressMonitor monitor) {
95 getConnectorService().addCommunicationsListener(this);
96 }
97
98 /*
99 * (non-Javadoc)
100 * @see org.eclipse.rse.core.subsystems.SubSystem#uninitializeSubSystem(org.eclipse.core.runtime.IProgressMonitor)
101 */
102 @Override
103 public void uninitializeSubSystem(IProgressMonitor monitor) {
104 }
105
106 /*
107 * (non-Javadoc)
108 * @see org.eclipse.rse.core.subsystems.SubSystem#getObjectWithAbsoluteName(java.lang.String)
109 *
110 * For drag and drop, and clipboard support of remote objects.
111 *
112 * Return the remote object within the subsystem that corresponds to the specified unique ID. Because each subsystem maintains it's own objects, it's the responsability of the subsystem to determine how an ID (or key) for a given object maps to
113 * the real object. By default this returns null.
114 */
115 @Override
116 public Object getObjectWithAbsoluteName(String key) {
117 return null;
118 }
119
120 /*
121 * (non-Javadoc)
122 * @see org.eclipse.rse.core.subsystems.SubSystem#internalResolveFilterString(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
123 */
124 @Override
125 protected Object[] internalResolveFilterString(String filterString, IProgressMonitor monitor) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException {
126
127 ProviderResource[] allProviders;
128
129 try {
130 allProviders = getAllProviders();
131 } catch (SystemMessageException e) {
132 SystemBasePlugin.logError("TraceSubSystem", e); //$NON-NLS-1$
133 Object[] children = new SystemMessageObject[1];
134 children[0] = new SystemMessageObject(e.getSystemMessage(), ISystemMessageObject.MSGTYPE_ERROR, null);
135 return children;
136 }
137
138 // Now, subset master list, based on filter string...
139 NamePatternMatcher subsetter = new NamePatternMatcher(filterString);
140 Vector<ProviderResource> v = new Vector<ProviderResource>();
141 for (int idx = 0; idx < allProviders.length; idx++) {
142 if (subsetter.matches(allProviders[idx].getName())) {
143 v.addElement(allProviders[idx]);
144 }
145 }
146 return allProviders;
147 }
148 /*
149 * (non-Javadoc)
150 * @see org.eclipse.rse.core.subsystems.SubSystem#internalResolveFilterString(java.lang.Object, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
151 */
152 @Override
153 protected Object[] internalResolveFilterString(Object parent, String filterString, IProgressMonitor monitor) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException {
154 return null;
155 }
156
157 /* (non-Javadoc)
158 * @see org.eclipse.rse.core.subsystems.SubSystem#filterEventFilterCreated(java.lang.Object, org.eclipse.rse.core.filters.ISystemFilter)
159 */
160 @Override
161 public void filterEventFilterCreated(Object selectedObject, ISystemFilter newFilter) {
162 super.filterEventFilterCreated(selectedObject, newFilter);
163 ISystemRegistry registry = SystemStartHere.getSystemRegistry();
164 registry.fireEvent(new SystemResourceChangeEvent(this, ISystemResourceChangeEvents.EVENT_REFRESH, null));
165 }
166
167 /* (non-Javadoc)
168 * @see org.eclipse.rse.core.subsystems.SubSystem#filterEventFilterPoolReferenceCreated(org.eclipse.rse.core.filters.ISystemFilterPoolReference)
169 */
170 @Override
171 public void filterEventFilterPoolReferenceCreated(ISystemFilterPoolReference newPoolRef) {
172 super.filterEventFilterPoolReferenceCreated(newPoolRef);
173 if (getSystemFilterPoolReferenceManager().getSystemFilterPoolReferenceCount() == 1) {
174 ISystemRegistry registry = SystemStartHere.getSystemRegistry();
175 registry.fireEvent(new SystemResourceChangeEvent(this, ISystemResourceChangeEvents.EVENT_REFRESH, null));
176 }
177 }
178
179 /**
180 * Retrieves all provider resources from the remote system and updates local references.
181 *
182 * @return provider resources
183 * @throws SystemMessageException
184 * @throws InterruptedException
185 */
186 public ProviderResource[] getAllProviders() throws SystemMessageException, InterruptedException {
187 ProviderResource[] providers = createProviders();
188 if (fProviders == null) {
189 fProviders = providers;
190 }
191 else {
192 for (int i = 0; i < fProviders.length; i++) {
193 for (int j = 0; j < providers.length; j++) {
194 if(fProviders[i].getName().equals(providers[j].getName())) {
195 // Check if all targets already exist
196 fProviders[i].refreshTargets(providers[j].getTargets());
197 }
198 }
199 }
200 }
201 return fProviders;
202 }
203
204 /**
205 * Get the list of all targets.
206 *
207 * @return targets The list of targets.
208 * @throws SystemMessageException
209 */
210 public TargetResource[] getAllTargets() throws SystemMessageException {
211 ArrayList<TargetResource> targets = new ArrayList<TargetResource>();
212 if (fProviders != null) {
213 for (int i = 0; i < fProviders.length; i++) {
214 targets.addAll(Arrays.asList(fProviders[i].getTargets()));
215 }
216 }
217 return targets.toArray(new TargetResource[0]);
218 }
219
220 /**
221 * Get the list of all traces.
222 *
223 * @return traces The list of traces.
224 * @throws SystemMessageException
225 */
226 public TraceResource[] getAllTraces() throws SystemMessageException {
227 ArrayList<TraceResource> traces = new ArrayList<TraceResource>();
228 if (fProviders != null) {
229 for (int i = 0; i < fProviders.length; i++) {
230 ProviderResource provider = fProviders[i];
231 int numTargets = provider.getTargets().length;
232 for (int j = 0; j < numTargets; j++) {
233 TargetResource target = provider.getTargets()[j];
234 if (provider.getName().equals(LttngConstants.Lttng_Provider_Kernel)) {
235 traces.addAll(Arrays.asList(target.getTraces()));
236 }
237 }
238 }
239 }
240 return traces.toArray(new TraceResource[0]);
241 }
242
243 /**
244 * Get the list of all traces for given provider and target.
245 *
246 * @param provider
247 * @param target
248 * @returns trace resources
249 */
250 public TraceResource[] getAllTraces(String providerName, String targetName) throws SystemMessageException {
251 ArrayList<TraceResource> traces = new ArrayList<TraceResource>();
252 ProviderResource selectedProvider = null;
253 if (fProviders != null) {
254 for (int i = 0; i < fProviders.length; i++) {
255 ProviderResource provider = fProviders[i];
256 if (provider.getName().equals(providerName)) {
257 selectedProvider = fProviders[i];
258 break;
259 }
260 }
261
262 if (selectedProvider != null) {
263 int numTargets = selectedProvider.getTargets().length;
264 for (int j = 0; j < numTargets; j++) {
265 TargetResource target = selectedProvider.getTargets()[j];
266 if (target.getName().equals(targetName)) {
267 traces.addAll(Arrays.asList(target.getTraces()));
268 break;
269 }
270 }
271 }
272 }
273 return traces.toArray(new TraceResource[0]);
274 }
275
276 /**
277 * Finds a trace resource within a given provider and target for a given trace name
278 *
279 * @param targetName - target name to be searched
280 * @param traceName - trace name to be searched
281 * @return trace resource or null (if not found)
282 */
283 public TraceResource findTrace(String providerName, String targetName, String traceName) {
284 TraceResource trace = null;
285 TraceResource[] traces;
286 try {
287 traces = getAllTraces(providerName, targetName);
288 for (int i = 0; i < traces.length; i++) {
289 if (traces[i].getName().equals(traceName)) {
290 trace = traces[i];
291 break;
292 }
293 }
294 } catch (SystemMessageException e) {
295 SystemBasePlugin.logError("TraceSubSystem", e); //$NON-NLS-1$
296 }
297
298 return trace;
299 }
300
301 /*
302 * Retrieves the providers from the remote system.
303 */
304 private ProviderResource[] createProviders() throws SystemMessageException {
305 ProviderResource[] providers = null;
306 try {
307
308 final ILttControllerService service = getControllerService();
309
310 // Create future task
311 providers = new TCFTask<ProviderResource[]>() {
312 @Override
313 public void run() {
314
315 // Get provider using Lttng controller service proxy
316 service.getProviders(new ILttControllerService.DoneGetProviders() {
317
318 @Override
319 public void doneGetProviders(IToken token, Exception error, String[] str) {
320 if (error != null) {
321 // Notify with error
322 error(error);
323 return;
324 }
325
326 // Create provider list
327 ProviderResource[] providers = new ProviderResource[str.length];
328
329 for (int i = 0; i < str.length; i++) {
330 ProviderResource tempProvider = new ProviderResource(TraceSubSystem.this);
331 tempProvider.setName(str[i]);
332 providers[i] = tempProvider;
333 }
334
335 // Notify with provider list
336 done(providers);
337 }
338 });
339 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
340 } catch (Exception e) {
341 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
342 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
343 }
344
345 for (int i = 0; i < providers.length; i++) {
346 createTargets(providers[i]);
347 }
348
349 return providers;
350 }
351
352 /*
353 * Retrieves the targets for given provider from the remote system.
354 */
355 private TargetResource[] createTargets(final ProviderResource provider) throws SystemMessageException {
356 TargetResource[] targets;
357 try {
358 final ILttControllerService service = getControllerService();
359
360 // Create future task
361 targets = new TCFTask<TargetResource[]>() {
362 @Override
363 public void run() {
364
365 // Get targets using Lttng controller service proxy
366 service.getTargets(provider.getName(), new ILttControllerService.DoneGetTargets() {
367
368 @Override
369 public void doneGetTargets(IToken token, Exception error, String[] str) {
370 if (error != null) {
371 // Notify with error
372 error(error);
373 return;
374 }
375
376 // Create targets
377 TargetResource[] targets = new TargetResource[str.length];
378 for (int i = 0; i < str.length; i++) {
379 TargetResource tempTarget = new TargetResource(TraceSubSystem.this);
380 tempTarget.setName(str[i]);
381 tempTarget.setParent(provider);
382 targets[i] = tempTarget;
383 }
384 // Notify with target list
385 done(targets);
386 }
387 });
388 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
389 } catch (Exception e) {
390 provider.setTargets(new TargetResource[0]);
391 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
392 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
393 }
394
395 provider.setTargets(targets);
396 for (int i = 0; i < targets.length; i++) {
397 if (targets[i].getParent().getName().equals(LttngConstants.Lttng_Provider_Kernel)) {
398 createTraces(targets[i]);
399 }
400 }
401
402 return targets;
403 }
404
405 /*
406 * Retrieves the trace instances for a given target from the remote system.
407 */
408 private TraceResource[] createTraces(final TargetResource target) throws SystemMessageException {
409 TraceResource[] traces;
410 try {
411 final ILttControllerService service = getControllerService();
412
413 // Create future task
414 traces = new TCFTask<TraceResource[]>() {
415 @Override
416 public void run() {
417 // Get targets using Lttng controller service proxy
418 service.getTraces(target.getParent().getName(), target.getName(), new ILttControllerService.DoneGetTraces() {
419
420 @Override
421 public void doneGetTraces(IToken token, Exception error, String[] str) {
422 if (error != null) {
423 // Notify with error
424 error(error);
425 return;
426 }
427
428 // Create trace list
429 TraceResource[] traces = new TraceResource[str.length];
430 for (int i = 0; i < str.length; i++) {
431 TraceResource trace = new TraceResource(TraceSubSystem.this, service);
432 trace.setName(str[i]);
433 trace.setParent(target);
434 trace.setTraceState(TraceState.CREATED);
435 traces[i] = trace;
436 }
437
438 // Notify with trace list
439 done(traces);
440 }
441 });
442 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
443 } catch (Exception e) {
444 target.setTraces(new TraceResource[0]);
445 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
446 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
447 }
448
449 target.setTraces(traces);
450
451 // get active trace information (is only supported for kernel traces)
452 createTraceConfigurations(target, traces);
453 return traces;
454 }
455
456 /*
457 * Retrieves the trace configurations for the given trace from the remote system.
458 */
459 private void createTraceConfigurations(final TargetResource target, TraceResource[] traces) throws SystemMessageException {
460 if (!target.isUst() && (traces.length > 0)) {
461 // get active traces
462 String[] activeTraceNames;
463 try {
464 final ILttControllerService service = getControllerService();
465 activeTraceNames = new TCFTask<String[]>() {
466 @Override
467 public void run() {
468 // Get targets using Lttng controller service proxy
469 service.getActiveTraces(target.getParent().getName(), target.getName(), new ILttControllerService.DoneGetActiveTraces() {
470
471 @Override
472 public void doneGetActiveTraces(IToken token, Exception error, String[] str) {
473 if (error != null) {
474 // Notify with error
475 error(error);
476 return;
477 }
478
479 // Notify with active trace list
480 done(str);
481 }
482 });
483 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
484 } catch (Exception e) {
485 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
486 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
487 }
488
489 // get active trace information
490 for (int j = 0; j < activeTraceNames.length; j++) {
491 final TraceResource trace = target.getTrace(activeTraceNames[j]);
492 if (trace != null) {
493 // get trace info
494 TraceConfig traceConfig;
495
496 try {
497 final ILttControllerService service = getControllerService();
498 traceConfig = new TCFTask<TraceConfig>() {
499 @Override
500 public void run() {
501 // Get targets using Lttng controller service proxy
502 service.getActiveTraceInfo(target.getParent().getName(), target.getName(), trace.getName(), new ILttControllerService.DoneGetActiveTraceInfo() {
503
504 @Override
505 public void doneGetActiveTraceInfo(IToken token, Exception error, String[] strArray) {
506 if (error != null) {
507 // Notify with error
508 error(error);
509 return;
510 }
511
512 TraceConfig config = new TraceConfig();
513 config.setTraceName(trace.getName());
514 config.setTraceTransport(TraceControlConstants.Lttng_Trace_Transport_Relay);
515 config.setIsAppend(false);
516 for (String pair : strArray) {
517 String[] pairArray = pair.split(LttngConstants.Lttng_Control_GetActiveTraceInfoSeparator);
518 if (pairArray.length != 2) {
519 continue;
520 }
521 String param = pairArray[0];
522 String value = pairArray[1];
523 if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_DESTINATION)) {
524 if (value.startsWith(TraceControlConstants.ACTIVE_TRACE_INFO_DESTINATION_PREFIX_LOCAL)) {
525 config.setNetworkTrace(false);
526 config.setTracePath(value.substring(TraceControlConstants.ACTIVE_TRACE_INFO_DESTINATION_PREFIX_LOCAL.length()));
527 } else if (value.startsWith(TraceControlConstants.ACTIVE_TRACE_INFO_DESTINATION_PREFIX_NETWORK)) {
528 config.setNetworkTrace(true);
529 config.setTracePath(value.substring(TraceControlConstants.ACTIVE_TRACE_INFO_DESTINATION_PREFIX_NETWORK.length()));
530 }
531 } else if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_NUM_THREAD)) {
532 config.setNumChannel(Integer.valueOf(value));
533 } else if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_NORMAL_ONLY)) {
534 if (value.equals(Boolean.toString(true))) {
535 config.setMode(TraceConfig.NORMAL_MODE);
536 }
537 } else if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_FLIGHT_ONLY)) {
538 if (value.equals(Boolean.toString(true))) {
539 config.setMode(TraceConfig.FLIGHT_RECORDER_MODE);
540 }
541 } else if (param.equals(TraceControlConstants.ACTIVE_TRACE_INFO_PARAM_ENABLED)) {
542 if (value.equals(Boolean.toString(true))) {
543 trace.setTraceState(TraceState.STARTED);
544 } else {
545 trace.setTraceState(TraceState.PAUSED);
546 }
547 }
548 }
549
550 // Notify with active trace list
551 done(config);
552 }
553 });
554 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
555 trace.setTraceConfig(traceConfig);
556 if (traceConfig != null) {
557 if (traceConfig.isNetworkTrace()) {
558 // stop and restart the network transfer since TCF channel may be different
559 if (fProviders == null) { // do this only on startup, not on refresh
560 restartTraceNetwork(service, trace, traceConfig);
561 }
562 LiveTraceManager.setLiveTrace(traceConfig.getTracePath(), true);
563 }
564 }
565 } catch (Exception e) {
566 if (e instanceof SystemMessageException) throw (SystemMessageException)e;
567 throw new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
568 }
569 }
570 }
571 }
572 }
573
574 /*
575 * (non-Javadoc)
576 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
577 */
578 @Override
579 public void communicationsStateChange(CommunicationsEvent e) {
580 switch (e.getState())
581 {
582 case CommunicationsEvent.BEFORE_CONNECT :
583 break;
584 case CommunicationsEvent.AFTER_CONNECT :
585 break;
586 case CommunicationsEvent.BEFORE_DISCONNECT :
587
588 try {
589 final TraceResource[] traces = getAllTraces();
590
591 StringBuffer traceNames = new StringBuffer(""); //$NON-NLS-1$
592 String filler = ""; //$NON-NLS-1$
593 for (int j = 0; j < traces.length; j++) {
594 // For network traces, ask user to pause tracing
595 if (traces[j].isNetworkTraceAndStarted()) {
596 traceNames.append(filler);
597 traceNames.append(traces[j].getName());
598 }
599 filler = ", "; //$NON-NLS-1$
600 }
601 if (!"".equals(traceNames.toString())) { //$NON-NLS-1$
602 final String finalTraceNames = traceNames.toString();
603 Display.getDefault().syncExec(new Runnable() {
604
605 @Override
606 public void run() {
607 MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.Ltt_ShutdownWarning, Messages.Ltt_NetworkTraceRunningWarning + ":\n" + finalTraceNames); //$NON-NLS-1$
608
609 // Pause tracing
610 PauseTrace pauseAction = new PauseTrace();
611 pauseAction.setSelectedTraces(new ArrayList<TraceResource>(Arrays.asList(traces)));
612 pauseAction.run(null);
613 try {
614 Thread.sleep(2000); // allow time for target to pause traces before disconnecting the channel
615 } catch (InterruptedException e) {
616 e.printStackTrace();
617 }
618 }
619 });
620 }
621
622 if (fProviders != null) {
623 // reset all providers and it's children
624 for (int i = 0; i < fProviders.length; i++) {
625 fProviders[i].removeAllTargets();
626 }
627 fProviders = null;
628 }
629
630 } catch (SystemMessageException ex) {
631 SystemBasePlugin.logError("TraceSubSystem", ex); //$NON-NLS-1$
632 }
633 break;
634 case CommunicationsEvent.AFTER_DISCONNECT :
635 getConnectorService().removeCommunicationsListener(this);
636 break;
637 case CommunicationsEvent.CONNECTION_ERROR :
638 // TODO notify user about the lost connection ?!
639 getConnectorService().removeCommunicationsListener(this);
640 try {
641 this.disconnect();
642 } catch (Exception e1) {
643 // Nothing to do
644 }
645 break;
646 default :
647 break;
648 }
649 }
650
651 /*
652 * (non-Javadoc)
653 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
654 */
655 @Override
656 public boolean isPassiveCommunicationsListener() {
657 return true;
658 }
659
660 /**
661 * Returns the trace controller service.
662 *
663 * @return trace controller service
664 * @throws Exception
665 */
666 public LttControllerServiceProxy getControllerService() throws Exception {
667 return ((TraceConnectorService)getConnectorService()).getControllerService();
668 }
669
670 /*
671 * Stop and restart the network transfer. Only normal channels are written while trace is started.
672 */
673 private void restartTraceNetwork(final ILttControllerService service, final TraceResource trace, final TraceConfig traceConfig) throws Exception {
674 File newDir = new File(traceConfig.getTracePath());
675 if (!newDir.exists()) {
676 boolean created = newDir.mkdirs();
677 if (!created) {
678 throw new Exception(Messages.Lttng_Control_ErrorCreateTracePath + ": " + traceConfig.getTracePath()); //$NON-NLS-1$
679 }
680 if (traceConfig.getProject() != null) {
681 ImportToProject.linkTrace(getShell(), trace, traceConfig.getProject(), traceConfig.getTraceName());
682 }
683 }
684
685 // stop the previous lttd
686 boolean ok = new TCFTask<Boolean>() {
687 @Override
688 public void run() {
689
690 // Setup trace transport using Lttng controller service proxy
691 service.stopWriteTraceNetwork(trace.getParent().getParent().getName(),
692 trace.getParent().getName(),
693 traceConfig.getTraceName(),
694 new ILttControllerService.DoneStopWriteTraceNetwork() {
695
696 @Override
697 public void doneStopWriteTraceNetwork(IToken token, Exception error, Object str) {
698 if (error != null) {
699 // Notify with error
700 error(error);
701 return;
702 }
703
704 // Notify about success
705 done(true);
706 }
707 });
708 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
709
710 if (!ok) {
711 return;
712 }
713
714 // lttd will only perform the shutdown after stopWriteTraceNetwork
715 // when it receives the next on_read_subbuffer callback
716
717 if (trace.getTraceState() == TraceState.PAUSED) {
718 // we need to start the trace to make sure that the network transfer is stopped
719 ok = new TCFTask<Boolean>() {
720 @Override
721 public void run() {
722
723 // Start the trace
724 service.startTrace(trace.getParent().getParent().getName(),
725 trace.getParent().getName(),
726 traceConfig.getTraceName(),
727 new ILttControllerService.DoneStartTrace() {
728
729 @Override
730 public void doneStartTrace(IToken token, Exception error, Object str) {
731 if (error != null) {
732 // Notify with error
733 error(error);
734 return;
735 }
736
737 // Notify about success
738 done(true);
739 }
740 });
741 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
742
743 if (!ok) {
744 return;
745 }
746
747 trace.setTraceState(TraceState.STARTED);
748
749 // wait for the lttd shutdown
750 Thread.sleep(1000);
751
752 // return to paused state
753 ok = new TCFTask<Boolean>() {
754 @Override
755 public void run() {
756
757 // Pause the trace
758 service.pauseTrace(trace.getParent().getParent().getName(),
759 trace.getParent().getName(),
760 traceConfig.getTraceName(),
761 new ILttControllerService.DonePauseTrace() {
762
763 @Override
764 public void donePauseTrace(IToken token, Exception error, Object str) {
765 if (error != null) {
766 // Notify with error
767 error(error);
768 return;
769 }
770
771 // Notify about success
772 done(true);
773 }
774 });
775 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
776
777 if (!ok) {
778 return;
779 }
780
781 trace.setTraceState(TraceState.PAUSED);
782
783 } else {
784 // wait for the lttd shutdown
785 Thread.sleep(1000);
786 }
787
788 // start a new lttd
789 new TCFTask<Boolean>() {
790 @Override
791 public void run() {
792
793 // Setup trace transport using Lttng controller service proxy
794 service.writeTraceNetwork(trace.getParent().getParent().getName(),
795 trace.getParent().getName(),
796 traceConfig.getTraceName(),
797 traceConfig.getTracePath(),
798 traceConfig.getNumChannel(),
799 traceConfig.getIsAppend(),
800 false,
801 true, // write only normal channels
802 new ILttControllerService.DoneWriteTraceNetwork() {
803
804 @Override
805 public void doneWriteTraceNetwork(IToken token, Exception error, Object str) {
806 if (error != null) {
807 // Notify with error
808 error(error);
809 return;
810 }
811
812 // Notify about success
813 done(true);
814 }
815 });
816 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
817 }
818 }
This page took 0.048994 seconds and 5 git commands to generate.