river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tho...@apache.org
Subject svn commit: r1240194 - in /river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery: ./ AbstractDiscovery.java DiscoveryException.java EasyDiscovery.java MulticastDiscovery.java UnicastDiscovery.java
Date Fri, 03 Feb 2012 14:40:38 GMT
Author: thobbs
Date: Fri Feb  3 14:40:37 2012
New Revision: 1240194

URL: http://svn.apache.org/viewvc?rev=1240194&view=rev
Log:
missing files.  oops

Added:
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/AbstractDiscovery.java
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/DiscoveryException.java
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/EasyDiscovery.java
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/MulticastDiscovery.java
    river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/UnicastDiscovery.java

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/AbstractDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/AbstractDiscovery.java?rev=1240194&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/AbstractDiscovery.java
(added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/AbstractDiscovery.java
Fri Feb  3 14:40:37 2012
@@ -0,0 +1,69 @@
+package org.apache.river.extra.easystart.discovery;
+
+import java.io.IOException;
+import java.rmi.RMISecurityManager;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import net.jini.discovery.DiscoveryManagement;
+import net.jini.lease.LeaseRenewalManager;
+import net.jini.lookup.LookupCache;
+import net.jini.lookup.ServiceDiscoveryListener;
+import net.jini.lookup.ServiceDiscoveryManager;
+
+public abstract class AbstractDiscovery implements EasyDiscovery {
+
+	private static final Logger log = Logger.getLogger(AbstractDiscovery.class.getSimpleName());
+	
+	private final DiscoveryManagement disco;
+	private final ServiceDiscoveryManager sdm;
+	private final LookupCache cache;
+	
+	protected AbstractDiscovery(DiscoveryManagement dm) throws IOException {
+		System.setSecurityManager(new RMISecurityManager());
+		
+		this.disco = dm;
+		
+		LeaseRenewalManager lrm = new LeaseRenewalManager();
+		sdm = new ServiceDiscoveryManager(dm, lrm);
+		cache = sdm.createLookupCache(EVERYTHING, NO_FILTER, NO_LISTENER);
+	}
+	
+	protected DiscoveryManagement getDiscoveryManagement() {
+		return this.disco;
+	}
+	
+	protected ServiceDiscoveryManager getServiceDiscoveryManager() {
+		return this.sdm;
+	}
+	
+	protected LookupCache getCache() {
+		return this.cache;
+	}
+	
+	@Override
+	public void addServiceDiscoveryListener(ServiceDiscoveryListener sdl) {
+		if(null != sdl) {
+			cache.addListener(sdl);
+		}
+	}
+	
+	@Override
+	public void terminate() {
+		try {
+			cache.terminate();
+		} catch (Exception e) {
+			log.log(Level.WARNING, "Failed to terminate LookupCache", e);
+		}
+		try {
+			sdm.terminate();
+		} catch (Exception e) {
+			log.log(Level.WARNING, "Failed to terminate ServiceDiscoveryManager", e);
+		}
+		try {
+			disco.terminate();
+		} catch (Exception e) {
+			log.log(Level.WARNING, "Failed to terminate DiscoveryManagement", e);
+		}
+	}
+}

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/DiscoveryException.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/DiscoveryException.java?rev=1240194&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/DiscoveryException.java
(added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/DiscoveryException.java
Fri Feb  3 14:40:37 2012
@@ -0,0 +1,18 @@
+package org.apache.river.extra.easystart.discovery;
+
+import java.rmi.RemoteException;
+
+public class DiscoveryException extends RuntimeException {
+
+	private static final long serialVersionUID = -5785894817597158158L;
+
+	public DiscoveryException(RemoteException e) {
+		super(e);
+	}
+
+	public DiscoveryException(String msg) {
+		super(msg);
+	}
+
+
+}

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/EasyDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/EasyDiscovery.java?rev=1240194&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/EasyDiscovery.java
(added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/EasyDiscovery.java
Fri Feb  3 14:40:37 2012
@@ -0,0 +1,27 @@
+package org.apache.river.extra.easystart.discovery;
+
+import java.rmi.RemoteException;
+import java.util.Iterator;
+import java.util.List;
+
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.lookup.ServiceDiscoveryListener;
+import net.jini.lookup.ServiceItemFilter;
+
+public interface EasyDiscovery extends Iterable<ServiceItem> {
+
+	final static ServiceItemFilter NO_FILTER = null;
+	final static ServiceDiscoveryListener NO_LISTENER = null;
+	final static ServiceTemplate EVERYTHING = new ServiceTemplate(null, null, null);
+	
+	public abstract void terminate();
+
+	public abstract List<ServiceItem> lookupAll(ServiceTemplate tmpl) throws RemoteException;
+
+	@Override
+	public abstract Iterator<ServiceItem> iterator();
+	
+	public abstract void addServiceDiscoveryListener(ServiceDiscoveryListener sdl);
+
+}

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/MulticastDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/MulticastDiscovery.java?rev=1240194&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/MulticastDiscovery.java
(added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/MulticastDiscovery.java
Fri Feb  3 14:40:37 2012
@@ -0,0 +1,33 @@
+package org.apache.river.extra.easystart.discovery;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.discovery.LookupDiscovery;
+
+public class MulticastDiscovery extends AbstractDiscovery {
+
+	public MulticastDiscovery() throws IOException {
+		this(LookupDiscovery.ALL_GROUPS);
+	}
+
+	public MulticastDiscovery(String[] groups) throws IOException {
+		super(new LookupDiscovery(groups));
+	}
+
+	@Override
+	public Iterator<ServiceItem> iterator() {
+		ServiceItem[] services = getCache().lookup(null, Integer.MAX_VALUE);
+		return Arrays.asList(services).iterator();
+	}
+
+	@Override
+	public List<ServiceItem> lookupAll(ServiceTemplate tmpl) {
+		return Arrays.asList(getServiceDiscoveryManager().lookup(tmpl, Integer.MAX_VALUE, null));
+	}
+
+}

Added: river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/UnicastDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/UnicastDiscovery.java?rev=1240194&view=auto
==============================================================================
--- river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/UnicastDiscovery.java
(added)
+++ river/jtsk/skunk/easystart/src-extra/org/apache/river/extra/easystart/discovery/UnicastDiscovery.java
Fri Feb  3 14:40:37 2012
@@ -0,0 +1,46 @@
+package org.apache.river.extra.easystart.discovery;
+
+import java.io.IOException;
+import java.rmi.RemoteException;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import net.jini.core.discovery.LookupLocator;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceMatches;
+import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.discovery.LookupLocatorDiscovery;
+
+public class UnicastDiscovery extends AbstractDiscovery {
+
+	public UnicastDiscovery(LookupLocator[] locators) throws IOException {
+		super(new LookupLocatorDiscovery(locators));
+	}
+
+	@Override
+	public List<ServiceItem> lookupAll(ServiceTemplate tmpl) throws RemoteException {
+		ServiceRegistrar[] registrars = getDiscoveryManagement().getRegistrars();
+		if(null != registrars && 0 != registrars.length) {
+			ServiceMatches matches = registrars[0].lookup(tmpl, Integer.MAX_VALUE);
+			return Arrays.asList(matches.items);
+		} else {
+			return null;
+		}
+	}
+
+	@Override
+	public Iterator<ServiceItem> iterator() throws DiscoveryException {
+		try {
+			List<ServiceItem> all = lookupAll(EVERYTHING);
+			if(null != all) {
+				return all.iterator();
+			}
+		} catch (RemoteException e) {
+			throw new DiscoveryException(e);
+		}
+		return null;
+	}
+
+}



Mime
View raw message