river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtra...@apache.org
Subject svn commit: r1484221 - in /river/jtsk/skunk/surrogate: nbproject/ src/org/apache/river/container/ src/org/apache/river/container/deployer/ src/org/apache/river/container/hsm/ src/org/apache/river/container/security/ src/org/apache/river/container/work/...
Date Sun, 19 May 2013 05:06:06 GMT
Author: gtrasuk
Date: Sun May 19 05:06:05 2013
New Revision: 1484221

URL: http://svn.apache.org/r1484221
Log:
Can start the reggie module.  Monitoring JMX MBeans through jconsole works.  Need to continue
work on service lifecycle state machine to include shutdown.

Restructured and added StartupDeployer to handle startup-time launching of services in the
deploy dir.  This functionality used to be in StarterServiceDeployer, but trying to make that
more stand-alone for simplicity.

Added:
    river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ServiceLifeCycle.java
      - copied, changed from r1482317, river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycle.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StartupDeployer.java
Removed:
    river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycle.java
Modified:
    river/jtsk/skunk/surrogate/nbproject/build-impl.xml
    river/jtsk/skunk/surrogate/nbproject/genfiles.properties
    river/jtsk/skunk/surrogate/nbproject/project.properties
    river/jtsk/skunk/surrogate/src/org/apache/river/container/MBeanRegistrar.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
    river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ApplicationEnvironment.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployer.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycleSM.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StatusEvents.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/hsm/PlainStateMachineExecutor.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/work/BasicWorkManager.java
    river/jtsk/skunk/surrogate/test/org/apache/river/container/hsm/InitializedMachineTest.java
    river/jtsk/skunk/surrogate/testfiles/testroot/profile/default/config.xml

Modified: river/jtsk/skunk/surrogate/nbproject/build-impl.xml
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/nbproject/build-impl.xml?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/nbproject/build-impl.xml (original)
+++ river/jtsk/skunk/surrogate/nbproject/build-impl.xml Sun May 19 05:06:05 2013
@@ -54,6 +54,7 @@ is divided into following sections:
         <property file="nbproject/project.properties"/>
     </target>
     <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property"
name="-do-init">
+        <property name="platform.java" value="${java.home}/bin/java"/>
         <available file="${manifest.file}" property="manifest.available"/>
         <condition property="splashscreen.available">
             <and>
@@ -434,7 +435,7 @@ is divided into following sections:
                     </fileset>
                 </union>
                 <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}"
name="testng"/>
-                <testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}"
mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="RiverSurrogate" testname="TestNG
tests" workingDir="${work.dir}">
+                <testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter"
methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}"
suitename="RiverSurrogate" testname="TestNG tests" workingDir="${work.dir}">
                     <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
                     <propertyset>
                         <propertyref prefix="test-sys-prop."/>

Modified: river/jtsk/skunk/surrogate/nbproject/genfiles.properties
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/nbproject/genfiles.properties?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/nbproject/genfiles.properties (original)
+++ river/jtsk/skunk/surrogate/nbproject/genfiles.properties Sun May 19 05:06:05 2013
@@ -4,8 +4,8 @@ build.xml.stylesheet.CRC32=28e38971@1.38
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files
for you.
 nbproject/build-impl.xml.data.CRC32=8f1c53be
-nbproject/build-impl.xml.script.CRC32=5baae9fa
-nbproject/build-impl.xml.stylesheet.CRC32=c4a38350@1.60.0.46
+nbproject/build-impl.xml.script.CRC32=4f16d38a
+nbproject/build-impl.xml.stylesheet.CRC32=4e931b40@1.63.0.46
 nbproject/management-build-impl.xml.data.CRC32=318d2fde
 nbproject/management-build-impl.xml.script.CRC32=630dcf8f
 nbproject/management-build-impl.xml.stylesheet.CRC32=545273be@1.1

Modified: river/jtsk/skunk/surrogate/nbproject/project.properties
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/nbproject/project.properties?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/nbproject/project.properties (original)
+++ river/jtsk/skunk/surrogate/nbproject/project.properties Sun May 19 05:06:05 2013
@@ -90,7 +90,7 @@ run.classpath=\
 # Space-separated list of JVM arguments used when running the project
 # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
 # or test-sys-prop.name=value to set system properties for unit tests):
