1 /**********************************************************************
2 * Copyright (c) 2012, 2015 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 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
12 * Bernd Hufmann - Update to org.eclipse.remote API 2.0
13 **********************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.remote
.core
.IRemoteConnection
;
21 import org
.eclipse
.remote
.core
.IRemoteConnectionChangeListener
;
22 import org
.eclipse
.remote
.core
.RemoteConnectionChangeEvent
;
23 import org
.eclipse
.remote
.core
.exception
.RemoteConnectionException
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.core
.shell
.CommandShell
;
25 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
29 * RemoteSystemProxy implementation.
32 * @author Bernd Hufmann
35 public class RemoteSystemProxy
implements IRemoteConnectionChangeListener
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
40 private final IRemoteConnection fHost
;
41 private boolean fExplicitConnect
;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
51 * The host of this proxy
53 public RemoteSystemProxy(IRemoteConnection host
) {
55 fHost
.addConnectionChangeListener(this);
59 * Returns the connection instance.
61 * @return the @link{IRemoteConnection} instance
63 public IRemoteConnection
getRemoteConnection() {
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 * Connects the remote connection.
75 * a monitor to report progress.
77 * @throws ExecutionException
78 * If the connection fails
80 public void connect(IProgressMonitor monitor
) throws ExecutionException
{
82 if (!fHost
.isOpen()) {
83 // Note that open() may trigger a RemoteConnectionChangeEvent
85 fExplicitConnect
= true;
87 } catch (RemoteConnectionException e
) {
88 throw new ExecutionException("Cannot connect " + fHost
.getName(), e
); //$NON-NLS-1$
93 * Disconnects from the remote connection, may close the connection.
95 public void disconnect() {
96 if (fExplicitConnect
) {
98 fExplicitConnect
= false;
103 * Disposes the proxy, may close the connection.
105 public void dispose() {
106 fHost
.removeConnectionChangeListener(this);
111 * Creates a command shell.
113 * @return the command shell implementation
115 public ICommandShell
createCommandShell() {
116 return new CommandShell(fHost
);
120 * Returns the connection state.
122 * @return whether the remote host is currently connected.
124 public boolean isConnected() {
125 return fHost
.isOpen();
129 public void connectionChanged(@Nullable RemoteConnectionChangeEvent event
) {
131 int type
= event
.getType();
132 if (type
== RemoteConnectionChangeEvent
.CONNECTION_ABORTED
||
133 type
== RemoteConnectionChangeEvent
.CONNECTION_CLOSED
) {
134 fExplicitConnect
= false;