Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/plugin.xml2
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ClientPlugin.java92
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/DiscoveryStartup.java141
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ServerStartup.java25
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/CollabDiscoveryView.java66
5 files changed, 13 insertions, 313 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml b/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
index 48a8f578e..7e5f3ca2b 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
+++ b/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
@@ -12,7 +12,7 @@
id="org.eclipse.ecf.internal.example.collab.ui.LineChatView"/>
<view
category="org.eclipse.ecf.ui.viewcategory"
- class="org.eclipse.ecf.internal.example.collab.ui.CollabDiscoveryView"
+ class="org.eclipse.ecf.discovery.ui.views.DiscoveryView"
icon="icons/default_provider_image.gif"
id="org.eclipse.ecf.example.collab.discoveryview"
name="Service Discovery"/>
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ClientPlugin.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ClientPlugin.java
index 25ffa8bd5..93cd5f91f 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ClientPlugin.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ClientPlugin.java
@@ -12,10 +12,6 @@ package org.eclipse.ecf.internal.example.collab;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter;
-import org.eclipse.ecf.discovery.IServiceInfo;
-import org.eclipse.ecf.discovery.ui.views.IDiscoveryController;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.widgets.Shell;
@@ -32,9 +28,8 @@ public class ClientPlugin extends AbstractUIPlugin implements ClientPluginConsta
private FontRegistry fontRegistry = null;
private ServerStartup serverStartup = null;
- private DiscoveryStartup discoveryStartup = null;
- public static final String TCPSERVER_DISCOVERY_TYPE = "_ecftcp._tcp.local."; //$NON-NLS-1$
- protected static String serviceTypes[] = new String[] {TCPSERVER_DISCOVERY_TYPE};
+
+ private BundleContext context;
public static void log(String message) {
getDefault().getLog().log(new Status(IStatus.OK, ClientPlugin.getDefault().getBundle().getSymbolicName(), IStatus.OK, message, null));
@@ -53,54 +48,6 @@ public class ClientPlugin extends AbstractUIPlugin implements ClientPluginConsta
this.fontRegistry = new FontRegistry();
}
- public IDiscoveryController getDiscoveryController() {
- return new IDiscoveryController() {
- public void connectToService(IServiceInfo service) {
- synchronized (ClientPlugin.this) {
- if (discoveryStartup == null)
- return;
- discoveryStartup.connectToServiceFromInfo(service);
- }
- }
-
- public void startDiscovery() {
- try {
- getDefault().initDiscovery();
- } catch (final Exception e) {
- ClientPlugin.log("Exception initializing discovery", e);
- }
- }
-
- public void stopDiscovery() {
- getDefault().disposeDiscovery();
- }
-
- public IDiscoveryContainerAdapter getDiscoveryContainer() {
- synchronized (ClientPlugin.this) {
- if (discoveryStartup == null)
- return null;
- return discoveryStartup.getDiscoveryContainer();
- }
- }
-
- public IContainer getContainer() {
- synchronized (ClientPlugin.this) {
- if (discoveryStartup == null)
- return null;
- return discoveryStartup.getContainer();
- }
- }
-
- public String[] getServiceTypes() {
- return serviceTypes;
- }
-
- public boolean isDiscoveryStarted() {
- return getDefault().isDiscoveryActive();
- }
- };
- }
-
protected void setPreferenceDefaults() {
this.getPreferenceStore().setDefault(ClientPlugin.PREF_USE_CHAT_WINDOW, false);
this.getPreferenceStore().setDefault(ClientPlugin.PREF_DISPLAY_TIMESTAMP, true);
@@ -119,18 +66,17 @@ public class ClientPlugin extends AbstractUIPlugin implements ClientPluginConsta
/**
* This method is called upon plug-in activation
- * @param context
+ * @param ctxt
* @throws Exception
*/
- public void start(BundleContext context) throws Exception {
- super.start(context);
+ public void start(BundleContext ctxt) throws Exception {
+ super.start(ctxt);
setPreferenceDefaults();
+ this.context = ctxt;
}
- public synchronized void initDiscovery() throws Exception {
- if (discoveryStartup == null) {
- discoveryStartup = new DiscoveryStartup();
- }
+ protected BundleContext getContext() {
+ return context;
}
public synchronized void initServer() throws Exception {
@@ -139,19 +85,6 @@ public class ClientPlugin extends AbstractUIPlugin implements ClientPluginConsta
}
}
- public synchronized void registerServers() {
- if (discoveryStartup != null && serverStartup != null) {
- serverStartup.registerServers();
- }
- }
-
- public synchronized boolean isDiscoveryActive() {
- if (discoveryStartup == null)
- return false;
- else
- return discoveryStartup.isActive();
- }
-
public synchronized boolean isServerActive() {
if (serverStartup == null)
return false;
@@ -159,13 +92,6 @@ public class ClientPlugin extends AbstractUIPlugin implements ClientPluginConsta
return serverStartup.isActive();
}
- public synchronized void disposeDiscovery() {
- if (discoveryStartup != null) {
- discoveryStartup.dispose();
- discoveryStartup = null;
- }
- }
-
public synchronized void disposeServer() {
if (serverStartup != null) {
serverStartup.dispose();
@@ -181,8 +107,8 @@ public class ClientPlugin extends AbstractUIPlugin implements ClientPluginConsta
public void stop(BundleContext context) throws Exception {
super.stop(context);
plugin = null;
+ context = null;
disposeServer();
- disposeDiscovery();
}
public FontRegistry getFontRegistry() {
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/DiscoveryStartup.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/DiscoveryStartup.java
deleted file mode 100644
index 5aa7e1071..000000000
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/DiscoveryStartup.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/****************************************************************************
- * Copyright (c) 2004 Composent, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- *****************************************************************************/
-package org.eclipse.ecf.internal.example.collab;
-
-import java.net.URI;
-import java.util.Properties;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.ecf.core.ContainerCreateException;
-import org.eclipse.ecf.core.ContainerFactory;
-import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.core.identity.IDFactory;
-import org.eclipse.ecf.core.identity.Namespace;
-import org.eclipse.ecf.core.sharedobject.ISharedObjectContainer;
-import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter;
-import org.eclipse.ecf.discovery.IServiceInfo;
-import org.eclipse.ecf.discovery.IServiceProperties;
-import org.eclipse.ecf.discovery.ServiceInfo;
-import org.eclipse.ecf.discovery.ServiceProperties;
-import org.eclipse.ecf.discovery.identity.IServiceID;
-import org.eclipse.ecf.internal.example.collab.actions.URIClientConnectAction;
-
-public class DiscoveryStartup {
- public static final String DISCOVERY_CONTAINER = "ecf.discovery.jmdns";
- public static final String PROP_PROTOCOL_NAME = "protocol";
- public static final String PROP_CONTAINER_TYPE_NAME = "containertype";
- public static final String PROP_CONTAINER_TYPE_VALUE = CollabClient.GENERIC_CONTAINER_CLIENT_NAME;
- public static final String PROP_PW_REQ_NAME = "pwrequired";
- public static final String PROP_PW_REQ_VALUE = "false";
- public static final String PROP_DEF_USER_NAME = "defaultuser";
- public static final String PROP_DEF_USER_VALUE = "guest";
- public static final String PROP_PATH_NAME = "path";
- public static final int SVC_DEF_WEIGHT = 0;
- public static final int SVC_DEF_PRIORITY = 0;
-
- static IDiscoveryContainerAdapter discovery = null;
- static IContainer container = null;
-
- public DiscoveryStartup() throws Exception {
- setupDiscovery();
- }
-
- protected IDiscoveryContainerAdapter getDiscoveryContainer() {
- return discovery;
- }
-
- protected IContainer getContainer() {
- return container;
- }
-
- public void dispose() {
- if (container != null) {
- container.dispose();
- container = null;
- }
- discovery = null;
- }
-
- protected boolean isActive() {
- return discovery != null;
- }
-
- protected void setupDiscovery() throws Exception {
- try {
- container = ContainerFactory.getDefault().createContainer(DISCOVERY_CONTAINER);
- discovery = (IDiscoveryContainerAdapter) container.getAdapter(IDiscoveryContainerAdapter.class);
- if (discovery != null) {
- container.connect(null, null);
- } else {
- dispose();
- ClientPlugin.log("No discovery container available");
- }
- } catch (final ContainerCreateException e1) {
- container = null;
- discovery = null;
- ClientPlugin.log("No discovery container available", e1);
- return;
- } catch (final Exception e) {
- dispose();
- throw e;
- }
- }
-
- protected void connectToServiceFromInfo(IServiceInfo svcInfo) {
- final IServiceProperties props = svcInfo.getServiceProperties();
- String type = props.getPropertyString(PROP_CONTAINER_TYPE_NAME);
- if (type == null || type.equals("")) {
- type = CollabClient.GENERIC_CONTAINER_CLIENT_NAME;
- }
- final String username = System.getProperty("user.name");
- String targetString = null;
- IResource workspace = null;
- try {
- targetString = new URI(svcInfo.getServiceID().getName()).toString();
- workspace = ResourcesPlugin.getWorkspace().getRoot();
- } catch (final Exception e) {
- ClientPlugin.log("Exception connecting to service with info " + svcInfo, e);
- return;
- }
- final URIClientConnectAction action = new URIClientConnectAction(type, targetString, username, null, workspace, false);
- // do it
- action.run(null);
- }
-
- public static void registerService(URI uri) {
- if (discovery != null) {
- try {
- final String path = uri.getPath();
- final Properties props = new Properties();
- final String protocol = uri.getScheme();
- props.setProperty(PROP_CONTAINER_TYPE_NAME, PROP_CONTAINER_TYPE_VALUE);
- props.setProperty(PROP_PROTOCOL_NAME, protocol);
- props.setProperty(PROP_PW_REQ_NAME, PROP_PW_REQ_VALUE);
- props.setProperty(PROP_DEF_USER_NAME, PROP_DEF_USER_VALUE);
- props.setProperty(PROP_PATH_NAME, path);
- final String svcName = System.getProperty("user.name") + "." + protocol;
- final Namespace namespace = IDFactory.getDefault().getNamespaceByName("zeroconf.jmdns");
- final IServiceID srvID = (IServiceID) namespace.createInstance(new String[] {ClientPlugin.TCPSERVER_DISCOVERY_TYPE, svcName});
- final ServiceInfo svcInfo = new ServiceInfo(uri, srvID, SVC_DEF_PRIORITY, SVC_DEF_WEIGHT, new ServiceProperties(props));
- discovery.registerService(svcInfo);
- } catch (final Exception e) {
- ClientPlugin.log("Exception registering service " + uri, e);
- }
- } else {
- ClientPlugin.log("Cannot register service " + uri + " because no discovery service is available");
- }
- }
-
- public static void unregisterServer(ISharedObjectContainer container) {
- }
-
-}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ServerStartup.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ServerStartup.java
index f8a72ac8b..549921e2e 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ServerStartup.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ServerStartup.java
@@ -11,8 +11,6 @@
package org.eclipse.ecf.internal.example.collab;
import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -20,7 +18,6 @@ import java.util.List;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
-import org.eclipse.ecf.core.sharedobject.ISharedObjectContainer;
import org.eclipse.ecf.provider.generic.SOContainerConfig;
import org.eclipse.ecf.provider.generic.TCPServerSOContainer;
import org.eclipse.ecf.provider.generic.TCPServerSOContainerGroup;
@@ -51,7 +48,6 @@ public class ServerStartup {
protected synchronized void destroyServers() {
for (final Iterator i = servers.iterator(); i.hasNext();) {
final TCPServerSOContainer s = (TCPServerSOContainer) i.next();
- DiscoveryStartup.unregisterServer(s);
if (s != null) {
try {
s.dispose();
@@ -70,17 +66,17 @@ public class ServerStartup {
}
protected synchronized void createServers(InputStream ins) throws Exception {
- ServerConfigParser scp = new ServerConfigParser();
+ final ServerConfigParser scp = new ServerConfigParser();
final List connectors = scp.load(ins);
if (connectors != null) {
serverGroups = new TCPServerSOContainerGroup[connectors.size()];
int j = 0;
for (final Iterator i = connectors.iterator(); i.hasNext();) {
- Connector connect = (Connector) i.next();
+ final Connector connect = (Connector) i.next();
serverGroups[j] = createServerGroup(connect.getHostname(), connect.getPort());
final List groups = connect.getGroups();
for (final Iterator g = groups.iterator(); g.hasNext();) {
- NamedGroup group = (NamedGroup) g.next();
+ final NamedGroup group = (NamedGroup) g.next();
final TCPServerSOContainer cont = createServerContainer(group.getIDForGroup(), serverGroups[j], group.getName(), connect.getTimeout());
servers.add(cont);
ClientPlugin.log("ECF group server created: " + cont.getConfig().getID().getName());
@@ -91,21 +87,6 @@ public class ServerStartup {
}
}
- protected void registerServers() {
- for (final Iterator i = servers.iterator(); i.hasNext();) {
- final ISharedObjectContainer cont = (ISharedObjectContainer) i.next();
- try {
- registerServer(cont);
- } catch (final Exception e) {
- ClientPlugin.log("Exception registering server " + cont.getID().getName() + " for discovery", e);
- }
- }
- }
-
- protected void registerServer(ISharedObjectContainer cont) throws URISyntaxException {
- DiscoveryStartup.registerService(new URI(cont.getID().getName()));
- }
-
protected TCPServerSOContainerGroup createServerGroup(String name, int port) {
final TCPServerSOContainerGroup group = new TCPServerSOContainerGroup(name, port);
return group;
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/CollabDiscoveryView.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/CollabDiscoveryView.java
deleted file mode 100644
index 34418583c..000000000
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/CollabDiscoveryView.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************************
- * Copyright (c) 2004 Composent, Inc. and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Composent, Inc. - initial API and implementation
- *****************************************************************************/
-package org.eclipse.ecf.internal.example.collab.ui;
-
-import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter;
-import org.eclipse.ecf.discovery.IServiceEvent;
-import org.eclipse.ecf.discovery.IServiceListener;
-import org.eclipse.ecf.discovery.IServiceTypeEvent;
-import org.eclipse.ecf.discovery.IServiceTypeListener;
-import org.eclipse.ecf.discovery.ui.views.DiscoveryView;
-import org.eclipse.ecf.discovery.ui.views.IDiscoveryController;
-import org.eclipse.ecf.internal.example.collab.ClientPlugin;
-
-public class CollabDiscoveryView extends DiscoveryView {
-
- public static final String VIEW_ID = "org.eclipse.ecf.example.collab.discoveryview"; //$NON-NLS-1$
-
- protected static final int SERVICE_REQUEST_TIMEOUT = 3000;
-
- public CollabDiscoveryView() {
- super();
- setShowTypeDetails(false);
- this.setDiscoveryController(ClientPlugin.getDefault().getDiscoveryController());
- }
-
- public void setDiscoveryController(final IDiscoveryController controller) {
- super.setDiscoveryController(controller);
- if (controller != null) {
- final IDiscoveryContainerAdapter dc = controller.getDiscoveryContainer();
- if (dc != null) {
- // setup listeners
- dc.addServiceTypeListener(new IServiceTypeListener() {
- public void serviceTypeDiscovered(IServiceTypeEvent event) {
- addServiceTypeInfo(event.getServiceTypeID().getName());
- dc.addServiceListener(event.getServiceTypeID(), new IServiceListener() {
- public void serviceDiscovered(IServiceEvent anEvent) {
- addServiceInfo(anEvent.getServiceInfo().getServiceID());
- addServiceInfo(anEvent.getServiceInfo());
- }
-
- public void serviceUndiscovered(IServiceEvent anEvent) {
- removeServiceInfo(anEvent.getServiceInfo());
- }
- });
- }
- });
- }
- }
- }
-
- public void dispose() {
- final IDiscoveryController c = getController();
- if (c != null && c.isDiscoveryStarted()) {
- c.stopDiscovery();
- }
- super.dispose();
- }
-}

Back to the top