tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.remote.core / src / org / eclipse / tracecompass / tmf / remote / core / proxy / RemoteSystemProxy.java
CommitLineData
eb1bab5b 1/**********************************************************************
533d0bc3 2 * Copyright (c) 2012, 2015 Ericsson
cfdb727a 3 *
eb1bab5b
BH
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
cfdb727a
AM
8 *
9 * Contributors:
eb1bab5b 10 * Bernd Hufmann - Initial API and implementation
b732adaa 11 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
533d0bc3 12 * Bernd Hufmann - Update to org.eclipse.remote API 2.0
eb1bab5b 13 **********************************************************************/
ec619615 14package org.eclipse.tracecompass.tmf.remote.core.proxy;
eb1bab5b
BH
15
16import org.eclipse.core.commands.ExecutionException;
b732adaa 17import org.eclipse.core.runtime.IProgressMonitor;
d8a4fd60 18import org.eclipse.jdt.annotation.NonNullByDefault;
533d0bc3 19import org.eclipse.jdt.annotation.Nullable;
b732adaa 20import org.eclipse.remote.core.IRemoteConnection;
b732adaa 21import org.eclipse.remote.core.IRemoteConnectionChangeListener;
533d0bc3 22import org.eclipse.remote.core.RemoteConnectionChangeEvent;
b732adaa 23import org.eclipse.remote.core.exception.RemoteConnectionException;
13729cbc 24import org.eclipse.tracecompass.internal.tmf.remote.core.shell.CommandShell;
d8a4fd60 25import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandShell;
533d0bc3 26
eb1bab5b 27/**
eb1bab5b
BH
28 * <p>
29 * RemoteSystemProxy implementation.
30 * </p>
cfdb727a 31 *
dbd4432d 32 * @author Bernd Hufmann
eb1bab5b 33 */
d8a4fd60
BH
34@NonNullByDefault
35public class RemoteSystemProxy implements IRemoteConnectionChangeListener {
cfdb727a 36
eb1bab5b
BH
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
533d0bc3 40 private final IRemoteConnection fHost;
b732adaa 41 private boolean fExplicitConnect;
bbb3538a 42
eb1bab5b
BH
43 // ------------------------------------------------------------------------
44 // Constructors
45 // ------------------------------------------------------------------------
cfdb727a
AM
46
47 /**
48 * Constructor
49 *
50 * @param host
51 * The host of this proxy
52 */
b732adaa 53 public RemoteSystemProxy(IRemoteConnection host) {
eb1bab5b 54 fHost = host;
b732adaa 55 fHost.addConnectionChangeListener(this);
eb1bab5b
BH
56 }
57
d8a4fd60
BH
58 /**
59 * Returns the connection instance.
60 *
61 * @return the @link{IRemoteConnection} instance
62 */
63 public IRemoteConnection getRemoteConnection() {
64 return fHost;
65 }
66
eb1bab5b
BH
67 // ------------------------------------------------------------------------
68 // Operations
69 // ------------------------------------------------------------------------
11252342 70
d8a4fd60
BH
71 /**
72 * Connects the remote connection.
73 *
74 * @param monitor
75 * a monitor to report progress.
76 *
77 * @throws ExecutionException
78 * If the connection fails
79 */
b732adaa
MS
80 public void connect(IProgressMonitor monitor) throws ExecutionException {
81 try {
82 if (!fHost.isOpen()) {
2fb2f1a6 83 // Note that open() may trigger a RemoteConnectionChangeEvent
b732adaa 84 fHost.open(monitor);
2fb2f1a6 85 fExplicitConnect = true;
bbb3538a 86 }
b732adaa
MS
87 } catch (RemoteConnectionException e) {
88 throw new ExecutionException("Cannot connect " + fHost.getName(), e); //$NON-NLS-1$
bbb3538a 89 }
bbb3538a 90 }
cfdb727a 91
d8a4fd60 92 /**
2fb2f1a6 93 * Disconnects from the remote connection, may close the connection.
d8a4fd60
BH
94 */
95 public void disconnect() {
2fb2f1a6
BH
96 if (fExplicitConnect) {
97 fHost.close();
98 fExplicitConnect = false;
99 }
00de7b32
BH
100 }
101
d8a4fd60
BH
102 /**
103 * Disposes the proxy, may close the connection.
104 */
b732adaa
MS
105 public void dispose() {
106 fHost.removeConnectionChangeListener(this);
2fb2f1a6 107 disconnect();
00de7b32
BH
108 }
109
d8a4fd60
BH
110 /**
111 * Creates a command shell.
112 *
113 * @return the command shell implementation
d8a4fd60 114 */
13729cbc
BH
115 public ICommandShell createCommandShell() {
116 return new CommandShell(fHost);
eb1bab5b
BH
117 }
118
d8a4fd60
BH
119 /**
120 * Returns the connection state.
121 *
122 * @return whether the remote host is currently connected.
123 */
b732adaa
MS
124 public boolean isConnected() {
125 return fHost.isOpen();
eb1bab5b
BH
126 }
127
eb1bab5b 128 @Override
d8a4fd60
BH
129 public void connectionChanged(@Nullable RemoteConnectionChangeEvent event) {
130 if (event != null) {
131 int type = event.getType();
132 if (type == RemoteConnectionChangeEvent.CONNECTION_ABORTED ||
133 type == RemoteConnectionChangeEvent.CONNECTION_CLOSED) {
134 fExplicitConnect = false;
135 }
eb1bab5b
BH
136 }
137 }
533d0bc3 138
eb1bab5b 139}
This page took 0.077726 seconds and 5 git commands to generate.