-run.jvmargs=-classpath lib/RiverSurrogate.jar -Djava.util.logging.config.file=../../testfiles/logging.properties
+run.jvmargs=-classpath lib/RiverSurrogate.jar -Djava.util.logging.config.file=../../testfiles/logging.properties
-Dcom.sun.management.jmxremote
 run.test.classpath=\
     ${javac.test.classpath}:\
     ${build.test.classes.dir}

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/MBeanRegistrar.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/MBeanRegistrar.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/MBeanRegistrar.java (original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/MBeanRegistrar.java Sun May
19 05:06:05 2013
@@ -30,6 +30,10 @@ public class MBeanRegistrar implements D
 
     private MBeanServer mbeanServer=null;
 
+    public MBeanServer getMbeanServer() {
+        return mbeanServer;
+    }
+
     public void postInit(String name, Object object) {
         try {
             /*

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java (original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java Sun May 19
05:06:05 2013
@@ -100,6 +100,7 @@ public class MessageNames {
             READING_OBJECT_MEMBER_COUNT="readingObject.memberCount",
             READING_OBJECT_ANNOTATED_MEMBER_FOUND="readingObject.annotatedMemberFound",
             READING_OBJECT_NON_ANNOTATED_MEMBER_FOUND="readingObject.nonAnnotatedMemberFound",
+            RECEIVED_START="receivedStart",
             SECURITY_INIT_FAILED="securityInitializationFailed",
             SECURITY_INIT_SUCCEEDED="securityInitializationSucceeded",
             SECURITY_INIT_WRONG_POLICY="securityInitializationWrongPolicy",
@@ -110,6 +111,9 @@ public class MessageNames {
             STARTER_SERVICE_DEPLOYER_FAILED_INIT="starterServiceDeployerFailedInit",
             STARTER_SERVICE_DEPLOYER_INITIALIZED="starterServiceDeployerInitialized",
             STARTER_SERVICE_DEPLOYER_STARTING="starterServiceDeployerStarting",
+            STARTUP_DEPLOYER_FAILED_INIT="startupDeployerFailedInit",
+            STARTUP_DEPLOYER_INITIALIZED="startupDeployerInitialized",
+            STARTUP_DEPLOYER_STARTING="startupDeployerStarting",
             SYSTEM_CLASSLOADER_IS="systemClassLoaderIs",
             UNRESOLVED_DEPENDENCY="unresolvedDependency",
             UNSUPPORTED_ELEMENT="unsupportedElement";

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties (original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties Sun May
19 05:06:05 2013
@@ -85,6 +85,7 @@ readingObject=Reading instance of {1} na
 readingObject.memberCount={0} members found.
 readingObject.annotatedMemberFound=Member ''{0}'' is annotated @Injected.
 readingObject.nonAnnotatedMemberFound=Member ''{0}'' is not annotated @Injected.
+receivedStart=Received start event while in state {0}.
 securityInitializationFailed=Failed to initialize security subsystem.
 securityInitializationSucceeded=Security Manager and Dynamic Policy successfully installed.
           
 securityInitializationWrongPolicy=After security manager setup, the wrong policy is installed:
{0}.
@@ -99,6 +100,11 @@ starterServiceDeployerInitialized=Starte
 initialization.
 starterServiceDeployerStarting=Starter-Service deployer named ''{0}'' is being \
 initialized.
+startupDeployerFailedInit=Starter-Service deployer has failed to initialize.
+startupDeployerInitialized=Starter-Service deployer named ''{0}'' completed \
+initialization.
+startupDeployerStarting=Starter-Service deployer named ''{0}'' is being \
+initialized.
 systemClassLoaderIs=System classloader is ''{0}'' with classpath {1}.
 unresolvedDependency=Object {0} has an unresolved dependent member ''{1}'' \
 (name=''{2}'').

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ApplicationEnvironment.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ApplicationEnvironment.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ApplicationEnvironment.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ApplicationEnvironment.java
Sun May 19 05:06:05 2013
@@ -31,16 +31,6 @@ public class ApplicationEnvironment {
 
     String serviceName=null;
 
-    public StarterServiceLifeCycle getLifeCycle() {
-        return lifeCycle;
-    }
-
-    public void setLifeCycle(StarterServiceLifeCycle lifeCycle) {
-        this.lifeCycle = lifeCycle;
-    }
-    
-    StarterServiceLifeCycle lifeCycle=null;
-    
     public String getServiceName() {
         return serviceName;
     }
@@ -83,4 +73,15 @@ public class ApplicationEnvironment {
     public void setCodebaseContext(CodebaseContext codebaseContext) {
         this.codebaseContext = codebaseContext;
     }
+    
+    Object serviceInstance = null;
+
+    public Object getServiceInstance() {
+        return serviceInstance;
+    }
+
+    public void setServiceInstance(Object serviceInstance) {
+        this.serviceInstance = serviceInstance;
+    }
+    
 }

Copied: river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ServiceLifeCycle.java
(from r1482317, river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycle.java)
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ServiceLifeCycle.java?p2=river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ServiceLifeCycle.java&p1=river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycle.java&r1=1482317&r2=1484221&rev=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycle.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/ServiceLifeCycle.java
Sun May 19 05:06:05 2013
@@ -17,11 +17,16 @@
  */
 package org.apache.river.container.deployer;
 
+import javax.management.MXBean;
+
 /**
  * Life cycle state controller interface for a Starter Service application.
  * @author trasukg
  */
-public interface StarterServiceLifeCycle {
+@MXBean
+public interface ServiceLifeCycle {
+    public String getName();
+    
     public void start();
     
     public void stop();
@@ -29,4 +34,5 @@ public interface StarterServiceLifeCycle
     public void prepare();
     
     public String getStatus();
+    
 }

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployer.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployer.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployer.java
Sun May 19 05:06:05 2013
@@ -65,8 +65,8 @@ import org.apache.river.container.work.T
 import org.apache.river.container.work.WorkManager;
 
 /**
-
- @author trasukg
+ * Deployer that instantiates applications or services based on the
+ * com.sun.jini.starter API
  */
 public class StarterServiceDeployer implements StarterServiceDeployerMXBean {
 
@@ -80,19 +80,9 @@ public class StarterServiceDeployer impl
     private String myName = null;
     @Injected(style = InjectionStyle.BY_TYPE)
     private CodebaseHandler codebaseHandler = null;
-    private String deployDirectory = Strings.DEFAULT_DEPLOY_DIRECTORY;
+    
     private String config = Strings.STARTER_SERVICE_DEPLOYER_CONFIG;
     private ASTconfig configNode = null;
-    private List<ApplicationEnvironment> applicationEnvironments =
-            new ArrayList<ApplicationEnvironment>();
-
-    public String getDeployDirectory() {
-        return deployDirectory;
-    }
-
-    public void setDeployDirectory(String deployDirectory) {
-        this.deployDirectory = deployDirectory;
-    }
 
     public String getConfig() {
         return config;
@@ -101,13 +91,15 @@ public class StarterServiceDeployer impl
     public void setConfig(String config) {
         this.config = config;
     }
-    private FileObject deploymentDirectoryFile = null;
     @Injected(style = InjectionStyle.BY_TYPE)
     private PropertiesFileReader propertiesFileReader = null;
+    
     @Injected(style = InjectionStyle.BY_TYPE)
     private ArgsParser argsParser = null;
+    
     @Injected(style = InjectionStyle.BY_TYPE)
     WorkManager workManager = null;
+    
     @Injected(style = InjectionStyle.BY_TYPE)
     private DynamicPolicyProvider securityPolicy = null;
 
@@ -209,7 +201,7 @@ public class StarterServiceDeployer impl
         }
     }
 
-    public void launchService(final ClassLoader cl, Properties startProps, final String[]
args) {
+    public void launchService(final ApplicationEnvironment env, Properties startProps, final
String[] args) {
         final String startClassName = startProps.getProperty(Strings.START_CLASS);
         /*
          Launch the service.
@@ -222,15 +214,25 @@ public class StarterServiceDeployer impl
             @Override
             public void run() {
                 try {
-                    instantiateService(cl, startClassName, args);
+                    env.setServiceInstance(instantiateService(env.getClassLoader(), startClassName,
args));
                 } catch (Exception ex) {
                     throw new RuntimeException(ex);
                 }
             }
         };
-        workManager.queueTask(TaskClass.APPLICATION_TASK, cl, task);
+        workManager.queueTask(TaskClass.APPLICATION_TASK, env.getClassLoader(), task);
     }
 
+    public void stopService(ApplicationEnvironment env) {
+        /*
+         * TODO: Write the implementation of this method.
+         * Should do something like:
+         *  - Call destroy() on the service proxy if possible.
+         *  - Check to make sure all the threads are gone.
+         *  - Interrupt the threads if necessary.
+         */
+    }
+    
     public Properties readStartProperties(FileObject serviceRoot) throws FileSystemException,
LocalizedRuntimeException, IOException {
         /*
          Read the start.properties file.
@@ -286,7 +288,7 @@ public class StarterServiceDeployer impl
                 } 
             }
         } catch (Exception ex) {
-            log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, ex);
+            log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, Utils.stackTrace(ex));
             throw new ConfigurationException(ex,
                     MessageNames.STARTER_SERVICE_DEPLOYER_FAILED_INIT);
         }
@@ -295,68 +297,26 @@ public class StarterServiceDeployer impl
     private void tryInitialize() throws IOException, ParseException {
         log.log(Level.FINE, MessageNames.STARTER_SERVICE_DEPLOYER_STARTING, myName);
         /*
-         Establish the deployment directory.
-         */
-        deploymentDirectoryFile = fileUtility.getProfileDirectory().resolveFile(deployDirectory);
-        if (deploymentDirectoryFile == null
-                || deploymentDirectoryFile.getType() != FileType.FOLDER) {
-            log.log(Level.WARNING, MessageNames.NO_DEPLOYMENT_DIRECTORY,
-                    new Object[]{deployDirectory, fileUtility.getProfileDirectory()});
-        }
-        /*
          Read and parse the configuration file.
          */
 
         FileObject configFile = fileUtility.getProfileDirectory().resolveFile(config);
         InputStream in = configFile.getContent().getInputStream();
         configNode = DeployerConfigParser.parseConfig(in);
-
-        /*
-         Go through the deployment directory looking for services to deploy.
-         */
-        List<FileObject> serviceArchives =
-                Utils.findChildrenWithSuffix(deploymentDirectoryFile,
-                Strings.SSAR);
-        if (serviceArchives != null) {
-            log.log(Level.FINE, MessageNames.FOUND_SERVICE_ARCHIVES,
-                    new Object[]{serviceArchives.size(), deployDirectory});
-            deployServiceArchives(serviceArchives);
-        } else {
-            log.log(Level.WARNING, MessageNames.FOUND_NO_SERVICE_ARCHIVES,
-                    new Object[]{deployDirectory});
-
-        }
-
-        establishLiveDeploymentMonitoring();
-        log.log(Level.INFO, MessageNames.STARTER_SERVICE_DEPLOYER_INITIALIZED, myName);
-
-    }
-
-    private void deployServiceArchives(List<FileObject> serviceArchives) {
-        /*
-         Deploy those services.
-         */
-        for (FileObject archiveFile : serviceArchives) {
-            try {
-                deployServiceArchive(archiveFile);
-            } catch (Throwable t) {
-                log.log(Level.WARNING, MessageNames.FAILED_DEPLOY_SERVICE, archiveFile.toString());
-                log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, Utils.stackTrace(t));
-            }
-        }
+        log.log(Level.FINE,MessageNames.STARTER_SERVICE_DEPLOYER_INITIALIZED, 
+                new Object[] {myName} );
     }
 
-    private void deployServiceArchive(FileObject serviceArchive) throws IOException, ClassNotFoundException,
NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
InstantiationException {
+    public ServiceLifeCycle deployServiceArchive(FileObject serviceArchive) throws IOException,
ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, InstantiationException {
         // Create an application environment
         ApplicationEnvironment env = new ApplicationEnvironment();
         env.setServiceArchive(serviceArchive);
         env.setServiceRoot(
                 serviceArchive.getFileSystem().getFileSystemManager().createFileSystem(Strings.JAR,
serviceArchive));
-        env.setLifeCycle(StarterServiceLifeCycleSM.newStarterServiceLifeCycle(env, this));
-        // Store it in our list of environments.
-        applicationEnvironments.add(env);
-        // Deploy it.
-        env.getLifeCycle().start();
+        String serviceName = findServiceName(env.getServiceArchive(), env.getServiceRoot());
+        env.setServiceName(serviceName);
+        ServiceLifeCycle slc=StarterServiceLifeCycleSM.newStarterServiceLifeCycle(env, this);
+        return slc;
     }
 
     private String findServiceName(FileObject serviceArchive, FileObject serviceRoot) {
@@ -374,13 +334,12 @@ public class StarterServiceDeployer impl
     }
 
     void prepareService(ApplicationEnvironment env) throws IOException, ClassNotFoundException,
NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
InstantiationException {
-        String serviceName = findServiceName(env.getServiceArchive(), env.getServiceRoot());
-        env.setServiceName(serviceName);
+        
         CodeSource serviceCodeSource =
                 new CodeSource(findServiceURL(env.getServiceArchive(), env.getServiceRoot()),
                 new Certificate[0]);
         log.log(Level.INFO, MessageNames.CODESOURCE_IS,
-                new Object[]{serviceName, serviceCodeSource});
+                new Object[]{env.getServiceName(), serviceCodeSource});
         VirtualFileSystemClassLoader cl = createServiceClassloader(env.getServiceRoot(),
serviceCodeSource);
         env.setClassLoader(cl);
         
@@ -388,7 +347,7 @@ public class StarterServiceDeployer impl
          Create a codebase context.
          */
         CodebaseContext codebaseContext =
-                codebaseHandler.createContext(serviceName);
+                codebaseHandler.createContext(env.getServiceName());
         env.setCodebaseContext(codebaseContext);
         addPlatformCodebaseJars(codebaseContext);
         exportServiceCodebaseJars(env.getServiceRoot(), codebaseContext);
@@ -412,7 +371,7 @@ public class StarterServiceDeployer impl
         String argLine = startProps.getProperty(Strings.START_PARAMETERS);
         final String[] args = constructArgs(argLine);
 
-        launchService(env.getClassLoader(), startProps, args);
+        launchService(env, startProps, args);
         log.log(Level.INFO, MessageNames.COMPLETED_SERVICE_DEPLOYMENT, env.getServiceName());
     }
 
@@ -492,35 +451,4 @@ public class StarterServiceDeployer impl
         constructor.setAccessible(true);
         return constructor.newInstance(parms, null);
     }
-
-    private void establishLiveDeploymentMonitoring() {
-        // TODO: Write this
-    }
-
-    @Override
-    public String shutdown(String appId) {
-        throw new UnsupportedOperationException("Not supported yet.");
-    }
-
-    @Override
-    public String listApplications() {
-        StringBuilder sb=new StringBuilder();
-        for (ApplicationEnvironment env: applicationEnvironments) {
-            sb.append(env.getServiceName());
-            sb.append(" - ");
-            sb.append(env.getLifeCycle().getStatus());
-            sb.append("\n");
-        }
-        return sb.toString();
-    }
-
-    @Override
-    public String prepare(String appId) {
-        throw new UnsupportedOperationException("Not supported yet.");
-    }
-
-    @Override
-    public String start(String appId) {
-        throw new UnsupportedOperationException("Not supported yet.");
-    }
 }

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java
Sun May 19 05:06:05 2013
@@ -22,11 +22,5 @@ package org.apache.river.container.deplo
  * @author trasukg
  */
 public interface StarterServiceDeployerMXBean {
-    public String shutdown(String appId);
-    
-    public String listApplications();
-    
-    public String prepare(String appId);
-    
-    public String start(String appId);
+
 }

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycleSM.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycleSM.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycleSM.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StarterServiceLifeCycleSM.java
Sun May 19 05:06:05 2013
@@ -17,6 +17,9 @@
  */
 package org.apache.river.container.deployer;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.river.container.MessageNames;
 import org.apache.river.container.hsm.Controller;
@@ -32,7 +35,7 @@ import org.apache.river.container.work.T
  * Life cycle controller for "service-starter" services. Idle --> Starting -->
  * Running --> Stopping --> Idle --> Zombie
  */
-@RootState({StarterServiceLifeCycle.class, StatusEvents.class})
+@RootState({ServiceLifeCycle.class, StatusEvents.class})
 public class StarterServiceLifeCycleSM {
 
     private static final Logger logger = Logger.getLogger(StarterServiceLifeCycleSM.class.getName(),
@@ -40,14 +43,15 @@ public class StarterServiceLifeCycleSM {
     private ApplicationEnvironment appEnv = null;
     private StarterServiceDeployer deployer = null;
     private StatusEvents eventProxy = null;
-    private StarterServiceLifeCycle lifeCycleProxy = null;
+    private ServiceLifeCycle lifeCycleProxy = null;
+    private List<Throwable> exceptions = new ArrayList<Throwable>();
 
-    public static StarterServiceLifeCycle newStarterServiceLifeCycle(ApplicationEnvironment
appEnv, StarterServiceDeployer deployer) {
+    public static ServiceLifeCycle newStarterServiceLifeCycle(ApplicationEnvironment appEnv,
StarterServiceDeployer deployer) {
         StarterServiceLifeCycleSM machine = new StarterServiceLifeCycleSM();
         machine.appEnv = appEnv;
         machine.deployer = deployer;
         machine.eventProxy = (StatusEvents) PlainStateMachineExecutor.createProxy(machine);
-        machine.lifeCycleProxy = (StarterServiceLifeCycle) machine.eventProxy;
+        machine.lifeCycleProxy = (ServiceLifeCycle) machine.eventProxy;
         return machine.lifeCycleProxy;
     }
     @State({Idle.class, Preparing.class, Prepared.class, Starting.class, Failed.class, Running.class,
Stopping.class, Idle.class})
@@ -59,6 +63,15 @@ public class StarterServiceLifeCycleSM {
     public String getStatus() {
         return state.getClass().getSimpleName();
     }
+
+    public String getName() {
+        return appEnv.getServiceName();
+    }
+
+    public void start() {
+        logger.log(Level.FINE,MessageNames.RECEIVED_START,
+                new String[]{ getStatus() });
+    }
     
     public class Idle {
         /*
@@ -67,17 +80,18 @@ public class StarterServiceLifeCycleSM {
 
         @Transition(Preparing.class)
         public void start() {
+            exceptions.clear();
             Runnable command = new Runnable() {
                 public void run() {
                     /* Prepare the application environment. */
                     try {
                         deployer.prepareService(appEnv);
                         eventProxy.prepareSucceeded();
+                        lifeCycleProxy.start();
+                        eventProxy.startSucceeded();
                     } catch (Exception ex) {
-                        eventProxy.prepareFailed(ex);
+                        eventProxy.exception(ex);
                     }
-
-                    lifeCycleProxy.start();
                 }
             };
             deployer.workManager.queueTask(TaskClass.SYSTEM_TASK, null, command);
@@ -85,6 +99,7 @@ public class StarterServiceLifeCycleSM {
 
         @Transition(Preparing.class)
         public void prepare() {
+            exceptions.clear();
             Runnable command = new Runnable() {
                 public void run() {
                     /* Prepare the application environment. */
@@ -92,19 +107,38 @@ public class StarterServiceLifeCycleSM {
                         deployer.prepareService(appEnv);
                         eventProxy.prepareSucceeded();
                     } catch (Exception ex) {
-                        eventProxy.prepareFailed(ex);
+                        eventProxy.exception(ex);
                     }
                 }
             };
             deployer.workManager.queueTask(TaskClass.SYSTEM_TASK, null, command);
         }
-       
+
     }
 
     public class Preparing {
+
+        @Transition(Prepared.class)
+        public void prepareSucceeded() {
+        }
+
+        @Transition(Failed.class)
+        public void exception(Exception ex) {
+            exceptions.add(ex);
+        }
+
+        public void start() {
+            throw new IllegalStateException(getStatus());
+        }
+
+        public void stop() {
+            throw new IllegalStateException(getStatus());
+        }
+
     }
 
     public class Prepared {
+
         @Transition(Starting.class)
         public void start() {
             Runnable command = new Runnable() {
@@ -114,24 +148,56 @@ public class StarterServiceLifeCycleSM {
                         deployer.launchService(appEnv);
                         eventProxy.startSucceeded();
                     } catch (Exception ex) {
-                        eventProxy.startFailed(ex);
+                        eventProxy.exception(ex);
                     }
                 }
             };
             deployer.workManager.queueTask(TaskClass.SYSTEM_TASK, null, command);
-            
+
         }
+        
+        @Transition(Idle.class)
+        public void stop() {}
+        
     }
 
     public class Running {
+        @Transition(Stopping.class) 
+        public void stop() {
+             Runnable command = new Runnable() {
+                public void run() {
+                    /* Prepare the application environment. */
+                    try {
+                        deployer.stopService(appEnv);
+                        eventProxy.stopSucceeded();
+                    } catch (Exception ex) {
+                        eventProxy.exception(ex);
+                    }
+                }
+            };
+            deployer.workManager.queueTask(TaskClass.SYSTEM_TASK, null, command);
+           
+        }
     }
 
     public class Failed {
     }
 
     public class Stopping {
+        /* TODO: Implement the state machine from here to check for proper
+         * shutdown.
+         */
     }
 
     public class Starting {
+
+        @Transition(Running.class)
+        public void startSucceeded() {
+        }
+
+        @Transition(Failed.class)
+        public void exception(Exception ex) {
+            exceptions.add(ex);
+        }
     }
 }

Added: river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StartupDeployer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StartupDeployer.java?rev=1484221&view=auto
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StartupDeployer.java
(added)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StartupDeployer.java
Sun May 19 05:06:05 2013
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.container.deployer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileType;
+import org.apache.river.container.ConfigurationException;
+import org.apache.river.container.Context;
+import org.apache.river.container.FileUtility;
+import org.apache.river.container.Init;
+import org.apache.river.container.Injected;
+import org.apache.river.container.InjectionStyle;
+import org.apache.river.container.MBeanRegistrar;
+import org.apache.river.container.MessageNames;
+import org.apache.river.container.Name;
+import org.apache.river.container.Utils;
+
+/**
+ *
+ * A Deployer task that deploys all the applications in a given directory when
+ * the container is started up.
+ */
+public class StartupDeployer {
+
+    private static final Logger log =
+            Logger.getLogger(StartupDeployer.class.getName(), MessageNames.BUNDLE_NAME);
+    
+    private String deployDirectory = org.apache.river.container.Strings.DEFAULT_DEPLOY_DIRECTORY;
+    
+    @Injected(style = InjectionStyle.BY_TYPE)
+    private FileUtility fileUtility = null;
+    
+    @Injected(style = InjectionStyle.BY_TYPE)
+    private Context context;
+    
+    @Injected(style = InjectionStyle.BY_TYPE)
+    private StarterServiceDeployer deployer;
+    
+    @Injected(style = InjectionStyle.BY_TYPE)
+    private MBeanRegistrar mbeanRegistrar;
+    
+    @Name
+    private String myName = null;
+
+    private List<ApplicationEnvironment> applicationEnvironments =
+            new ArrayList<ApplicationEnvironment>();
+
+    public String getDeployDirectory() {
+        return deployDirectory;
+    }
+
+    public void setDeployDirectory(String deployDirectory) {
+        this.deployDirectory = deployDirectory;
+    }
+
+    FileObject deploymentDirectoryFile=null;
+    
+    @Init
+    public void init() {
+        try {
+            tryInitialize();
+        } catch (Throwable ex) {
+            log.log(Level.SEVERE, MessageNames.STARTUP_DEPLOYER_FAILED_INIT,
+                    ex);
+            throw new ConfigurationException(ex,
+                    MessageNames.STARTUP_DEPLOYER_FAILED_INIT);
+        }
+    }
+
+    private void tryInitialize() throws IOException, ParseException {
+        log.log(Level.FINE, MessageNames.STARTER_SERVICE_DEPLOYER_STARTING, myName);
+        /*
+         Establish the deployment directory.
+         */
+        deploymentDirectoryFile = fileUtility.getProfileDirectory().resolveFile(deployDirectory);
+        if (deploymentDirectoryFile == null
+                || deploymentDirectoryFile.getType() != FileType.FOLDER) {
+            log.log(Level.WARNING, MessageNames.NO_DEPLOYMENT_DIRECTORY,
+                    new Object[]{deployDirectory, fileUtility.getProfileDirectory()});
+        }
+        /*
+         Go through the deployment directory looking for services to deploy.
+         */
+        List<FileObject> serviceArchives =
+                Utils.findChildrenWithSuffix(deploymentDirectoryFile,
+                org.apache.river.container.Strings.SSAR);
+        if (serviceArchives != null) {
+            log.log(Level.FINE, MessageNames.FOUND_SERVICE_ARCHIVES,
+                    new Object[]{serviceArchives.size(), deployDirectory});
+            deployServiceArchives(serviceArchives);
+        } else {
+            log.log(Level.WARNING, MessageNames.FOUND_NO_SERVICE_ARCHIVES,
+                    new Object[]{deployDirectory});
+
+        }
+
+    }
+
+    private void deployServiceArchives(List<FileObject> serviceArchives) {
+        /*
+         Deploy those services.
+         */
+        for (FileObject archiveFile : serviceArchives) {
+            try {
+                /* Try the archive in all the deployers to see if someone can 
+                 * handle it. For now there's only one.
+                 */
+                
+                /*
+                 * Create the ApplicationEnvironment for the archive.
+                 */
+                ServiceLifeCycle deployedApp=deployer.deployServiceArchive(archiveFile);
+                // Register it as an MBean
+                registerApplication(deployedApp);
+                deployedApp.start();
+            } catch (Throwable t) {
+                log.log(Level.WARNING, MessageNames.FAILED_DEPLOY_SERVICE, archiveFile.toString());
+                log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, Utils.stackTrace(t));
+            }
+        }
+    }
+    
+    private void registerApplication(ServiceLifeCycle deployedApp) throws MalformedObjectNameException,
InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
+        Hashtable<String, String> props=new Hashtable<String,String>();
+        props.put(org.apache.river.container.Strings.NAME, deployedApp.getName());
+        ObjectName oName=new ObjectName(org.apache.river.container.Strings.CONTAINER_JMX_DOMAIN,
props);
+        mbeanRegistrar.getMbeanServer().registerMBean(
+                deployedApp, oName);
+    }
+}

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StatusEvents.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StatusEvents.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StatusEvents.java (original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/deployer/StatusEvents.java Sun
May 19 05:06:05 2013
@@ -24,11 +24,11 @@ package org.apache.river.container.deplo
 interface StatusEvents {
     public void prepareSucceeded();
     
-    public void prepareFailed(Exception ex);
-    
     public void startSucceeded();
     
-    public void startFailed(Exception ex);
+    public void stopSucceeded();
+    
+    public void exception(Exception ex);
     
     public void tick();
 }

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/hsm/PlainStateMachineExecutor.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/hsm/PlainStateMachineExecutor.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/hsm/PlainStateMachineExecutor.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/hsm/PlainStateMachineExecutor.java
Sun May 19 05:06:05 2013
@@ -132,7 +132,7 @@ public class PlainStateMachineExecutor i
     private static void writeStateField(SubstateInfo ssi, MetaState metaState) throws IllegalArgumentException,
IllegalAccessException, SecurityException {
         boolean originalAccess = ssi.getField().isAccessible();
         ssi.getField().setAccessible(true);
-        ssi.getField().set(ssi.getObjectThatHoldsField(), ssi.getInitialMetaState().stateInstance);
+        ssi.getField().set(ssi.getObjectThatHoldsField(), metaState.stateInstance);
         ssi.getField().setAccessible(originalAccess);
     }
 

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java
Sun May 19 05:06:05 2013
@@ -19,6 +19,7 @@ package org.apache.river.container.secur
 
 import java.security.*;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -56,13 +57,20 @@ public class ContainerCodePolicy extends
     @Override
     public PermissionCollection getPermissions(ProtectionDomain domain) {
         if (privilegedClassLoaders.contains(domain.getClassLoader()) ) {
-            return allPermissions;
+            return copyPermissions(allPermissions);
         } else {
             log.log(Level.FINE, MessageNames.POLICY_DECLINED,
                     new Object[] { domain.getClassLoader() });
-            return noPermissions;
+            return copyPermissions(noPermissions);
         }
     }
     
-    
+    PermissionCollection copyPermissions(PermissionCollection orig) {
+        PermissionCollection pc=new Permissions();
+        Enumeration perms=orig.elements();
+        while(perms.hasMoreElements()) {
+            pc.add((Permission) perms.nextElement());
+        }
+        return pc; 
+    }
 }

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/work/BasicWorkManager.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/work/BasicWorkManager.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/work/BasicWorkManager.java (original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/work/BasicWorkManager.java Sun
May 19 05:06:05 2013
@@ -52,18 +52,8 @@ public class BasicWorkManager implements
         threadFactory = new MyThreadFactory();
         executor = Executors.newCachedThreadPool(threadFactory);
     }
-    int activeCount = 0;
-
-    synchronized void incActiveCount() {
-        activeCount++;
-    }
-
-    synchronized void decActiveCount() {
-        activeCount--;
-    }
 
     synchronized int getActiveCount() {
-        //return activeCount;
         return threadFactory.threadGroup.activeCount();
     }
 
@@ -90,11 +80,9 @@ public class BasicWorkManager implements
             originalClassLoader = Thread.currentThread().getContextClassLoader();
             Thread.currentThread().setContextClassLoader(contextClassLoader);
             try {
-                incActiveCount();
                 task.run();
             } finally {
                 Thread.currentThread().setContextClassLoader(originalClassLoader);
-                decActiveCount();
             }
         }
     }

