Author: gtrasuk Date: Wed Sep 14 04:20:03 2011 New Revision: 1170432 URL: http://svn.apache.org/viewvc?rev=1170432&view=rev Log: Continuing work on the surrogate classloading and container startup code.
Modified: river/jtsk/skunk/surrogate/build.xml river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java river/jtsk/skunk/surrogate/test/org/apache/river/container/CommonsVFSTest.java Modified: river/jtsk/skunk/surrogate/build.xml URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/build.xml?rev=1170432&r1=1170431&r2=1170432&view=diff ============================================================================== --- river/jtsk/skunk/surrogate/build.xml (original) +++ river/jtsk/skunk/surrogate/build.xml Wed Sep 14 04:20:03 2011 @@ -159,7 +159,7 @@ </xjc> </target> - <target name="-post-jar"> + <target name="-post-jar" depends="-build-reggie-module"> <antcall target="-build-testroot" inheritall="true"/> </target> @@ -179,6 +179,10 @@ <include name="RiverSurrogate.jar"/> </fileset> </copy> + <mkdir dir="${build.testroot}/profile/default/deploy"/> + <copy todir="${build.testroot}/profile/default/deploy"> + <fileset dir="${basedir}/build/test/files" includes="reggie-module.ssar"/> + </copy> </target> </project> Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java?rev=1170432&r1=1170431&r2=1170432&view=diff ============================================================================== --- river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java (original) +++ river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java Wed Sep 14 04:20:03 2011 @@ -118,14 +118,18 @@ public class AnnotatedClassDeployer impl */ private boolean initializeIfFullyResolved(DeployedObject deployed) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (deployed.getUnresolvedDependencies().isEmpty()) { - uninitializedObjects.remove(deployed); - for (Method initMethod : deployed.getInitMethods()) { - initMethod.invoke(deployed.getDeployedObject()); - } - notifyDeploymentListeners(deployed); - initializedObjects.put(deployed.getName(), deployed); - if (deployed.getDeployedObject() instanceof DeploymentListener) { - deploymentListeners.add((DeploymentListener) deployed.getDeployedObject()); + if (deployed.isInitialized() == false) { + + uninitializedObjects.remove(deployed); + for (Method initMethod : deployed.getInitMethods()) { + initMethod.invoke(deployed.getDeployedObject()); + } + notifyDeploymentListeners(deployed); + initializedObjects.put(deployed.getName(), deployed); + if (deployed.getDeployedObject() instanceof DeploymentListener) { + deploymentListeners.add((DeploymentListener) deployed.getDeployedObject()); + } + deployed.setInitialized(true); } return true; } @@ -249,7 +253,7 @@ public class AnnotatedClassDeployer impl } /** Build a list of members that might be candidates for injection. - + @param cls @return @throws SecurityException @@ -383,7 +387,7 @@ public class AnnotatedClassDeployer impl unresolved dependencies for this object. If there are no further unresolved dependencies, call the object's init method and move it into the initialized objects group. - + @param deployed The holder for the deployment unit. @param m The member (either Field or Method that is used to set the value. @param val The value to set. Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java?rev=1170432&r1=1170431&r2=1170432&view=diff ============================================================================== --- river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java (original) +++ river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java Wed Sep 14 04:20:03 2011 @@ -33,7 +33,16 @@ public class DeployedObject { private String name; private List<Member> unresolvedDependencies=new ArrayList<Member>(); private List<Method> initMethods=new ArrayList<Method>(); + private boolean initialized=false; + public boolean isInitialized() { + return initialized; + } + + public void setInitialized(boolean isInitialized) { + this.initialized = isInitialized; + } + public List<Method> getInitMethods() { return initMethods; } Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java?rev=1170432&r1=1170431&r2=1170432&view=diff ============================================================================== --- river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java (original) +++ river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java Wed Sep 14 04:20:03 2011 @@ -31,6 +31,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSelector; +import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileType; import org.apache.river.container.classloading.VirtualFileSystemClassLoader; import org.apache.river.container.codebase.CodebaseContext; @@ -65,6 +66,54 @@ public class StarterServiceDeployer { @Injected private ArgsParser argsParser = null; + public void addPlatformCodebaseJars(CodebaseContext codebaseContext) throws IOException { + /* Register the platform codebase jars with the codebase service. */ + String platformCodebaseSpec = configProperties.getProperty(Strings.PLATFORM_CODEBASE); + String[] codebaseJars = Utils.splitOnWhitespace(platformCodebaseSpec); + for (String codebaseJar : codebaseJars) { + FileObject fo = fileUtility.getLibDirectory().resolveFile(codebaseJar); + codebaseContext.addFile(fo); + } + } + + public String[] constructArgs(String argLine) { + String[] args = null; + if (argLine == null) { + args = new String[0]; + } else { + args = argsParser.toArgs(argLine); + } + return args; + } + + public VirtualFileSystemClassLoader createServiceClassloader(FileObject serviceRoot) throws IOException, FileSystemException { + /* Create the service classloader. */ + VirtualFileSystemClassLoader cl = + new VirtualFileSystemClassLoader(null, systemClassLoader); + /* Include platform jars from the container's lib directory. */ + String platformJarSpec = configProperties.getProperty(Strings.PLATFORM_JARS); + log.log(Level.FINE, MessageNames.ADDING_CLASSPATH_ENTRY, new Object[]{platformJarSpec}); + cl.addClassPathEntry(fileUtility.getLibDirectory(), platformJarSpec); + /* Add the jar files from the service's 'lib' directory. */ + FileObject libDir = serviceRoot.resolveFile(Strings.LIB); + List<FileObject> jarFiles = Utils.findChildrenWithSuffix(libDir, + Strings.DOT_JAR); + for (FileObject jarFile : jarFiles) { + cl.addClassPathEntry(libDir, jarFile.getName().getBaseName()); + } + return cl; + } + + public void exportServiceCodebaseJars(FileObject serviceRoot, CodebaseContext codebaseContext) throws FileSystemException { + /* Register the service's codebase jars with the codebase service. */ + FileObject libDlDir = serviceRoot.resolveFile(Strings.LIB_DL); + List<FileObject> dljarFiles = Utils.findChildrenWithSuffix(libDlDir, + Strings.DOT_JAR); + for (FileObject jarFile : dljarFiles) { + codebaseContext.addFile(jarFile); + } + } + @Init public void init() { try { @@ -79,6 +128,49 @@ public class StarterServiceDeployer { } } + public void launchService(Properties startProps, String[] args) { + String startClassName = startProps.getProperty(Strings.START_CLASS); + /* Launch the service. */ + log.log(Level.FINE, MessageNames.CALLING_MAIN, new Object[] { + startClassName, Utils.format(args) + }); + + } + + public Properties readStartProperties(FileObject serviceRoot) throws FileSystemException, LocalizedRuntimeException, IOException { + /* Read the start.properties file. */ + FileObject startProperties = serviceRoot.resolveFile(Strings.START_PROPERTIES); + if (startProperties == null || !startProperties.getType().equals(FileType.FILE) + || !startProperties.isReadable()) { + throw new LocalizedRuntimeException(MessageNames.BUNDLE_NAME, + MessageNames.CANT_READ_START_PROPERTIES, + new Object[]{Strings.START_PROPERTIES, + serviceRoot.getName().getBaseName()}); + } + Properties startProps = propertiesFileReader.getProperties(startProperties); + return startProps; + } + + public void setupLiaisonConfiguration(FileObject serviceArchive, FileObject serviceRoot, VirtualFileSystemClassLoader cl) throws ConfigurationException { + /* Setup the liaison configuration. */ + try { + File workingDir = null; + if (serviceArchive != null) { + workingDir = new File(serviceArchive.getURL().toURI()); + } else { + workingDir = new File(serviceRoot.getURL().toURI()); + + } + invokeStatic(cl, VirtualFileSystemConfiguration.class.getName(), + Strings.SET_WORKING_DIRECTORY, + workingDir); + } catch (Exception ex) { + log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, ex); + throw new ConfigurationException(ex, + MessageNames.STARTER_SERVICE_DEPLOYER_FAILED_INIT); + } + } + private void tryInitialize() throws IOException { log.log(Level.FINE, MessageNames.STARTER_SERVICE_DEPLOYER_STARTING, myName); /* Establish the deployment directory. */ @@ -142,85 +234,23 @@ public class StarterServiceDeployer { } private void deployService(FileObject serviceArchive, FileObject serviceRoot) throws IOException { String serviceName=findServiceName(serviceArchive, serviceRoot); - /* Create the service classloader. */ - VirtualFileSystemClassLoader cl = - new VirtualFileSystemClassLoader(null, systemClassLoader); - /* Include platform jars from the container's lib directory. */ - String platformJarSpec = configProperties.getProperty(Strings.PLATFORM_JARS); - log.log(Level.FINE, MessageNames.ADDING_CLASSPATH_ENTRY, new Object[]{platformJarSpec}); - cl.addClassPathEntry(fileUtility.getLibDirectory(), platformJarSpec); - - /* Add the jar files from the service's 'lib' directory. */ - FileObject libDir = serviceRoot.resolveFile(Strings.LIB); - List<FileObject> jarFiles = Utils.findChildrenWithSuffix(libDir, - Strings.DOT_JAR); - for (FileObject jarFile : jarFiles) { - cl.addClassPathEntry(libDir, jarFile.getName().getBaseName()); - } + VirtualFileSystemClassLoader cl = createServiceClassloader(serviceRoot); /* Create a codebase context. */ CodebaseContext codebaseContext = codebaseHandler.createContext(); - - /* Register the platform codebase jars with the codebase service. */ - String platformCodebaseSpec = configProperties.getProperty(Strings.PLATFORM_CODEBASE); - String[] codebaseJars = Utils.splitOnWhitespace(platformCodebaseSpec); - for (String codebaseJar : codebaseJars) { - FileObject fo = fileUtility.getLibDirectory().resolveFile(codebaseJar); - codebaseContext.addFile(fo); - } - - /* Register the service's codebase jars with the codebase service. */ - FileObject libDlDir = serviceRoot.resolveFile(Strings.LIB_DL); - List<FileObject> dljarFiles = Utils.findChildrenWithSuffix(libDlDir, - Strings.DOT_JAR); - for (FileObject jarFile : dljarFiles) { - codebaseContext.addFile(jarFile); - } + addPlatformCodebaseJars(codebaseContext); + exportServiceCodebaseJars(serviceRoot, codebaseContext); /* Setup the classloader's codebase annotation. */ cl.setCodebase(codebaseContext.getCodebaseAnnotation()); /* Grant the appropriate permissions to the service's classloader and protection domain. */ // TODO: Figure out how the protection domains, codesources, etc need to work. - - /* Setup the liaison configuration. */ - try { - File workingDir = null; - if (serviceArchive != null) { - workingDir = new File(serviceArchive.getURL().toURI()); - } else { - workingDir = new File(serviceRoot.getURL().toURI()); - - } - invokeStatic(cl, VirtualFileSystemConfiguration.class.getName(), - Strings.SET_WORKING_DIRECTORY, - workingDir); - } catch (Exception ex) { - log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, ex); - throw new ConfigurationException(ex, - MessageNames.STARTER_SERVICE_DEPLOYER_FAILED_INIT); - } - /* Read the start.properties file. */ - FileObject startProperties = serviceRoot.resolveFile(Strings.START_PROPERTIES); - if (startProperties == null || !startProperties.getType().equals(FileType.FILE) - || !startProperties.isReadable()) { - throw new LocalizedRuntimeException(MessageNames.BUNDLE_NAME, - MessageNames.CANT_READ_START_PROPERTIES, - new Object[]{Strings.START_PROPERTIES, - serviceRoot.getName().getBaseName()}); - } - Properties startProps = propertiesFileReader.getProperties(startProperties); + setupLiaisonConfiguration(serviceArchive, serviceRoot, cl); + Properties startProps = readStartProperties(serviceRoot); String argLine = startProps.getProperty(Strings.START_PARAMETERS); - String[] args = null; - if (argLine == null) { - args = new String[0]; - } else { - args = argsParser.toArgs(argLine); - } - String startClassName = startProps.getProperty(Strings.START_CLASS); - /* Launch the service. */ - log.log(Level.FINE, MessageNames.CALLING_MAIN, new Object[] { - startClassName, Utils.format(args) - }); + String[] args = constructArgs(argLine); + + launchService(startProps, args); // TODO: Call the main class/method. log.log(Level.INFO, MessageNames.COMPLETED_SERVICE_DEPLOYMENT, serviceName); } Modified: river/jtsk/skunk/surrogate/test/org/apache/river/container/CommonsVFSTest.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/test/org/apache/river/container/CommonsVFSTest.java?rev=1170432&r1=1170431&r2=1170432&view=diff ============================================================================== --- river/jtsk/skunk/surrogate/test/org/apache/river/container/CommonsVFSTest.java (original) +++ river/jtsk/skunk/surrogate/test/org/apache/river/container/CommonsVFSTest.java Wed Sep 14 04:20:03 2011 @@ -94,9 +94,9 @@ public class CommonsVFSTest { @Test public void testFileInReggieModuleJar() throws Exception { FileObject reggieJar = - fileSystemManager.resolveFile(new File("../../build/test/files"), "reggie-module.jar"); - assertTrue("Bad file:" + reggieJar.toString(), reggieJar.toString().endsWith("reggie-module.jar")); - FileObject reggieJarFS = fileSystemManager.createFileSystem(reggieJar); + fileSystemManager.resolveFile(new File("../../build/test/files"), "reggie-module.ssar"); + assertTrue("Bad file:" + reggieJar.toString(), reggieJar.toString().endsWith("reggie-module.ssar")); + FileObject reggieJarFS = fileSystemManager.createFileSystem(Strings.JAR, reggieJar); FileObject startProperties = reggieJarFS.resolveFile("start.properties"); assertNotNull(startProperties);