1 /**********************************************************************
2 * Copyright (c) 2012, 2013. 2013 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
.control
.ui
.views
.service
;
14 import java
.util
.regex
.Matcher
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.preferences
.ControlPreferences
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandResult
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.remote
.ICommandShell
;
26 * Factory to create LTTngControlService instances depending on the version of the LTTng Trace Control
27 * installed on the remote host.
30 * @author Bernd Hufmann
32 public class LTTngControlServiceFactory
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 * The singleton instance.
40 private static LTTngControlServiceFactory fInstance
= null;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
48 private LTTngControlServiceFactory() {
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 * @return the LTTngControlServiceFactory singleton instance.
57 public static synchronized LTTngControlServiceFactory
getInstance() {
58 if (fInstance
== null) {
59 fInstance
= new LTTngControlServiceFactory();
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 * Gets the LTTng Control Service implementation based on the version of the
71 * @param shell - the shell implementation to pass to the service
72 * @return - LTTng Control Service implementation
73 * @throws ExecutionException If the command fails
75 public ILttngControlService
getLttngControlService(ICommandShell shell
) throws ExecutionException
{
77 String command
= LTTngControlServiceConstants
.CONTROL_COMMAND
+ LTTngControlServiceConstants
.COMMAND_VERSION
;
79 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
80 ControlCommandLogger
.log(command
);
82 ICommandResult result
= null;
85 result
= shell
.executeCommand(command
, new NullProgressMonitor());
86 } catch (ExecutionException e
) {
87 throw new ExecutionException(Messages
.TraceControl_GettingVersionError
+ ": " + e
); //$NON-NLS-1$
90 if (ControlPreferences
.getInstance().isLoggingEnabled()) {
91 ControlCommandLogger
.log(LTTngControlService
.formatOutput(result
));
94 if ((result
!= null) && (result
.getResult() == 0) && (result
.getOutput().length
>= 1)) {
96 while (index
< result
.getOutput().length
) {
97 String line
= result
.getOutput()[index
];
98 Matcher versionMatcher
= LTTngControlServiceConstants
.VERSION_PATTERN
.matcher(line
);
99 if (versionMatcher
.matches()) {
100 String version
= versionMatcher
.group(1).trim();
101 Matcher matcher
= LTTngControlServiceConstants
.VERSION_2_PATTERN
.matcher(version
);
102 if (matcher
.matches()) {
103 LTTngControlService service
= new LTTngControlService(shell
);
104 service
.setVersion(version
);
107 throw new ExecutionException(Messages
.TraceControl_UnsupportedVersionError
+ ": " + version
); //$NON-NLS-1$
112 throw new ExecutionException(Messages
.TraceControl_GettingVersionError
);