Modified: river/jtsk/skunk/surrogate/test/org/apache/river/container/hsm/InitializedMachineTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/test/org/apache/river/container/hsm/InitializedMachineTest.java?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/test/org/apache/river/container/hsm/InitializedMachineTest.java
(original)
+++ river/jtsk/skunk/surrogate/test/org/apache/river/container/hsm/InitializedMachineTest.java
Sun May 19 05:06:05 2013
@@ -69,6 +69,7 @@ public class InitializedMachineTest {
     @Test
     public void testUnlocking() {
         UUTI.unlock();
+        assertTrue("lockedState is not instance of Unlocked", UUT.lockedState instanceof
InitializedTestSM.Unlocked);
         UUTI.setValue(20);
     }
     

Modified: river/jtsk/skunk/surrogate/testfiles/testroot/profile/default/config.xml
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/testfiles/testroot/profile/default/config.xml?rev=1484221&r1=1484220&r2=1484221&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/testfiles/testroot/profile/default/config.xml (original)
+++ river/jtsk/skunk/surrogate/testfiles/testroot/profile/default/config.xml Sun May 19 05:06:05
2013
@@ -42,6 +42,13 @@
         <cfg:property name="deployDirectory" value="deploy"/>
     </cfg:component>
     
+    <!-- Deployer for applications that are in the 'deploy' directory
+    at startup. -->
+    <cfg:component class="org.apache.river.container.deployer.StartupDeployer">
+        <cfg:property name="config" value="service-starter.cfg"/>
+        <cfg:property name="deployDirectory" value="deploy"/>
+    </cfg:component>
+    
     <!-- Deployer for 'system apps' like the remote deployment service 
     <cfg:component class="org.apache.river.container.deployer.StarterServiceDeployer">
         <cfg:property name="config" value="privileged-services.cfg"/>



Mime
View raw message