[Gabel-guys] gabel/src/net/sf/gabel/server KNService.java,1.1,1.2 KnownNodeServer.java,1.2,1.3 RmiSe
Status: Alpha
Brought to you by:
alllee
|
From: allen l. <al...@us...> - 2004-05-12 10:08:27
|
Update of /cvsroot/gabel/gabel/src/net/sf/gabel/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19336/src/net/sf/gabel/server Modified Files: KNService.java KnownNodeServer.java RmiServer.java Service.java Log Message: More refactoring, turning KnownNodeServer into a specific instance of the more general RmiServer. Index: Service.java =================================================================== RCS file: /cvsroot/gabel/gabel/src/net/sf/gabel/server/Service.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Service.java 12 May 2004 08:56:01 -0000 1.1 --- Service.java 12 May 2004 10:08:16 -0000 1.2 *************** *** 28,34 **** } ! public Service(KNService service) { ! delegate = service; ! properties = service.myParameters; } --- 28,34 ---- } ! public Service(String description, KNService delegate) { ! this(description, delegate.properties); ! this.delegate = delegate; } *************** *** 61,64 **** --- 61,68 ---- /* * $Log$ + * Revision 1.2 2004/05/12 10:08:16 alllee + * More refactoring, turning KnownNodeServer into a specific instance of the more + * general RmiServer. + * * Revision 1.1 2004/05/12 08:56:01 alllee * First cut at generalizing the KNS server. Index: RmiServer.java =================================================================== RCS file: /cvsroot/gabel/gabel/src/net/sf/gabel/server/RmiServer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RmiServer.java 12 May 2004 08:56:01 -0000 1.1 --- RmiServer.java 12 May 2004 10:08:16 -0000 1.2 *************** *** 1,5 **** package net.sf.gabel.server; - import java.rmi.Remote; import java.rmi.RemoteException; --- 1,4 ---- *************** *** 33,38 **** - public boolean remove(Service service) throws RemoteException; - /** * Stores a file on this remote machine. Very useful for --- 32,35 ---- *************** *** 54,57 **** --- 51,58 ---- /* * $Log$ + * Revision 1.2 2004/05/12 10:08:16 alllee + * More refactoring, turning KnownNodeServer into a specific instance of the more + * general RmiServer. + * * Revision 1.1 2004/05/12 08:56:01 alllee * First cut at generalizing the KNS server. Index: KNService.java =================================================================== RCS file: /cvsroot/gabel/gabel/src/net/sf/gabel/server/KNService.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** KNService.java 12 May 2004 08:56:01 -0000 1.1 --- KNService.java 12 May 2004 10:08:16 -0000 1.2 *************** *** 30,34 **** /** * The parameters of this service, can be anything */ ! public Properties myParameters = null; } --- 30,34 ---- /** * The parameters of this service, can be anything */ ! public Properties properties = null; } Index: KnownNodeServer.java =================================================================== RCS file: /cvsroot/gabel/gabel/src/net/sf/gabel/server/KnownNodeServer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** KnownNodeServer.java 12 May 2004 09:32:47 -0000 1.2 --- KnownNodeServer.java 12 May 2004 10:08:16 -0000 1.3 *************** *** 19,31 **** * @web http://groupsolve.dhs.org/ */ ! public class KnownNodeServer extends UnicastRemoteObject implements KNServable, Runnable { private final static int MAX_SERVICES = 100; private final Logger logger = Logger.getLogger(getClass().getName()); ! private Registry registry = null; ! // FIXME: this should be configurable. Either hand-roll configuration ! // management or use Jakarta Commons Configuration ! private static int myPort = 2099; /* defunct arrays. private int numServices = 0; --- 19,32 ---- * @web http://groupsolve.dhs.org/ */ ! public class KnownNodeServer extends AbstractRmiServer implements KNServable { + // FIXME: all this should be configurable at runtime. Either hand-roll + // configuration management or use Jakarta Commons Configuration private final static int MAX_SERVICES = 100; + private final static int PORT_NUMBER = 2099; + private final static String REGISTRY_NAME = "kns"; private final Logger logger = Logger.getLogger(getClass().getName()); ! // private Registry registry = null; /* defunct arrays. private int numServices = 0; *************** *** 36,42 **** // Map< String, Service > private final Map services = new LinkedHashMap(); - // FIXME: private boolean running = true; --- 37,43 ---- // Map< String, Service > + // using a LinkedHashMap to maintain insertion order private final Map services = new LinkedHashMap(); private boolean running = true; *************** *** 66,70 **** /** Sets up a new registry using the given port - */ public boolean createReg(int port) { try { --- 67,70 ---- *************** *** 77,84 **** return true; } /** Let us add ourselves to the registry * so that others can find us - */ public boolean addMyself() throws RemoteException { try { --- 77,84 ---- return true; } + */ /** Let us add ourselves to the registry * so that others can find us public boolean addMyself() throws RemoteException { try { *************** *** 92,95 **** --- 92,108 ---- return false; } + */ + + public String getRegistryName() { + return REGISTRY_NAME; + } + + public int getPort() { + return PORT_NUMBER; + } + + public String[] availableServices() throws RemoteException { + return listService(); + } /** Returns an array of available services. *************** *** 102,105 **** --- 115,126 ---- } + public boolean add(Service service) throws RemoteException { + if ( services.size() < MAX_SERVICES ) { + services.put(service.toString(), service); + return true; + } + return false; + } + /** Adds a service with the given name and properties to this kns. * <P> *************** *** 110,119 **** */ public boolean addService(String description, KNService obj) throws RemoteException { ! if ( services.size() < MAX_SERVICES ) { ! services.put(description, new Service(obj)); ! return true; ! } ! return false; ! /* int x = 0; --- 131,136 ---- */ public boolean addService(String description, KNService obj) throws RemoteException { ! return add(new Service(description, obj)); ! /* int x = 0; *************** *** 144,155 **** } ! /** Removes the service with the given name ! */ ! public boolean removeService(String description) throws RemoteException { ! if ( services.containsKey(description) ) { ! Service service = (Service) services.remove(description); return true; } return false; /* int x = 0; --- 161,178 ---- } ! public boolean remove(String key) throws RemoteException { ! if ( services.containsKey(key) ) { ! Service service = (Service) services.remove(key); ! logger.info("Removing service: " + key); return true; } return false; + } + + + /** Removes the service with the given name + */ + public boolean removeService(String description) throws RemoteException { + return remove(description); /* int x = 0; *************** *** 180,183 **** --- 203,214 ---- } + public Service get(String key) throws RemoteException { + return (Service) services.get(key); + } + + public void persist(String filename, byte[] data) throws RemoteException { + storeFile(filename, data); + } + /** * Returns the object encapsulating the setup information *************** *** 217,221 **** // do maintenance ! public void run() { while (running) { try { --- 248,252 ---- // do maintenance ! public void execute() { while (running) { try { *************** *** 322,327 **** --- 353,360 ---- } + /* if (line.equals("add")) addMyself(); + */ } *************** *** 337,346 **** KnownNodeServer kns = new KnownNodeServer(); new Thread(kns).start(); success = kns.createReg(myPort); if (!success) throw new Exception("Could not create the registry!!"); success = kns.addMyself(); if (!success) throw new Exception("Could not add myself to the registry!!"); kns.repl(); ! throw new Exception("repl returned, uhoh!!"); } catch (Exception e) { e.printStackTrace(); --- 370,381 ---- KnownNodeServer kns = new KnownNodeServer(); new Thread(kns).start(); + /* success = kns.createReg(myPort); if (!success) throw new Exception("Could not create the registry!!"); success = kns.addMyself(); if (!success) throw new Exception("Could not add myself to the registry!!"); + */ kns.repl(); ! throw new RuntimeException("repl returned, uhoh!!"); } catch (Exception e) { e.printStackTrace(); |