You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by gt...@apache.org on 2014/02/18 15:20:39 UTC
[6/8] git commit: Admin Service is able to query all the
ApplicationManager objects in the container context for application statuses.
Admin Service is able to query all the ApplicationManager objects in the container context for application statuses.
StarterServiceDeployer now creates a working directory for each service and places the File for that directory into the service's configuration as $workingDirectory.
The StartupDeployer has been renamed to FolderBasedAppRunner which is more descriptive of its function. It scans a folder at startup and runs any application archives that it finds. Similarly, the ClientAppDeployer has been renamed to CommandLineAppRunner, since it runs the application specified on the command line.
The Context class now supports getting all components that implement a given interface. This functionality is used to find all the ApplicationManager implementations that can be polled for applications.
Project: http://git-wip-us.apache.org/repos/asf/river-container/repo
Commit: http://git-wip-us.apache.org/repos/asf/river-container/commit/33855de2
Tree: http://git-wip-us.apache.org/repos/asf/river-container/tree/33855de2
Diff: http://git-wip-us.apache.org/repos/asf/river-container/diff/33855de2
Branch: refs/heads/master
Commit: 33855de2556a78d42329e48b109bd949eb244dad
Parents: e6828db
Author: Greg Trasuk <tr...@trasuk.com>
Authored: Mon Feb 17 22:05:39 2014 -0500
Committer: Greg Trasuk <tr...@trasuk.com>
Committed: Mon Feb 17 22:05:39 2014 -0500
----------------------------------------------------------------------
.../container/admin/api/ApplicationInfo.java | 43 ++-
.../river/container/admin/impl/AdminImpl.java | 68 +++-
.../admin-svc-module/src/assemble/module.xml | 3 +
.../src/main/root/admin-svc.config | 6 +
product/src/main/root/bin/logging.properties | 3 +-
.../main/root/profile/admin-client/config.xml | 2 +-
product/src/main/root/profile/client/config.xml | 2 +-
.../src/main/root/profile/default/config.xml | 9 +-
.../src/main/root/profile/outrigger/config.xml | 2 +-
river-container-core/pom.xml | 10 +-
.../river/container/ApplicationManager.java | 30 ++
.../org/apache/river/container/Context.java | 12 +
.../apache/river/container/MessageNames.java | 1 +
.../org/apache/river/container/Strings.java | 3 +-
.../deployer/ApplicationEnvironment.java | 22 ++
.../container/deployer/ClientAppDeployer.java | 195 ------------
.../deployer/CommandLineAppRunner.java | 197 ++++++++++++
.../deployer/FolderBasedAppRunner.java | 316 +++++++++++++++++++
.../deployer/StarterServiceDeployer.java | 48 ++-
.../deployer/StarterServiceDeployerMXBean.java | 26 --
.../container/deployer/StartupDeployer.java | 291 -----------------
.../river/container/deployer/Strings.java | 3 +
.../apache/river/container/Messages.properties | 1 +
.../org/apache/river/container/core-config.xml | 1 +
.../org/apache/river/container/ContextTest.java | 73 +++++
.../src/main/root/profile/client/config.xml | 2 +-
.../src/main/root/profile/default/config.xml | 2 +-
27 files changed, 824 insertions(+), 547 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/admin-svc/admin-svc-api/src/main/java/org/apache/river/container/admin/api/ApplicationInfo.java
----------------------------------------------------------------------
diff --git a/admin-svc/admin-svc-api/src/main/java/org/apache/river/container/admin/api/ApplicationInfo.java b/admin-svc/admin-svc-api/src/main/java/org/apache/river/container/admin/api/ApplicationInfo.java
index df3f73b..74e2945 100644
--- a/admin-svc/admin-svc-api/src/main/java/org/apache/river/container/admin/api/ApplicationInfo.java
+++ b/admin-svc/admin-svc-api/src/main/java/org/apache/river/container/admin/api/ApplicationInfo.java
@@ -1,7 +1,19 @@
/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
+ * 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.admin.api;
@@ -9,16 +21,35 @@ package org.apache.river.container.admin.api;
import java.io.Serializable;
/**
- *
- * @author trasukg
+ * Transfer object for information about applications running in the container.
+ *
*/
public class ApplicationInfo implements Serializable {
String name;
ApplicationStatus status;
+ String deployer;
- public ApplicationInfo(String name, ApplicationStatus status) {
+ public ApplicationInfo(String deployer, String name, ApplicationStatus status) {
+ this.deployer=deployer;
this.name = name;
this.status = status;
}
+
+ public String getName() {
+ return name;
+ }
+
+ public ApplicationStatus getStatus() {
+ return status;
+ }
+
+ /**
+ * The name of the deployer that launched this service.
+ * @return
+ */
+ public String getDeployer() {
+ return deployer;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/admin-svc/admin-svc-impl/src/main/java/org/apache/river/container/admin/impl/AdminImpl.java
----------------------------------------------------------------------
diff --git a/admin-svc/admin-svc-impl/src/main/java/org/apache/river/container/admin/impl/AdminImpl.java b/admin-svc/admin-svc-impl/src/main/java/org/apache/river/container/admin/impl/AdminImpl.java
index b137e94..82e206a 100644
--- a/admin-svc/admin-svc-impl/src/main/java/org/apache/river/container/admin/impl/AdminImpl.java
+++ b/admin-svc/admin-svc-impl/src/main/java/org/apache/river/container/admin/impl/AdminImpl.java
@@ -19,9 +19,14 @@ package org.apache.river.container.admin.impl;
import com.sun.jini.config.Config;
import com.sun.jini.start.LifeCycle;
+import java.io.File;
import java.io.IOException;
import java.rmi.server.ExportException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.jini.config.Configuration;
@@ -34,11 +39,12 @@ import net.jini.export.Exporter;
import net.jini.lookup.JoinManager;
import net.jini.lookup.ServiceIDListener;
import net.jini.security.ProxyPreparer;
+import org.apache.river.container.ApplicationManager;
+import org.apache.river.container.Context;
import org.apache.river.container.MessageNames;
import org.apache.river.container.Utils;
import org.apache.river.container.admin.api.Admin;
import org.apache.river.container.admin.api.ApplicationInfo;
-import org.apache.river.container.admin.api.ApplicationStatus;
import org.apache.river.container.admin.dl.AdminRemote;
/**
@@ -53,17 +59,28 @@ public class AdminImpl implements ServiceIDListener, AdminRemote {
private static final String COMPONENT_ID = "basic";
Configuration config = null;
+ Context ctx = null;
+
Admin myProxy = null;
Exporter exporter = null;
ProxyPreparer registrarPreparer = null;
JoinManager joinManager = null;
DiscoveryManagement discoveryManager = null;
Entry[] attributes = null;
- ScheduledExecutorService executor=null;
+ volatile ScheduledExecutorService executor = null;
+ File workingDirectory=null;
public AdminImpl(String args[], final LifeCycle lc) throws ConfigurationException, ExportException, IOException {
config = ConfigurationProvider.getInstance(args);
+ try {
+ ctx = (Context) config.getEntry(COMPONENT_ID, "context", Context.class);
+ } catch(Throwable t) {
+ t.printStackTrace();
+ }
+
+ workingDirectory=(File) Config.getNonNullEntry(config, COMPONENT_ID, "workingDirectory", File.class);
+
// Get the exporter and create our proxy.
exporter = (Exporter) Config.getNonNullEntry(config, COMPONENT_ID, "exporter", Exporter.class);
Utils.logGrantsToClass(log, Level.FINE, this.getClass());
@@ -78,16 +95,31 @@ public class AdminImpl implements ServiceIDListener, AdminRemote {
// Publish it using the join manager.
// We don't have to do anything with it - just creating it starts the join process.
joinManager = new JoinManager(myProxy, attributes, this, discoveryManager, null, config);
- log.info("Started the admin service");
-
+
/* For local clients, we don't want to be dependent on the Jini infrastructure being setup
- correctly. For this reason, we stash a copy of the proxy's MarshalledObject in the local
- file system.
- */
- synchronized(this) {
- executor=(ScheduledExecutorService) Config.getNonNullEntry(config, COMPONENT_ID, "$executor", ScheduledExecutorService.class);
+ correctly. For this reason, we stash a copy of the proxy's MarshalledObject in the local
+ file system.
+ */
+ try {
+ synchronized (this) {
+ executor = (ScheduledExecutorService) Config.getNonNullEntry(config, COMPONENT_ID,
+ "scheduledExecutorService", ScheduledExecutorService.class);
+ executor.schedule(new Runnable() {
+ public void run() {
+ System.out.println("Hooray! we're on the executor!");
+ System.out.println("Applications:");
+ try {
+ printApps(listApplications());
+ } catch(Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }, 4, TimeUnit.SECONDS);
+ }
+ log.info("Started the admin service");
+ } catch (Throwable t) {
+ t.printStackTrace();
}
-
}
ServiceID sid = null;
@@ -97,9 +129,19 @@ public class AdminImpl implements ServiceIDListener, AdminRemote {
}
public ApplicationInfo[] listApplications() throws IOException {
- return new ApplicationInfo[]{
- new ApplicationInfo("abc", ApplicationStatus.UNKNOWN)
- };
+
+ Collection<ApplicationManager> managers = ctx.getAll(ApplicationManager.class);
+ List<ApplicationInfo> info = new ArrayList<ApplicationInfo>();
+ for (ApplicationManager manager : managers) {
+ info.addAll(manager.getApplicationInfo());
+ }
+ return info.toArray(new ApplicationInfo[0]);
}
+ void printApps(ApplicationInfo[] apps) {
+ for (ApplicationInfo app:apps) {
+ System.out.printf(" %s - %s - %s\n", app.getDeployer(), app.getName(), app.getStatus().toString());
+ }
+ System.out.printf("Working directory is %s and writable=%b\n", workingDirectory.getAbsolutePath(), workingDirectory.canWrite());
+ }
}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/admin-svc/admin-svc-module/src/assemble/module.xml
----------------------------------------------------------------------
diff --git a/admin-svc/admin-svc-module/src/assemble/module.xml b/admin-svc/admin-svc-module/src/assemble/module.xml
index d8f36d3..a051d78 100644
--- a/admin-svc/admin-svc-module/src/assemble/module.xml
+++ b/admin-svc/admin-svc-module/src/assemble/module.xml
@@ -47,6 +47,9 @@
<!-- jsk jars are already provided by the container. -->
<excludes>
<exclude>*:jsk-*</exclude>
+ <!-- This jar is in the parent, so we can't have it in the
+ module -->
+ <exclude>org.apache.river.container:admin-svc-api</exclude>
</excludes>
</dependencySet>
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/admin-svc/admin-svc-module/src/main/root/admin-svc.config
----------------------------------------------------------------------
diff --git a/admin-svc/admin-svc-module/src/main/root/admin-svc.config b/admin-svc/admin-svc-module/src/main/root/admin-svc.config
index 7b6854f..0ed2d46 100644
--- a/admin-svc/admin-svc-module/src/main/root/admin-svc.config
+++ b/admin-svc/admin-svc-module/src/main/root/admin-svc.config
@@ -29,6 +29,12 @@ basic {
static attributes = new Entry[] { new Name("admin-service") };
+ scheduledExecutorService=$scheduledExecutorService;
+
+ context=$context;
+
+ workingDirectory=$workingDirectory;
+
}
net.jini.lookup.JoinManager {
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/product/src/main/root/bin/logging.properties
----------------------------------------------------------------------
diff --git a/product/src/main/root/bin/logging.properties b/product/src/main/root/bin/logging.properties
index 66e0a0c..4586c3b 100644
--- a/product/src/main/root/bin/logging.properties
+++ b/product/src/main/root/bin/logging.properties
@@ -77,6 +77,7 @@ org.apache.river.container.security.ContainerCodePolicy.level=SEVERE
org.apache.river.container.admin.level=INFO
org.apache.river.container.deployer.level=INFO
org.apache.river.container.deployer.ClasspathFilterBuilder.level=INFO
-org.apache.river.container.deployer.DeployerConfigParser=INFO
+org.apache.river.container.deployer.DeployerConfigParser.level=INFO
+org.apache.river.container.deployer.FolderBasedAppRunner.level=FINE
org.apache.river.container.hsm.level=SEVERE
net.jini.config.level=INFO
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/product/src/main/root/profile/admin-client/config.xml
----------------------------------------------------------------------
diff --git a/product/src/main/root/profile/admin-client/config.xml b/product/src/main/root/profile/admin-client/config.xml
index dc607fe..914ca41 100644
--- a/product/src/main/root/profile/admin-client/config.xml
+++ b/product/src/main/root/profile/admin-client/config.xml
@@ -45,7 +45,7 @@
<!-- Deployer for 'service-starter'-style applications.
This is the 'admin-app' profile, so set the clientAppName to 'admin'
-->
- <cfg:component class="org.apache.river.container.deployer.ClientAppDeployer">
+ <cfg:component class="org.apache.river.container.deployer.CommandLineAppRunner">
<cfg:property name="deployDirectory" value="deploy"/>
<cfg:property name="clientAppName" value="admin"/>
</cfg:component>
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/product/src/main/root/profile/client/config.xml
----------------------------------------------------------------------
diff --git a/product/src/main/root/profile/client/config.xml b/product/src/main/root/profile/client/config.xml
index 9b01480..b46200f 100644
--- a/product/src/main/root/profile/client/config.xml
+++ b/product/src/main/root/profile/client/config.xml
@@ -43,7 +43,7 @@
</cfg:component>
<!-- Deployer for 'service-starter'-style applications. -->
- <cfg:component class="org.apache.river.container.deployer.ClientAppDeployer">
+ <cfg:component class="org.apache.river.container.deployer.CommandLineAppRunner">
<cfg:property name="deployDirectory" value="deploy"/>
</cfg:component>
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/product/src/main/root/profile/default/config.xml
----------------------------------------------------------------------
diff --git a/product/src/main/root/profile/default/config.xml b/product/src/main/root/profile/default/config.xml
index 69488e2..cd21bc2 100644
--- a/product/src/main/root/profile/default/config.xml
+++ b/product/src/main/root/profile/default/config.xml
@@ -38,13 +38,15 @@
<cfg:component class="org.apache.river.container.codebase.ClassServer"/>
<!-- Deployer for 'service-starter'-style applications. -->
- <cfg:component class="org.apache.river.container.deployer.StarterServiceDeployer">
+ <cfg:component class="org.apache.river.container.deployer.StarterServiceDeployer"
+ name="starter-service-deployer">
<cfg:property name="config" value="service-starter.cfg"/>
</cfg:component>
<!-- Deployer for applications that are in the 'deploy' directory
at startup. -->
- <cfg:component class="org.apache.river.container.deployer.StartupDeployer">
+ <cfg:component class="org.apache.river.container.deployer.FolderBasedAppRunner" name="deploy">
+ <cfg:property name="deployerName" value="starter-service-deployer"/>
<cfg:property name="deployDirectory" value="deploy"/>
<cfg:property name="autoDeploy" value="true"/>
</cfg:component>
@@ -59,7 +61,8 @@
<!-- Deployer for applications that are in the 'deploy' directory
at startup. -->
- <cfg:component class="org.apache.river.container.deployer.StartupDeployer">
+ <cfg:component class="org.apache.river.container.deployer.FolderBasedAppRunner"
+ name="deploy-privileged">
<cfg:property name="deployDirectory" value="deploy-privileged"/>
<cfg:property name="autoDeploy" value="true"/>
<cfg:property name="deployerName" value="privileged-deployer"/>
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/product/src/main/root/profile/outrigger/config.xml
----------------------------------------------------------------------
diff --git a/product/src/main/root/profile/outrigger/config.xml b/product/src/main/root/profile/outrigger/config.xml
index 7d81f52..5dcd2e0 100644
--- a/product/src/main/root/profile/outrigger/config.xml
+++ b/product/src/main/root/profile/outrigger/config.xml
@@ -44,7 +44,7 @@
<!-- Deployer for applications that are in the 'deploy' directory
at startup. -->
- <cfg:component class="org.apache.river.container.deployer.StartupDeployer">
+ <cfg:component class="org.apache.river.container.deployer.FolderBasedAppRunner">
<cfg:property name="deployDirectory" value="deploy"/>
<cfg:property name="autoDeploy" value="true"/>
</cfg:component>
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/pom.xml
----------------------------------------------------------------------
diff --git a/river-container-core/pom.xml b/river-container-core/pom.xml
index 1bce606..e3c5727 100644
--- a/river-container-core/pom.xml
+++ b/river-container-core/pom.xml
@@ -61,9 +61,17 @@
<dependency>
<groupId>org.apache.river.container</groupId>
- <artifactId>reggie-module</artifactId>
+ <artifactId>admin-svc-api</artifactId>
<version>1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.river.container</groupId>
+ <artifactId>reggie-module</artifactId>
+ <version>${project.version}</version>
+
<scope>test</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/ApplicationManager.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/ApplicationManager.java b/river-container-core/src/main/java/org/apache/river/container/ApplicationManager.java
new file mode 100644
index 0000000..346c388
--- /dev/null
+++ b/river-container-core/src/main/java/org/apache/river/container/ApplicationManager.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import java.util.List;
+import org.apache.river.container.admin.api.ApplicationInfo;
+
+/**
+ *
+ * @author trasukg
+ */
+public interface ApplicationManager {
+ List<ApplicationInfo> getApplicationInfo();
+}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/Context.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/Context.java b/river-container-core/src/main/java/org/apache/river/container/Context.java
index bbf2de6..89047e1 100644
--- a/river-container-core/src/main/java/org/apache/river/container/Context.java
+++ b/river-container-core/src/main/java/org/apache/river/container/Context.java
@@ -19,6 +19,7 @@
package org.apache.river.container;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -65,6 +66,17 @@ public class Context {
return contents.get(name);
}
+ public <T extends Object> Collection<T> getAll(Class<T> type) {
+ List<T> list=new ArrayList<T>();
+ for (Object item:contents.values()) {
+ if (type.isAssignableFrom(item.getClass())) {
+ list.add((T) item);
+ }
+ }
+ return list;
+ }
+
+
/**
Called by the bootstrapper to tell us that processing of the initialization
file is now complete.
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/MessageNames.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/MessageNames.java b/river-container-core/src/main/java/org/apache/river/container/MessageNames.java
index 95828e8..7c404b8 100644
--- a/river-container-core/src/main/java/org/apache/river/container/MessageNames.java
+++ b/river-container-core/src/main/java/org/apache/river/container/MessageNames.java
@@ -78,6 +78,7 @@ public class MessageNames {
DUPLICATE_CLASSPATH="duplicateClasspath",
EXCEPTION_THROWN="exceptionThrown",
EXCEPTION_WHILE_STOPPING="exceptionWhileStopping",
+ EXECUTOR_NAME_IS="executorNameIs",
FAILED_CLEAN_SHUTDOWN="failedCleanShutdown",
FAILED_DEPLOY_SERVICE="failedDeployService",
FAILED_READ_PROPERTIES="failedReadProperties",
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/Strings.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/Strings.java b/river-container-core/src/main/java/org/apache/river/container/Strings.java
index 76510b3..48dfa55 100644
--- a/river-container-core/src/main/java/org/apache/river/container/Strings.java
+++ b/river-container-core/src/main/java/org/apache/river/container/Strings.java
@@ -80,6 +80,7 @@ public class Strings {
UNKNOWN="unknown",
UNNAMED="unnamed",
WHITESPACE_SEPARATORS=" \t\n\r",
- WORK="work";
+ WORK="work",
+ WORKING_DIRECTORY="workingDirectory";
}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/deployer/ApplicationEnvironment.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/deployer/ApplicationEnvironment.java b/river-container-core/src/main/java/org/apache/river/container/deployer/ApplicationEnvironment.java
index dc9dab3..47f1c3f 100644
--- a/river-container-core/src/main/java/org/apache/river/container/deployer/ApplicationEnvironment.java
+++ b/river-container-core/src/main/java/org/apache/river/container/deployer/ApplicationEnvironment.java
@@ -18,6 +18,7 @@
package org.apache.river.container.deployer;
+import java.io.File;
import org.apache.commons.vfs2.FileObject;
import org.apache.river.container.classloading.VirtualFileSystemClassLoader;
import org.apache.river.container.codebase.CodebaseContext;
@@ -30,6 +31,16 @@ import org.apache.river.container.work.WorkingContext;
public class ApplicationEnvironment {
VirtualFileSystemClassLoader classLoader=null;
+ String applicationManagerName=null;
+
+ public String getApplicationManagerName() {
+ return applicationManagerName;
+ }
+
+ public void setApplicationManagerName(String applicationManagerName) {
+ this.applicationManagerName = applicationManagerName;
+ }
+
String serviceName=null;
public String getServiceName() {
@@ -95,4 +106,15 @@ public class ApplicationEnvironment {
this.workingContext = workingContext;
}
+ File workingDirectory=null;
+
+ public File getWorkingDirectory() {
+ return workingDirectory;
+ }
+
+ public void setWorkingDirectory(File workingDirectory) {
+ this.workingDirectory = workingDirectory;
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/deployer/ClientAppDeployer.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/deployer/ClientAppDeployer.java b/river-container-core/src/main/java/org/apache/river/container/deployer/ClientAppDeployer.java
deleted file mode 100644
index f3c3638..0000000
--- a/river-container-core/src/main/java/org/apache/river/container/deployer/ClientAppDeployer.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.ResourceBundle;
-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.vfs2.FileObject;
-import org.apache.commons.vfs2.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 ClientAppDeployer {
-
- private static final Logger log
- = Logger.getLogger(ClientAppDeployer.class.getName(), MessageNames.BUNDLE_NAME);
-
- @Injected
- ResourceBundle messages;
-
- @Injected
- public String[] commandLineArguments = null;
-
- @Injected(style = InjectionStyle.BY_TYPE)
- Context context = null;
-
- 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 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;
-
- private String clientAppName = null;
-
- public String getClientAppName() {
- return clientAppName;
- }
-
- /**
- * Set the client app that should be loaded. If not provided, client app
- * name is taken from the first parameter.
- *
- * @param clientApp
- */
- public void setClientAppName(String clientApp) {
- this.clientAppName = clientApp;
- }
-
- @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()});
- }
- /*
- * Find the name of the client we need to deploy.
- */
- /* First argument was the profile name. Second argument is the name of
- * the client app to run. All the rest are parameters to the client
- * app.
- */
- if (clientAppName == null && commandLineArguments.length < 2) {
- System.out.println(messages.getString(MessageNames.CLIENT_APP_USAGE));
- System.exit(1);
- }
- String[] clientAppArgs;
- if (clientAppName == null) {
- clientAppName = commandLineArguments[1];
- clientAppArgs = new String[commandLineArguments.length - 2];
- System.arraycopy(commandLineArguments, 2, clientAppArgs, 0,
- clientAppArgs.length);
- } else {
- clientAppArgs = new String[commandLineArguments.length - 1];
- System.arraycopy(commandLineArguments, 1, clientAppArgs, 0,
- clientAppArgs.length);
- }
- // Locate the service archive that has the client's name.
- // First get all the jar files.
- List<FileObject> serviceArchives
- = Utils.findChildrenWithSuffix(deploymentDirectoryFile,
- org.apache.river.container.Strings.JAR);
- //Then find the one that starts with the client name
- FileObject serviceArchive = null;
- for (FileObject fo : serviceArchives) {
- if (fo.getName().getBaseName().startsWith(clientAppName + org.apache.river.container.Strings.DASH)) {
- serviceArchive = fo;
- break;
- }
-
- }
-
- if (serviceArchive == null) {
- System.err.println(MessageFormat.format(messages.getString(MessageNames.NO_SUCH_CLIENT_APP), clientAppName));
- System.exit(1);
- }
- // Deploy the service
- deployServiceArchive(serviceArchive, clientAppArgs);
- // Run the main method with the remaining command line parameters.
- }
-
- private void deployServiceArchive(FileObject archiveFile, String[] commandLineArgs) {
- 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);
-
- deployedApp.startWithArgs(commandLineArgs);
- } catch (Throwable t) {
- log.log(Level.WARNING, MessageNames.FAILED_DEPLOY_SERVICE, archiveFile.toString());
- log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, Utils.stackTrace(t));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/deployer/CommandLineAppRunner.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/deployer/CommandLineAppRunner.java b/river-container-core/src/main/java/org/apache/river/container/deployer/CommandLineAppRunner.java
new file mode 100644
index 0000000..ed2abf6
--- /dev/null
+++ b/river-container-core/src/main/java/org/apache/river/container/deployer/CommandLineAppRunner.java
@@ -0,0 +1,197 @@
+/*
+ * 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.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.ResourceBundle;
+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.vfs2.FileObject;
+import org.apache.commons.vfs2.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 runner task that looks at the command line to determine the name of an
+ * application to run from a deployment folder. Generally used to run "client"
+ * apps where the name of the app is supplied on the command line, for instance
+ * the browser app or the admin client app.
+ */
+public class CommandLineAppRunner {
+
+ private static final Logger log
+ = Logger.getLogger(CommandLineAppRunner.class.getName(), MessageNames.BUNDLE_NAME);
+
+ @Injected
+ ResourceBundle messages;
+
+ @Injected
+ public String[] commandLineArguments = null;
+
+ @Injected(style = InjectionStyle.BY_TYPE)
+ Context context = null;
+
+ 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 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;
+
+ private String clientAppName = null;
+
+ public String getClientAppName() {
+ return clientAppName;
+ }
+
+ /**
+ * Set the client app that should be loaded. If not provided, client app
+ * name is taken from the first parameter.
+ *
+ * @param clientApp
+ */
+ public void setClientAppName(String clientApp) {
+ this.clientAppName = clientApp;
+ }
+
+ @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()});
+ }
+ /*
+ * Find the name of the client we need to deploy.
+ */
+ /* First argument was the profile name. Second argument is the name of
+ * the client app to run. All the rest are parameters to the client
+ * app.
+ */
+ if (clientAppName == null && commandLineArguments.length < 2) {
+ System.out.println(messages.getString(MessageNames.CLIENT_APP_USAGE));
+ System.exit(1);
+ }
+ String[] clientAppArgs;
+ if (clientAppName == null) {
+ clientAppName = commandLineArguments[1];
+ clientAppArgs = new String[commandLineArguments.length - 2];
+ System.arraycopy(commandLineArguments, 2, clientAppArgs, 0,
+ clientAppArgs.length);
+ } else {
+ clientAppArgs = new String[commandLineArguments.length - 1];
+ System.arraycopy(commandLineArguments, 1, clientAppArgs, 0,
+ clientAppArgs.length);
+ }
+ // Locate the service archive that has the client's name.
+ // First get all the jar files.
+ List<FileObject> serviceArchives
+ = Utils.findChildrenWithSuffix(deploymentDirectoryFile,
+ org.apache.river.container.Strings.JAR);
+ //Then find the one that starts with the client name
+ FileObject serviceArchive = null;
+ for (FileObject fo : serviceArchives) {
+ if (fo.getName().getBaseName().startsWith(clientAppName + org.apache.river.container.Strings.DASH)) {
+ serviceArchive = fo;
+ break;
+ }
+
+ }
+
+ if (serviceArchive == null) {
+ System.err.println(MessageFormat.format(messages.getString(MessageNames.NO_SUCH_CLIENT_APP), clientAppName));
+ System.exit(1);
+ }
+ // Deploy the service
+ deployServiceArchive(serviceArchive, clientAppArgs);
+ // Run the main method with the remaining command line parameters.
+ }
+
+ private void deployServiceArchive(FileObject archiveFile, String[] commandLineArgs) {
+ 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(myName, archiveFile);
+
+ deployedApp.startWithArgs(commandLineArgs);
+ } catch (Throwable t) {
+ log.log(Level.WARNING, MessageNames.FAILED_DEPLOY_SERVICE, archiveFile.toString());
+ log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, Utils.stackTrace(t));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/deployer/FolderBasedAppRunner.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/deployer/FolderBasedAppRunner.java b/river-container-core/src/main/java/org/apache/river/container/deployer/FolderBasedAppRunner.java
new file mode 100644
index 0000000..1204420
--- /dev/null
+++ b/river-container-core/src/main/java/org/apache/river/container/deployer/FolderBasedAppRunner.java
@@ -0,0 +1,316 @@
+/*
+ * 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.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+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.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.river.container.ApplicationManager;
+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;
+import org.apache.river.container.admin.api.ApplicationInfo;
+import org.apache.river.container.admin.api.ApplicationStatus;
+
+/**
+ *
+ * A task that deploys and runs all the applications in a given directory when
+ * the container is started up.
+ */
+public class FolderBasedAppRunner implements ApplicationManager {
+
+ private static final Logger log
+ = Logger.getLogger(FolderBasedAppRunner.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 Map<String, DeploymentRecord> deployedServices = new HashMap<String, DeploymentRecord>();
+
+ private class DeploymentRecord {
+
+ String name;
+ long updateTime;
+ FileObject fileObject;
+ ServiceLifeCycle serviceLifeCycle;
+ }
+
+ private boolean autoDeploy = false;
+
+ public boolean isAutoDeploy() {
+ return autoDeploy;
+ }
+
+ public void setAutoDeploy(boolean autoDeploy) {
+ this.autoDeploy = autoDeploy;
+ }
+
+ public int getScanInterval() {
+ return scanInterval;
+ }
+
+ public void setScanInterval(int scanInterval) {
+ this.scanInterval = scanInterval;
+ }
+
+ private int scanInterval = 5;
+
+ public String getDeployDirectory() {
+ return deployDirectory;
+ }
+
+ public void setDeployDirectory(String deployDirectory) {
+ this.deployDirectory = deployDirectory;
+ }
+
+ FileObject deploymentDirectoryFile = null;
+
+ private String deployerName=null;
+
+ public String getDeployerName() {
+ return deployerName;
+ }
+
+ public void setDeployerName(String deployerName) {
+ this.deployerName = deployerName;
+ }
+
+ @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);
+ /*
+ If the deployerName is supplied, look it up and override the injected deployer.
+ */
+ if(deployerName != null) {
+ deployer=(StarterServiceDeployer) context.get(deployerName);
+ }
+ /*
+ 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()});
+ }
+ /*
+ Do the scan task once - this will launch all the services currently in
+ deploy dir.
+ */
+ new ScanTask().runOnce();
+
+ if (autoDeploy) {
+ /* Now schedule a scan in the required scan time. */
+ deployer.workManager.schedule(null, new ScanTask(), getScanInterval(), TimeUnit.SECONDS);
+ }
+ }
+
+ 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);
+ }
+
+ private void unregisterApplication(ServiceLifeCycle deployedApp) {
+ try {
+ 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().unregisterMBean(oName);
+ } catch (Exception e) {
+ log.log(Level.SEVERE, MessageNames.FAILED_TO_REMOVE_MBEAN,
+ new Object[]{deployedApp.getName()});
+ }
+ }
+
+ private Map<String, DeploymentRecord> scanDeploymentArchives() throws FileSystemException {
+ /*
+ Go through the deployment directory looking for services to deploy.
+ */
+ Map<String, DeploymentRecord> deployDirListing = new HashMap<String, DeploymentRecord>();
+ deploymentDirectoryFile.refresh();
+ List<FileObject> serviceArchives
+ = Utils.findChildrenWithSuffix(deploymentDirectoryFile,
+ org.apache.river.container.Strings.JAR);
+ if (serviceArchives != null) {
+ log.log(Level.FINER, MessageNames.FOUND_SERVICE_ARCHIVES,
+ new Object[]{serviceArchives.size(), deployDirectory});
+ for (FileObject serviceArchive : serviceArchives) {
+ DeploymentRecord rec = new DeploymentRecord();
+ rec.fileObject = serviceArchive;
+ rec.name = serviceArchive.getName().getBaseName();
+ rec.updateTime = serviceArchive.getContent().getLastModifiedTime();
+ deployDirListing.put(rec.name, rec);
+ }
+ }
+ return deployDirListing;
+ }
+
+ private class ScanTask implements Runnable {
+
+ public void runOnce() {
+ try {
+ log.log(Level.FINER, MessageNames.SCANNING_DEPLOYMENT_DIRECTORY,
+ new Object[]{deployDirectory});
+ Map<String, DeploymentRecord> deployDirListing = scanDeploymentArchives();
+ // DeployDirListing will become the deployedServices collection
+ synchDeployedServices(deployedServices, deployDirListing);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public void run() {
+ runOnce();
+ deployer.workManager.schedule(null, this, scanInterval, TimeUnit.SECONDS);
+ }
+ }
+
+ private synchronized void synchDeployedServices(Map<String, DeploymentRecord> currentList,
+ Map<String, DeploymentRecord> newList) {
+ // For each entry
+ for (DeploymentRecord rec : newList.values()) {
+ // If it isn't already in deployedServices, start it
+ DeploymentRecord current = currentList.get(rec.name);
+ if (current == null) {
+ log.log(Level.FINE, MessageNames.STARTING_SERVICE,
+ new Object[]{rec.name});
+ currentList.put(rec.name, rec);
+ deployAndStart(rec);
+ } else if (current.updateTime != rec.updateTime) {
+ // If it's in deployedServices but now newer, stop and restart
+ log.log(Level.FINE, MessageNames.UPDATING_SERVICE,
+ new Object[]{rec.name});
+ currentList.remove(current.name);
+ stopAndRemove(current);
+ currentList.put(rec.name, rec);
+ deployAndStart(rec);
+ }
+ }
+ // If there are any services left in deployedServices, stop them
+ List<DeploymentRecord> removals = new ArrayList<DeploymentRecord>();
+ for (DeploymentRecord current : currentList.values()) {
+ if (!newList.containsKey(current.name)) {
+ removals.add(current);
+ }
+ }
+ for (DeploymentRecord current : removals) {
+ log.log(Level.FINE, MessageNames.STOPPING_SERVICE,
+ new Object[]{current.name});
+ currentList.remove(current.name);
+ stopAndRemove(current);
+ }
+
+ }
+
+ private void deployAndStart(DeploymentRecord dr) {
+ 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.
+ */
+ dr.serviceLifeCycle = deployer.deployServiceArchive(myName, dr.fileObject);
+ // Register it as an MBean
+ registerApplication(dr.serviceLifeCycle);
+ dr.serviceLifeCycle.start();
+ } catch (Throwable t) {
+ log.log(Level.WARNING, MessageNames.FAILED_DEPLOY_SERVICE, dr.name);
+ log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, Utils.stackTrace(t));
+ }
+
+ }
+
+ private void stopAndRemove(DeploymentRecord dr) {
+ dr.serviceLifeCycle.stop();
+ unregisterApplication(dr.serviceLifeCycle);
+ }
+
+ public synchronized List<ApplicationInfo> getApplicationInfo() {
+ List<ApplicationInfo> info=new ArrayList<ApplicationInfo>(deployedServices.size());
+ for (DeploymentRecord rec: deployedServices.values()) {
+ ApplicationInfo item=new ApplicationInfo(myName, rec.name, toApplicationStatus(rec.serviceLifeCycle));
+ info.add(item);
+ }
+ return info;
+ }
+
+ ApplicationStatus toApplicationStatus(ServiceLifeCycle lc) {
+ String status=lc.getStatus();
+ if (Strings.RUNNING.equals(status)) {
+ return ApplicationStatus.RUNNING;
+ }
+ if (Strings.IDLE.equals(status)) {
+ return ApplicationStatus.STOPPED;
+ }
+ if (Strings.FAILED.equals(status)) {
+ return ApplicationStatus.FAILED;
+ }
+ return ApplicationStatus.UNKNOWN;
+ }
+}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployer.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployer.java b/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployer.java
index 500bf90..8016c6a 100644
--- a/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployer.java
+++ b/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployer.java
@@ -73,7 +73,7 @@ import org.apache.river.container.work.WorkManager;
* Deployer that instantiates applications or services based on the
* com.sun.jini.starter API
*/
-public class StarterServiceDeployer implements StarterServiceDeployerMXBean {
+public class StarterServiceDeployer {
private static final Logger log
= Logger.getLogger(StarterServiceDeployer.class.getName(), MessageNames.BUNDLE_NAME);
@@ -276,13 +276,18 @@ public class StarterServiceDeployer implements StarterServiceDeployerMXBean {
Thread.currentThread().setContextClassLoader(env.getClassLoader());
File workingDir = null;
if (env.getServiceArchive() != null) {
- /* TODO: Is this right? Shouldn't the working directory be created
- by the file manager under the 'work' dir?
+ /* This variable, and the method we're calling on VirtualFileSystemConfiguration,
+ is named in an unfortunate manner for
+ historical reasons. What we're really doing here is telling the
+ VirtualFileSystemConfiguration where to read its configuration
+ file from. Iternally to VFSConfig, it's called the "root" directory.
+ It has nothing to do with the "working" directory where the service
+ should be allowed to write its own data.
*/
workingDir = new File(env.getServiceArchive().getURL().toURI());
} else {
workingDir = new File(env.getServiceArchive().getURL().toURI());
-
+
}
grantPermissions(env.getClassLoader(),
@@ -311,7 +316,16 @@ public class StarterServiceDeployer implements StarterServiceDeployerMXBean {
new Object[]{getConfig(), varName, contextVarName});
}
}
+
+ /*
+ One extra "special" variable is the File that gives the working directory.
+ */
+ invokeStatic(env.getClassLoader(), configName, Strings.PUT_SPECIAL_ENTRY,
+ new Class[]{String.class, Object.class},
+ Strings.DOLLAR + Strings.WORKING_DIRECTORY, env.getWorkingDirectory());
/* Install the Executor. */
+ log.log(Level.INFO, MessageNames.EXECUTOR_NAME_IS,
+ new Object[]{Strings.DOLLAR + Strings.EXECUTOR_NAME});
invokeStatic(env.getClassLoader(), configName,
Strings.PUT_SPECIAL_ENTRY,
new Class[]{String.class, Object.class
@@ -341,9 +355,10 @@ public class StarterServiceDeployer implements StarterServiceDeployerMXBean {
new Object[]{myName});
}
- public ServiceLifeCycle deployServiceArchive(FileObject serviceArchive) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
+ public ServiceLifeCycle deployServiceArchive(String managerName, FileObject serviceArchive) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
// Create an application environment
ApplicationEnvironment env = new ApplicationEnvironment();
+ env.setApplicationManagerName(managerName);
env.setServiceArchive(serviceArchive);
env.setServiceRoot(
serviceArchive.getFileSystem().getFileSystemManager().createFileSystem(Strings.JAR, serviceArchive));
@@ -398,6 +413,12 @@ public class StarterServiceDeployer implements StarterServiceDeployerMXBean {
grantPermissions(cl, perms);
/*
+ Create the service's working directory and grant permissions to it.
+ */
+ createWorkDirectoryFor(env);
+ grantPermissionsToWorkDirectoryFor(env);
+
+ /*
* Create a working context (work manager).
*/
env.setWorkingContext(contextualWorkManager.createContext(env.getServiceName(), env.getClassLoader()));
@@ -580,4 +601,21 @@ public class StarterServiceDeployer implements StarterServiceDeployerMXBean {
}
}
+
+ void createWorkDirectoryFor(ApplicationEnvironment env) throws IOException {
+ FileObject managerDir=fileUtility.getWorkingDirectory(env.getApplicationManagerName());
+ FileObject workingDir=managerDir.resolveFile(env.getServiceName());
+ if (!workingDir.exists()) {
+ workingDir.createFolder();
+ }
+ File workingDirFile=new File(workingDir.getName().getPath());
+ env.setWorkingDirectory(workingDirFile);
+ }
+
+ void grantPermissionsToWorkDirectoryFor(ApplicationEnvironment env) {
+ Permission[] perms=new Permission[] {
+ new FilePermission(env.getWorkingDirectory().getAbsolutePath()+"/-","read,write,delete")
+ };
+ grantPermissions(env.getClassLoader(), perms);
+ }
}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java b/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java
deleted file mode 100644
index b091746..0000000
--- a/river-container-core/src/main/java/org/apache/river/container/deployer/StarterServiceDeployerMXBean.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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;
-
-/**
- *
- * @author trasukg
- */
-public interface StarterServiceDeployerMXBean {
-
-}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/deployer/StartupDeployer.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/deployer/StartupDeployer.java b/river-container-core/src/main/java/org/apache/river/container/deployer/StartupDeployer.java
deleted file mode 100644
index 92c78ac..0000000
--- a/river-container-core/src/main/java/org/apache/river/container/deployer/StartupDeployer.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * 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.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanRegistrationException;
-import javax.management.MalformedObjectNameException;
-import javax.management.NotCompliantMBeanException;
-import javax.management.ObjectName;
-import org.apache.commons.vfs2.FileObject;
-import org.apache.commons.vfs2.FileSystemException;
-import org.apache.commons.vfs2.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 Map<String, DeploymentRecord> deployedServices = new HashMap<String, DeploymentRecord>();
-
- private class DeploymentRecord {
-
- String name;
- long updateTime;
- FileObject fileObject;
- ServiceLifeCycle serviceLifeCycle;
- }
-
- private boolean autoDeploy = false;
-
- public boolean isAutoDeploy() {
- return autoDeploy;
- }
-
- public void setAutoDeploy(boolean autoDeploy) {
- this.autoDeploy = autoDeploy;
- }
-
- public int getScanInterval() {
- return scanInterval;
- }
-
- public void setScanInterval(int scanInterval) {
- this.scanInterval = scanInterval;
- }
-
- private int scanInterval = 5;
-
- public String getDeployDirectory() {
- return deployDirectory;
- }
-
- public void setDeployDirectory(String deployDirectory) {
- this.deployDirectory = deployDirectory;
- }
-
- FileObject deploymentDirectoryFile = null;
-
- private String deployerName=null;
-
- public String getDeployerName() {
- return deployerName;
- }
-
- public void setDeployerName(String deployerName) {
- this.deployerName = deployerName;
- }
-
- @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);
- /*
- If the deployerName is supplied, look it up and override the injected deployer.
- */
- if(deployerName != null) {
- deployer=(StarterServiceDeployer) context.get(deployerName);
- }
- /*
- 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()});
- }
- /*
- Do the scan task once - this will launch all the services currently in
- deploy dir.
- */
- new ScanTask().runOnce();
-
- if (autoDeploy) {
- /* Now schedule a scan in the required scan time. */
- deployer.workManager.schedule(null, new ScanTask(), getScanInterval(), TimeUnit.SECONDS);
- }
- }
-
- 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);
- }
-
- private void unregisterApplication(ServiceLifeCycle deployedApp) {
- try {
- 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().unregisterMBean(oName);
- } catch (Exception e) {
- log.log(Level.SEVERE, MessageNames.FAILED_TO_REMOVE_MBEAN,
- new Object[]{deployedApp.getName()});
- }
- }
-
- private Map<String, DeploymentRecord> scanDeploymentArchives() throws FileSystemException {
- /*
- Go through the deployment directory looking for services to deploy.
- */
- Map<String, DeploymentRecord> deployDirListing = new HashMap<String, DeploymentRecord>();
- deploymentDirectoryFile.refresh();
- List<FileObject> serviceArchives
- = Utils.findChildrenWithSuffix(deploymentDirectoryFile,
- org.apache.river.container.Strings.JAR);
- if (serviceArchives != null) {
- log.log(Level.FINER, MessageNames.FOUND_SERVICE_ARCHIVES,
- new Object[]{serviceArchives.size(), deployDirectory});
- for (FileObject serviceArchive : serviceArchives) {
- DeploymentRecord rec = new DeploymentRecord();
- rec.fileObject = serviceArchive;
- rec.name = serviceArchive.getName().getBaseName();
- rec.updateTime = serviceArchive.getContent().getLastModifiedTime();
- deployDirListing.put(rec.name, rec);
- }
- }
- return deployDirListing;
- }
-
- private class ScanTask implements Runnable {
-
- public void runOnce() {
- try {
- log.log(Level.FINER, MessageNames.SCANNING_DEPLOYMENT_DIRECTORY,
- new Object[]{deployDirectory});
- Map<String, DeploymentRecord> deployDirListing = scanDeploymentArchives();
- // DeployDirListing will become the deployedServices collection
- synchDeployedServices(deployedServices, deployDirListing);
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
-
- public void run() {
- runOnce();
- deployer.workManager.schedule(null, this, scanInterval, TimeUnit.SECONDS);
- }
- }
-
- private void synchDeployedServices(Map<String, DeploymentRecord> currentList,
- Map<String, DeploymentRecord> newList) {
- // For each entry
- for (DeploymentRecord rec : newList.values()) {
- // If it isn't already in deployedServices, start it
- DeploymentRecord current = currentList.get(rec.name);
- if (current == null) {
- log.log(Level.FINE, MessageNames.STARTING_SERVICE,
- new Object[]{rec.name});
- currentList.put(rec.name, rec);
- deployAndStart(rec);
- } else if (current.updateTime != rec.updateTime) {
- // If it's in deployedServices but now newer, stop and restart
- log.log(Level.FINE, MessageNames.UPDATING_SERVICE,
- new Object[]{rec.name});
- currentList.remove(current.name);
- stopAndRemove(current);
- currentList.put(rec.name, rec);
- deployAndStart(rec);
- }
- }
- // If there are any services left in deployedServices, stop them
- List<DeploymentRecord> removals = new ArrayList<DeploymentRecord>();
- for (DeploymentRecord current : currentList.values()) {
- if (!newList.containsKey(current.name)) {
- removals.add(current);
- }
- }
- for (DeploymentRecord current : removals) {
- log.log(Level.FINE, MessageNames.STOPPING_SERVICE,
- new Object[]{current.name});
- currentList.remove(current.name);
- stopAndRemove(current);
- }
-
- }
-
- private void deployAndStart(DeploymentRecord dr) {
- 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.
- */
- dr.serviceLifeCycle = deployer.deployServiceArchive(dr.fileObject);
- // Register it as an MBean
- registerApplication(dr.serviceLifeCycle);
- dr.serviceLifeCycle.start();
- } catch (Throwable t) {
- log.log(Level.WARNING, MessageNames.FAILED_DEPLOY_SERVICE, dr.name);
- log.log(Level.WARNING, MessageNames.EXCEPTION_THROWN, Utils.stackTrace(t));
- }
-
- }
-
- private void stopAndRemove(DeploymentRecord dr) {
- dr.serviceLifeCycle.stop();
- unregisterApplication(dr.serviceLifeCycle);
- }
-}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/java/org/apache/river/container/deployer/Strings.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/java/org/apache/river/container/deployer/Strings.java b/river-container-core/src/main/java/org/apache/river/container/deployer/Strings.java
index 3f48d84..b7158f9 100644
--- a/river-container-core/src/main/java/org/apache/river/container/deployer/Strings.java
+++ b/river-container-core/src/main/java/org/apache/river/container/deployer/Strings.java
@@ -25,7 +25,10 @@ package org.apache.river.container.deployer;
public class Strings {
public static final String
EMPTY="",
+ FAILED="Failed",
+ IDLE="Idle",
LPAREN="(",
RPAREN=")",
+ RUNNING="Running",
SPACE=" ";
}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/resources/org/apache/river/container/Messages.properties
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/resources/org/apache/river/container/Messages.properties b/river-container-core/src/main/resources/org/apache/river/container/Messages.properties
index 2dcf8c2..f700f4a 100644
--- a/river-container-core/src/main/resources/org/apache/river/container/Messages.properties
+++ b/river-container-core/src/main/resources/org/apache/river/container/Messages.properties
@@ -57,6 +57,7 @@ createdThread=Created thread named ''{0}'' in thread group ''{1}''.
duplicateClasspath=Duplicate class path entry for id ''{0}''.
exceptionThrown=Exception thrown:\n{0}
exceptionWhileStopping=Exception thrown during stop operation:\n{0}
+executorNameIs=Executor name is ''{0}''.
failedCleanShutdown=Application ''{0}'' failed to shutdown cleanly, so we're interrupting it.
failedDeployService=Deployment of service archive at ''{0}'' failed.
failedReadProperties=Failed to read one or more properties files.
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/main/resources/org/apache/river/container/core-config.xml
----------------------------------------------------------------------
diff --git a/river-container-core/src/main/resources/org/apache/river/container/core-config.xml b/river-container-core/src/main/resources/org/apache/river/container/core-config.xml
index d4bb419..05db56a 100644
--- a/river-container-core/src/main/resources/org/apache/river/container/core-config.xml
+++ b/river-container-core/src/main/resources/org/apache/river/container/core-config.xml
@@ -55,6 +55,7 @@
lib/jsk-resources-${jsk-version}.jar
lib/regexp-1.3.jar
lib/river-hsm-${project.version}.jar
+ lib/admin-svc-api-${project.version}.jar
</cfg:classpath>
<!--cfg:component class="org.apache.river.container.ShowContextToConsole"/-->
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/river-container-core/src/test/java/org/apache/river/container/ContextTest.java
----------------------------------------------------------------------
diff --git a/river-container-core/src/test/java/org/apache/river/container/ContextTest.java b/river-container-core/src/test/java/org/apache/river/container/ContextTest.java
new file mode 100644
index 0000000..9d62ee3
--- /dev/null
+++ b/river-container-core/src/test/java/org/apache/river/container/ContextTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import org.apache.river.container.admin.api.ApplicationInfo;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author trasukg
+ */
+public class ContextTest {
+
+ Context UUT=new Context();
+
+ public ContextTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testGetByClass() {
+ UUT.put(new Object());
+ UUT.put(new Date());
+ ApplicationManager am=new ApplicationManager() {
+ public List<ApplicationInfo> getApplicationInfo() {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+ };
+ UUT.put(am);
+ Collection<ApplicationManager> ams=UUT.getAll(ApplicationManager.class);
+ assertEquals("Count of ApplicationManagers",1, ams.size());
+ assertEquals("ApplicationManagerInstance", am, ams.iterator().next());
+ }
+}
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/test-container/src/main/root/profile/client/config.xml
----------------------------------------------------------------------
diff --git a/test-container/src/main/root/profile/client/config.xml b/test-container/src/main/root/profile/client/config.xml
index 1c108d1..941d075 100644
--- a/test-container/src/main/root/profile/client/config.xml
+++ b/test-container/src/main/root/profile/client/config.xml
@@ -44,7 +44,7 @@
</cfg:component>
<!-- Deployer for 'service-starter'-style applications. -->
- <cfg:component class="org.apache.river.container.deployer.ClientAppDeployer">
+ <cfg:component class="org.apache.river.container.deployer.CommandLineAppRunner">
<cfg:property name="config" value="client-app.cfg"/>
<cfg:property name="deployDirectory" value="deploy"/>
</cfg:component>
http://git-wip-us.apache.org/repos/asf/river-container/blob/33855de2/test-container/src/main/root/profile/default/config.xml
----------------------------------------------------------------------
diff --git a/test-container/src/main/root/profile/default/config.xml b/test-container/src/main/root/profile/default/config.xml
index 06108ed..8525202 100644
--- a/test-container/src/main/root/profile/default/config.xml
+++ b/test-container/src/main/root/profile/default/config.xml
@@ -45,7 +45,7 @@
<!-- Deployer for applications that are in the 'deploy' directory
at startup. -->
- <cfg:component class="org.apache.river.container.deployer.StartupDeployer">
+ <cfg:component class="org.apache.river.container.deployer.FolderBasedAppRunner">
<cfg:property name="config" value="service-starter.cfg"/>
<cfg:property name="deployDirectory" value="deploy"/>
</cfg:component>