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
.internal
.lttng2
.ui
.views
.control
.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
.ui
.views
.control
.messages
.Messages
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandResult
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.ICommandShell
;
24 * Factory to create LTTngControlService instances depending on the version of the LTTng Trace Control
25 * installed on the remote host.
28 * @author Bernd Hufmann
30 public class LTTngControlServiceFactory
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 * The singleton instance.
38 private static LTTngControlServiceFactory fInstance
= null;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
46 private LTTngControlServiceFactory() {
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 * @return the LTTngControlServiceFactory singleton instance.
55 public static synchronized LTTngControlServiceFactory
getInstance() {
56 if (fInstance
== null) {
57 fInstance
= new LTTngControlServiceFactory();
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 * Gets the LTTng Control Service implementation based on the version of the
69 * @param shell - the shell implementation to pass to the service
70 * @return - LTTng Control Service implementation
71 * @throws ExecutionException
73 public ILttngControlService
getLttngControlService(ICommandShell shell
) throws ExecutionException
{
75 ICommandResult result
= shell
.executeCommand(LTTngControlServiceConstants
.CONTROL_COMMAND
+ LTTngControlServiceConstants
.COMMAND_VERSION
, new NullProgressMonitor());
77 if ((result
!= null) && (result
.getResult() == 0) && (result
.getOutput().length
>= 1) && (!LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
79 while (index
< result
.getOutput().length
) {
80 String line
= result
.getOutput()[index
];
81 Matcher matcher
= LTTngControlServiceConstants
.VERSION_PATTERN
.matcher(line
);
82 if (matcher
.matches()) {
83 String version
= matcher
.group(1).trim();
84 if (version
.startsWith(LTTngControlServiceConstants
.LTTNG_MAJOR_VERSION_2_0
)) {
85 LTTngControlService service
= new LTTngControlService(shell
);
86 service
.setVersion(version
);
89 throw new ExecutionException(Messages
.TraceControl_UnsupportedVersionError
+ ": " + version
); //$NON-NLS-1$
94 throw new ExecutionException(Messages
.TraceControl_GettingVersionError
);