Bug 448058: Replace RSE by org.eclipse.remote
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / remote / RemoteSystemProxy.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 * Bernd Hufmann - Initial API and implementation
11 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.remote;
14
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.remote.core.IRemoteConnection;
18 import org.eclipse.remote.core.IRemoteConnectionChangeEvent;
19 import org.eclipse.remote.core.IRemoteConnectionChangeListener;
20 import org.eclipse.remote.core.IRemoteFileManager;
21 import org.eclipse.remote.core.IRemoteProcessBuilder;
22 import org.eclipse.remote.core.exception.RemoteConnectionException;
23
24 /**
25 * <p>
26 * RemoteSystemProxy implementation.
27 * </p>
28 *
29 * @author Bernd Hufmann
30 */
31 public class RemoteSystemProxy implements IRemoteSystemProxy, IRemoteConnectionChangeListener {
32
33 // ------------------------------------------------------------------------
34 // Attributes
35 // ------------------------------------------------------------------------
36
37 private IRemoteConnection fHost;
38 private boolean fExplicitConnect;
39
40 // ------------------------------------------------------------------------
41 // Constructors
42 // ------------------------------------------------------------------------
43
44 /**
45 * Constructor
46 *
47 * @param host
48 * The host of this proxy
49 */
50 public RemoteSystemProxy(IRemoteConnection host) {
51 fHost = host;
52 fHost.addConnectionChangeListener(this);
53 }
54
55 // ------------------------------------------------------------------------
56 // Operations
57 // ------------------------------------------------------------------------
58
59 @Override
60 public IRemoteFileManager getFileServiceSubSystem() {
61 return fHost.getFileManager();
62 }
63
64 @Override
65 public IRemoteProcessBuilder getProcessBuilder(String...command) {
66 return fHost.getProcessBuilder(command);
67 }
68
69 @Override
70 public void connect(IProgressMonitor monitor) throws ExecutionException {
71 try {
72 if (!fHost.isOpen()) {
73 fExplicitConnect = true;
74 fHost.open(monitor);
75 }
76 } catch (RemoteConnectionException e) {
77 throw new ExecutionException("Cannot connect " + fHost.getName(), e); //$NON-NLS-1$
78 }
79 }
80
81 @Override
82 public void disconnect() throws ExecutionException {
83 fHost.close();
84 }
85
86 @Override
87 public void dispose() {
88 fHost.removeConnectionChangeListener(this);
89 if (fExplicitConnect) {
90 fHost.close();
91 }
92 }
93
94 @Override
95 public ICommandShell createCommandShell() throws ExecutionException {
96 ICommandShell shell = new CommandShell(fHost);
97 shell.connect();
98 return shell;
99 }
100
101 @Override
102 public void addConnectionChangeListener(IRemoteConnectionChangeListener listener) {
103 fHost.addConnectionChangeListener(listener);
104 }
105
106 @Override
107 public void removeConnectionChangeListener(IRemoteConnectionChangeListener listener) {
108 fHost.removeConnectionChangeListener(listener);
109 }
110
111 @Override
112 public boolean isConnected() {
113 return fHost.isOpen();
114 }
115
116 @Override
117 public void connectionChanged(IRemoteConnectionChangeEvent event) {
118 int type = event.getType();
119 if (type == IRemoteConnectionChangeEvent.CONNECTION_ABORTED ||
120 type == IRemoteConnectionChangeEvent.CONNECTION_CLOSED) {
121 fExplicitConnect = false;
122 }
123 }
124 }
This page took 0.047025 seconds and 6 git commands to generate.