|
Lines 4-10
Link Here
|
| 4 |
|
4 |
|
| 5 |
import org.eclipse.core.runtime.Assert; |
5 |
import org.eclipse.core.runtime.Assert; |
| 6 |
import org.eclipse.core.runtime.IProgressMonitor; |
6 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 7 |
import org.eclipse.core.runtime.content.IContentTypeManager.ISelectionPolicy; |
7 |
import org.eclipse.core.runtime.IStatus; |
|
|
8 |
import org.eclipse.core.runtime.Status; |
| 8 |
import org.eclipse.ecf.core.IContainer; |
9 |
import org.eclipse.ecf.core.IContainer; |
| 9 |
import org.eclipse.ecf.core.IContainerManager; |
10 |
import org.eclipse.ecf.core.IContainerManager; |
| 10 |
import org.eclipse.ecf.core.identity.IDFactory; |
11 |
import org.eclipse.ecf.core.identity.IDFactory; |
|
Lines 20-29
Link Here
|
| 20 |
import org.osgi.util.tracker.ServiceTracker; |
21 |
import org.osgi.util.tracker.ServiceTracker; |
| 21 |
|
22 |
|
| 22 |
import ch.ethz.iks.r_osgi.RemoteOSGiService; |
23 |
import ch.ethz.iks.r_osgi.RemoteOSGiService; |
| 23 |
import ch.ethz.iks.r_osgi.Remoting; |
|
|
| 24 |
|
24 |
|
| 25 |
public class RosgiRegistryBackend implements RegistryBackend { |
25 |
public class RosgiRegistryBackend implements RegistryBackend { |
| 26 |
private static final String DEFAULT_PORT = "9278"; |
|
|
| 27 |
private static final String DEFAULT_PROTOCOL = "r-osgi://"; |
26 |
private static final String DEFAULT_PROTOCOL = "r-osgi://"; |
| 28 |
private static final String DEFAULT_CONTAINER_TYPE = "ecf.r_osgi.peer"; |
27 |
private static final String DEFAULT_CONTAINER_TYPE = "ecf.r_osgi.peer"; |
| 29 |
|
28 |
|
|
Lines 35-41
Link Here
|
| 35 |
|
34 |
|
| 36 |
private String serverURI; |
35 |
private String serverURI; |
| 37 |
|
36 |
|
|
|
37 |
private String status = "not connected"; |
| 38 |
|
| 38 |
public boolean connect(IProgressMonitor monitor) { |
39 |
public boolean connect(IProgressMonitor monitor) { |
|
|
40 |
status = "connecting with " + serverURI; |
| 39 |
try { |
41 |
try { |
| 40 |
IContainerManager containerManager = getContainerManagerService(); |
42 |
IContainerManager containerManager = getContainerManagerService(); |
| 41 |
container = containerManager.getContainerFactory().createContainer(DEFAULT_CONTAINER_TYPE); |
43 |
container = containerManager.getContainerFactory().createContainer(DEFAULT_CONTAINER_TYPE); |
|
Lines 65-76
Link Here
|
| 65 |
} |
67 |
} |
| 66 |
|
68 |
|
| 67 |
if (remoteRosgiHost.connectRemoteBackendChangeListener() == false) { |
69 |
if (remoteRosgiHost.connectRemoteBackendChangeListener() == false) { |
| 68 |
throw new Exception("Unable to connect with server"); |
70 |
throw new Exception("Unable to connect with a server"); |
| 69 |
} |
71 |
} |
|
|
72 |
status = "connected with " + serverURI; |
| 70 |
return true; |
73 |
return true; |
| 71 |
|
74 |
|
| 72 |
} catch (Exception e) { |
75 |
} catch (Exception e) { |
|
|
76 |
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); |
| 73 |
disconnect(); |
77 |
disconnect(); |
|
|
78 |
status = "cannot connect with " + serverURI; |
| 74 |
return false; |
79 |
return false; |
| 75 |
} |
80 |
} |
| 76 |
} |
81 |
} |
|
Lines 124-140
Link Here
|
| 124 |
container.disconnect(); |
129 |
container.disconnect(); |
| 125 |
container = null; |
130 |
container = null; |
| 126 |
} |
131 |
} |
|
|
132 |
status = "disconnected"; |
| 127 |
} |
133 |
} |
| 128 |
|
134 |
|
| 129 |
private boolean registerBackendListener() { |
135 |
private boolean registerBackendListener() { |
| 130 |
IRemoteServiceContainerAdapter containerAdapter = |
136 |
IRemoteServiceContainerAdapter containerAdapter = |
| 131 |
(IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class); |
137 |
(IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class); |
| 132 |
|
|
|
| 133 |
remoteBackendChangeListenerService = containerAdapter.registerRemoteService( |
138 |
remoteBackendChangeListenerService = containerAdapter.registerRemoteService( |
| 134 |
new String[] { BackendChangeListener.class.getName() }, backendChangeListener, null); |
139 |
new String[] { BackendChangeListener.class.getName() }, backendChangeListener, null); |
| 135 |
|
|
|
| 136 |
System.out.println("BackendChangeListener RemoteService registered"); |
| 137 |
|
| 138 |
return true; |
140 |
return true; |
| 139 |
} |
141 |
} |
| 140 |
|
142 |
|
|
Lines 150-153
Link Here
|
| 150 |
public void setURI(String uri) { |
152 |
public void setURI(String uri) { |
| 151 |
this.serverURI = uri; |
153 |
this.serverURI = uri; |
| 152 |
} |
154 |
} |
|
|
155 |
|
| 156 |
public String getStatus() { |
| 157 |
return status + " - "; |
| 158 |
} |
| 153 |
} |
159 |
} |