From: Bryan T. <tho...@us...> - 2007-03-23 18:42:57
|
Update of /cvsroot/cweb/bigdata/src/test/com/bigdata/service In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv32506/src/test/com/bigdata/service Modified Files: ITestService.java TestServer.java TestServer.config Added Files: TestPersistentJiniService.java TestServerStarter.config Log Message: Working on service admin and service starter. --- NEW FILE: TestPersistentJiniService.java --- /** The Notice below must appear in each file of the Source Code of any copy you distribute of the Licensed Product. Contributors to any Modifications may add their own copyright notices to identify their own contributions. License: The contents of this file are subject to the CognitiveWeb Open Source License Version 1.1 (the License). You may not copy or use this file, in either source code or executable form, except in compliance with the License. You may obtain a copy of the License from http://www.CognitiveWeb.org/legal/license/ Software distributed under the License is distributed on an AS IS basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyrights: Portions created by or assigned to CognitiveWeb are Copyright (c) 2003-2003 CognitiveWeb. All Rights Reserved. Contact information for CognitiveWeb is available at http://www.CognitiveWeb.org Portions Copyright (c) 2002-2003 Bryan Thompson. Acknowledgements: Special thanks to the developers of the Jabber Open Source License 1.0 (JOSL), from which this License was derived. This License contains terms that differ from JOSL. Special thanks to the CognitiveWeb Open Source Contributors for their suggestions and support of the Cognitive Web. Modifications: */ /* * Created on Mar 23, 2007 */ package com.bigdata.service; import java.io.IOException; import net.jini.config.Configuration; import net.jini.config.ConfigurationException; import org.wonderly.jini2.PersistentJiniService; /** * @todo Work through an alternative to {@link TestServer} based on wonderly's * <code>startnow</code> JAR. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ public class TestPersistentJiniService extends PersistentJiniService { /** * @throws IOException * @throws ConfigurationException */ public TestPersistentJiniService() throws IOException, ConfigurationException { // TODO Auto-generated constructor stub } /** * @param arg0 * @throws IOException * @throws ConfigurationException */ public TestPersistentJiniService(Configuration arg0) throws IOException, ConfigurationException { super(arg0); // TODO Auto-generated constructor stub } /** * @param arg0 * @throws IOException * @throws ConfigurationException */ public TestPersistentJiniService(String[] arg0) throws IOException, ConfigurationException { super(arg0); // TODO Auto-generated constructor stub } } --- NEW FILE: TestServerStarter.config --- import java.io.File; import com.sun.jini.start.ServiceDescriptor; import com.sun.jini.start.NonActivatableServiceDescriptor; /* * Sample configuration for starting a service using the Jini ServiceStarter. * * Note: DO NOT include anything outside of com.sun.jini.start and the core * Java packages or you will get a ClassNotFoundException when the ServiceStarter * tries to resolve the imports! If you see this anyway, then add "jini-ext.jar" * to the classpath and it will resolve the ConfigurationException class and then * show you the stack trace so that you can figure out what is going on (I find * that it can help tremendously to have "jini-ext.jar" in the classpath when * working on this configuration - and can even appear to be necessary for the * server to start! * * @see http://java.sun.com/products/jini/2.0/doc/api/com/sun/jini/start/ServiceStarter.html */ com.sun.jini.start { /* * Code base for downloadable code exposed by this service. */ private static codebase = "http://proto.cognitiveweb.org/maven-repository/bigdata/jars/"; /* * @todo restrict the policy to what is actually required by the service. * Among other things, we only need access to a temporary directory and * to the directory in which the journals and index segments will be * stored, not general read/write on the disk. */ private static policy = "policy.all"; /* * The directory containing the various JARs. */ private static libdir = "lib"+File.separator; /* * Declare dependencies for the server here. */ private static classpath = // jini libdir+"jini-core.jar"+File.pathSeparator+ libdir+"jini-ext.jar"+File.pathSeparator+ libdir+"reggie.jar"+File.pathSeparator+ libdir+"sun-util.jar"+File.pathSeparator+ // utility JARs. libdir+"log4j-1.2.8.jar"+File.pathSeparator+ libdir+"ctc_utils-5-4-2005.jar"+File.pathSeparator+ libdir+"lgpl-utils-1.0-b1-dev.jar"+File.pathSeparator+ libdir+"cweb-extser-0.1-b2-dev.jar"+File.pathSeparator+ // ICU (unicode support). libdir+"icu4j-3_6.jar"+File.pathSeparator+ // test suites only! libdir+"junit-3.8.1.jar"+File.pathSeparator+ libdir+"cweb-junit-ext-1.1-b2-dev.jar"+File.pathSeparator+ // main bigdata JAR. //libdir+ "bigdata.jar" ; static serviceDescriptors = new ServiceDescriptor[] { new NonActivatableServiceDescriptor( codebase, policy, classpath, "com.bigdata.service.DataServer", new String[] { "src/test/com/bigdata/service/TestServer.config" }) }; } Index: TestServer.config =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/service/TestServer.config,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestServer.config 22 Mar 2007 21:11:24 -0000 1.1 --- TestServer.config 23 Mar 2007 18:42:47 -0000 1.2 *************** *** 1,3 **** ! import java.io.*; import net.jini.jeri.BasicILFactory; --- 1,3 ---- ! import java.io.File; import net.jini.jeri.BasicILFactory; *************** *** 5,10 **** import net.jini.jeri.tcp.TcpServerEndpoint; - import net.jini.core.discovery.LookupLocator; import net.jini.discovery.LookupDiscovery; import net.jini.core.entry.Entry; import net.jini.lookup.entry.Name; --- 5,10 ---- import net.jini.jeri.tcp.TcpServerEndpoint; import net.jini.discovery.LookupDiscovery; + import net.jini.core.discovery.LookupLocator; import net.jini.core.entry.Entry; import net.jini.lookup.entry.Name; *************** *** 14,23 **** import net.jini.lookup.entry.ServiceInfo; - import java.io.File; - import com.sun.jini.config.ConfigUtil; - - import com.sun.jini.start.ServiceDescriptor; - import com.sun.jini.start.NonActivatableServiceDescriptor; - /* * Declares how the service will provision itself. --- 14,17 ---- *************** *** 34,79 **** exporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(0), new BasicILFactory()); ! ! /* ! * Code base for downloadable code exposed by this service. ! */ ! private static codebase = ! "http://proto.cognitiveweb.org/maven-repository/bigdata/jars/"; ! ! /* @todo restrict the policy to what is actually required by the service. ! * Among other things, we only need access to a temporary directory and ! * to the directory in which the journals and index segments will be ! * stored, not general read/write on the disk. ! */ ! private static policy = "policy.all"; ! ! /* ! * The directory containing the various JARs. ! */ ! private static libdir = "ant-deploy"+File.separator; ! ! /* ! * Declare dependencies for the server here. ! */ ! private static classpath = ! // jini ! libdir+"reggie.jar"+File.pathSeparator+ ! libdir+"jini-core.jar"+File.pathSeparator+ ! libdir+"jini-ext.jar"+File.pathSeparator+ ! libdir+"sun-util.jar"+File.pathSeparator+ ! // utility JARs. ! libdir+"log4j-1.2.8.jar"+File.pathSeparator+ ! libdir+"ctc_utils-5-4-2005.jar"+File.pathSeparator+ ! libdir+"lgpl-utils-1.0-b1-dev.jar"+File.pathSeparator+ ! libdir+"cweb-extser-0.1-b2-dev.jar"+File.pathSeparator+ ! // ICU (unicode support). ! libdir+"icu4j-3_6.jar"+File.pathSeparator+ ! // test suites only! ! libdir+"junit-3.8.1.jar"+File.pathSeparator+ ! libdir+"cweb-junit-ext-1.1-b2-dev.jar"+File.pathSeparator+ ! // main bigdata JAR. ! libdir+"bigdata.jar" ! ; ! /* * The name of the property file containing the configuration information for --- 28,32 ---- exporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(0), new BasicILFactory()); ! /* * The name of the property file containing the configuration information for *************** *** 82,91 **** propertyFile = new File("src/test/com/bigdata/service/TestService.properties"); ! static serviceDescriptors = new ServiceDescriptor[] { ! new NonActivatableServiceDescriptor( ! codebase, policy, classpath, ! "config.FileClassifierServerConfig", ! new String[] { propertyFile}) ! }; } --- 35,42 ---- propertyFile = new File("src/test/com/bigdata/service/TestService.properties"); ! /* ! * The file on which the serviceID will be written. ! */ ! serviceIdFile = new File("TestService.id"); } *************** *** 131,138 **** }; - /* - * The file on which the serviceID will be written. - */ - serviceIdFile = new File("TestService.id"); - } --- 82,84 ---- Index: TestServer.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/service/TestServer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestServer.java 22 Mar 2007 21:11:24 -0000 1.1 --- TestServer.java 23 Mar 2007 18:42:47 -0000 1.2 *************** *** 56,62 **** --- 56,64 ---- import java.io.InputStream; import java.rmi.Remote; + import java.rmi.RemoteException; import java.rmi.server.ExportException; import java.util.Properties; + import net.jini.admin.Administrable; import net.jini.admin.JoinAdmin; import net.jini.config.Configuration; *************** *** 74,77 **** --- 76,80 ---- import net.jini.lease.LeaseRenewalEvent; import net.jini.lease.LeaseRenewalManager; + import net.jini.lookup.DiscoveryAdmin; import net.jini.lookup.JoinManager; import net.jini.lookup.ServiceIDListener; *************** *** 80,83 **** --- 83,88 ---- import com.bigdata.journal.Journal; + import com.sun.jini.admin.DestroyAdmin; + import com.sun.jini.admin.StorageLocationAdmin; import com.sun.jini.start.ServiceStarter; *************** *** 96,100 **** * * <pre> ! * java -Djava.security.policy=policy.all -classpath ant-deploy\reggie.jar;ant-deploy\jini-core.jar;ant-deploy\jini-ext.jar;ant-deploy\sun-util.jar;ant-deploy\bigdata.jar -jar ant-deploy\start.jar src\test\org\CognitiveWeb\bigdata\jini\TestServer.config * </pre> * --- 101,105 ---- * * <pre> ! * java -Djava.security.policy=policy.all -classpath ant-deploy\reggie.jar;ant-deploy\jini-core.jar;ant-deploy\jini-ext.jar;ant-deploy\sun-util.jar;ant-deploy\bigdata.jar -jar ant-deploy\start.jar src\test\org\CognitiveWeb\bigdata\jini\TestServer.config * </pre> * *************** *** 102,105 **** --- 107,123 ---- * transfer). Research how heavy mashalling is and what options exist to * make it faster and lighter. + * + * @todo Support JASS. + * + * @todo {@link JoinAdmin} is not actually implemented (it is declared as a work + * around for {@link DestroyAdmin} which otherwise crashes the Jini + * ServiceBrowser with a NPE when you try to destroy the service). + * Consider using Wonderly's <code>startNow</code> PersistentJiniService + * as a base rather than rolling our own. That might be more robust -- see + * {@link TestPersistentJiniService}. + * + * @todo consider {@link StorageLocationAdmin} + * + * @todo consider {@link DiscoveryAdmin} */ public class TestServer implements LeaseListener, ServiceIDListener *************** *** 116,120 **** private Exporter exporter; private ITestService proxy; ! private File serviceIdFile = null; /** --- 134,138 ---- private Exporter exporter; private ITestService proxy; ! protected File serviceIdFile = null; /** *************** *** 158,162 **** Entry[].class, null/* default */); ! serviceIdFile = (File) config.getEntry(ADVERT_LABEL, "serviceIdFile", File.class); // default --- 176,192 ---- Entry[].class, null/* default */); ! /* ! * Extract how the service will provision itself from the ! * Configuration. ! */ ! ! // use the configuration to construct an exporter ! exporter = (Exporter) config.getEntry(// ! SERVICE_LABEL, // component ! "exporter", // name ! Exporter.class // type (of the return object) ! ); ! ! serviceIdFile = (File) config.getEntry(SERVICE_LABEL, "serviceIdFile", File.class); // default *************** *** 183,198 **** /* - * Extract how the service will provision itself from the - * Configuration. - */ - - // use the configuration to construct an exporter - exporter = (Exporter) config.getEntry(// - SERVICE_LABEL, // component - "exporter", // name - Exporter.class // type (of the return object) - ); - - /* * Access the properties file used to configure the service. */ --- 213,216 ---- *************** *** 221,225 **** // create the service object. ! impl = new TestServiceImpl(properties); // export a proxy object for this service instance. --- 239,243 ---- // create the service object. ! impl = new TestServiceImpl(this,properties); // export a proxy object for this service instance. *************** *** 447,450 **** --- 465,480 ---- log.warn(ex); } + testServer.shutdownNow(); + // /* + // * Note: The reference to the service instance here forces a hard + // * reference to remain for the test server. If you comment out this log + // * statement, then you need to do something else to hold onto the hard + // * reference. + // */ + // log.info("Server will die: "+testServer); + } + + void shutdownNow() { + /* * Terminate manager threads. *************** *** 452,457 **** try { log.info("Terminating manager threads."); ! testServer.joinManager.terminate(); ! testServer.discoveryManager.terminate(); } catch (Exception ex) { log.error("Could not terminate: "+ex, ex); --- 482,487 ---- try { log.info("Terminating manager threads."); ! joinManager.terminate(); ! discoveryManager.terminate(); } catch (Exception ex) { log.error("Could not terminate: "+ex, ex); *************** *** 464,476 **** */ log.info("Unexporting the service proxy."); ! testServer.unexport(true); - // /* - // * Note: The reference to the service instance here forces a hard - // * reference to remain for the test server. If you comment out this log - // * statement, then you need to do something else to hold onto the hard - // * reference. - // */ - // log.info("Server will die: "+testServer); } --- 494,499 ---- */ log.info("Unexporting the service proxy."); ! unexport(true); } *************** *** 564,569 **** * </a> */ ! public static class TestServiceImpl implements ITestService { /** --- 587,601 ---- * </a> */ ! public static class TestServiceImpl implements ITestService, RemoteAdministrable, RemoteDestroyAdmin, RemoteJoinAdmin { + + private TestServer server; + private Journal journal; + + public Journal getJournal() { + + return journal; + + } /** *************** *** 572,580 **** * @param properties */ ! public TestServiceImpl(Properties properties) { log.info("Created: " + this ); ! new Journal(properties); } --- 604,614 ---- * @param properties */ ! public TestServiceImpl(TestServer server,Properties properties) { log.info("Created: " + this ); ! journal = new Journal(properties); ! ! this.server = server; } *************** *** 586,589 **** --- 620,805 ---- } + public Object getAdmin() throws RemoteException { + + log.info(""); + + return server.proxy; + + } + + /* + * DestroyAdmin + */ + + /** + * Destroy the service (including its persistent state). + * + * @throws RemoteException + */ + public void destroy() throws RemoteException { + + log.info(""); + + boolean destroyEnabled = true; + + if (destroyEnabled) { + + new Thread() { + + public void run() { + + server.shutdownNow(); + + try { + + getJournal().closeAndDelete(); + + log.info("Journal deleted."); + + } catch (Throwable t) { + + log.warn("Could not delete persistent state: " + t, + t); + + } + + if (!server.serviceIdFile.delete()) { + + log.warn("Could not delete file: " + + server.serviceIdFile); + + } + + try { + Thread.sleep(3); + } catch (InterruptedException ex) { + } + + log.info("Service Stop requested"); + + System.exit(1); + + } + + }.start(); + } else { + throw new RemoteException( + "Service Destroy Not Enabled, Operation Ignored"); + } + + } + + /* + * JoinAdmin + */ + + public void addLookupAttributes(Entry[] arg0) throws RemoteException { + + log.info(""); + + // TODO Auto-generated method stub + + } + + public void addLookupGroups(String[] arg0) throws RemoteException { + + log.info(""); + + // TODO Auto-generated method stub + + } + + public void addLookupLocators(LookupLocator[] arg0) throws RemoteException { + + log.info(""); + + // TODO Auto-generated method stub + + } + + public Entry[] getLookupAttributes() throws RemoteException { + + log.info(""); + + // TODO Auto-generated method stub + return null; + } + + public String[] getLookupGroups() throws RemoteException { + + log.info(""); + + // TODO Auto-generated method stub + return null; + } + + public LookupLocator[] getLookupLocators() throws RemoteException { + + log.info(""); + + // TODO Auto-generated method stub + return null; + } + + public void modifyLookupAttributes(Entry[] arg0, Entry[] arg1) throws RemoteException { + + log.info(""); + + // TODO Auto-generated method stub + + } + + public void removeLookupGroups(String[] arg0) throws RemoteException { + log.info(""); + + // TODO Auto-generated method stub + + } + + public void removeLookupLocators(LookupLocator[] arg0) throws RemoteException { + log.info(""); + + // TODO Auto-generated method stub + + } + + public void setLookupGroups(String[] arg0) throws RemoteException { + log.info(""); + + // TODO Auto-generated method stub + + } + + public void setLookupLocators(LookupLocator[] arg0) throws RemoteException { + log.info(""); + + // TODO Auto-generated method stub + + } + + } + + /* + * Note: You need to extend Remote in order for these APIs to be exported! + */ + + public static interface RemoteAdministrable extends Remote, Administrable { + + } + + public static interface RemoteDestroyAdmin extends Remote, DestroyAdmin { + + } + + public static interface RemoteJoinAdmin extends Remote, JoinAdmin { + + } + + public static interface RemoteDiscoveryAdmin extends Remote, DiscoveryAdmin { + + } + + public static interface RemoteStorageLocationAdmin extends Remote, StorageLocationAdmin { + } Index: ITestService.java =================================================================== RCS file: /cvsroot/cweb/bigdata/src/test/com/bigdata/service/ITestService.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ITestService.java 22 Mar 2007 21:11:24 -0000 1.1 --- ITestService.java 23 Mar 2007 18:42:47 -0000 1.2 *************** *** 52,55 **** --- 52,59 ---- import java.rmi.RemoteException; + import com.sun.jini.admin.DestroyAdmin; + + import net.jini.admin.Administrable; + /** * The public interface for a test service. *************** *** 65,69 **** * @download */ ! public interface ITestService extends Remote { --- 69,73 ---- * @download */ ! public interface ITestService extends Remote { |