Skip to content

Commit 3a31940

Browse files
committed
Implement -a switch to helma launcher that allows to explicitly list applications to start, overriding the apps.properties file (application settings in the apps.properties file are still honored, though). Adapt start scripts to pass though additional arguments.
1 parent e12c90a commit 3a31940

File tree

6 files changed

+69
-36
lines changed

6 files changed

+69
-36
lines changed

src/helma/main/ApplicationManager.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public ApplicationManager(ResourceProperties props,
7979
* to create and start new applications.
8080
*/
8181
protected void checkForChanges() {
82-
if (props.lastModified() > lastModified) {
82+
if (props.lastModified() > lastModified && server.getApplicationsOption() == null) {
8383
try {
8484
for (Enumeration e = props.keys(); e.hasMoreElements();) {
8585
String appName = (String) e.nextElement();
@@ -152,18 +152,26 @@ public void stop(String appName) {
152152
*/
153153
public void startAll() {
154154
try {
155-
for (Enumeration e = props.keys(); e.hasMoreElements();) {
156-
String appName = (String) e.nextElement();
155+
String[] apps = server.getApplicationsOption();
156+
if (apps != null) {
157+
for (int i = 0; i < apps.length; i++) {
158+
AppDescriptor desc = new AppDescriptor(apps[i]);
159+
desc.start();
160+
}
161+
} else {
162+
for (Enumeration e = props.keys(); e.hasMoreElements();) {
163+
String appName = (String) e.nextElement();
157164

158-
if (appName.indexOf(".") == -1) {
159-
String appValue = props.getProperty(appName);
165+
if (appName.indexOf(".") == -1) {
166+
String appValue = props.getProperty(appName);
160167

161-
if (appValue != null && appValue.length() > 0) {
162-
appName = appValue;
163-
}
168+
if (appValue != null && appValue.length() > 0) {
169+
appName = appValue;
170+
}
164171

165-
AppDescriptor desc = new AppDescriptor(appName);
166-
desc.start();
172+
AppDescriptor desc = new AppDescriptor(appName);
173+
desc.start();
174+
}
167175
}
168176
}
169177

src/helma/main/JettyServer.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.net.URL;
2828
import java.net.InetSocketAddress;
2929
import java.io.IOException;
30+
import java.io.File;
3031

3132
public class JettyServer {
3233

@@ -36,11 +37,12 @@ public class JettyServer {
3637
// the AJP13 Listener, used for connecting from external webserver to servlet via JK
3738
protected AJP13Listener ajp13;
3839

39-
public static JettyServer init(Server server) throws IOException {
40-
if (server.configFile != null && server.configFile.exists()) {
41-
return new JettyServer(server.configFile.toURI().toURL());
42-
} else if (server.websrvPort != null || server.ajp13Port != null) {
43-
return new JettyServer(server.websrvPort, server.ajp13Port, server);
40+
public static JettyServer init(Server server, ServerConfig config) throws IOException {
41+
File configFile = config.getConfigFile();
42+
if (configFile != null && configFile.exists()) {
43+
return new JettyServer(configFile.toURI().toURL());
44+
} else if (config.hasWebsrvPort() || config.hasAjp13Port()) {
45+
return new JettyServer(config.getWebsrvPort(), config.getAjp13Port(), server);
4446
}
4547
return null;
4648
}

src/helma/main/Server.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,9 @@ public class Server implements Runnable {
6666
private Vector extensions;
6767
private Thread mainThread;
6868

69-
// server ports
70-
InetSocketAddress rmiPort = null;
71-
InetSocketAddress xmlrpcPort = null;
72-
InetSocketAddress websrvPort = null;
73-
InetSocketAddress ajp13Port = null;
74-
75-
// Jetty configuration file
76-
File configFile = null;
77-
69+
// configuration
70+
ServerConfig config;
71+
7872
// map of server-wide database sources
7973
Hashtable dbSources;
8074

@@ -97,12 +91,11 @@ public Server(ServerConfig config) {
9791
server = this;
9892
starttime = System.currentTimeMillis();
9993

100-
rmiPort = config.getRmiPort();
101-
xmlrpcPort = config.getXmlrpcPort();
102-
websrvPort = config.getWebsrvPort();
103-
ajp13Port = config.getAjp13Port();
94+
this.config = config;
10495
hopHome = config.getHomeDir();
105-
configFile = config.getConfigFile();
96+
if (hopHome == null) {
97+
throw new RuntimeException("helma.home property not set");
98+
}
10699

107100
// create system properties
108101
sysProps = new ResourceProperties();
@@ -243,6 +236,8 @@ public static void parseArgs(ServerConfig config, String[] args) throws Exceptio
243236
config.setHomeDir(new File(args[++i]));
244237
} else if (args[i].equals("-f") && ((i + 1) < args.length)) {
245238
config.setPropFile(new File(args[++i]));
239+
} else if (args[i].equals("-a") && ((i + 1) < args.length)) {
240+
config.setApps(StringUtils.split(args[++i]));
246241
} else if (args[i].equals("-p") && ((i + 1) < args.length)) {
247242
try {
248243
config.setRmiPort(getInetSocketAddress(args[++i]));
@@ -333,8 +328,9 @@ public static void printUsageError() {
333328
System.out.println("");
334329
System.out.println("Usage: java helma.main.Server [options]");
335330
System.out.println("Possible options:");
336-
System.out.println(" -h dir Specify hop home directory");
337-
System.out.println(" -f file Specify server.properties file");
331+
System.out.println(" -a app[,...] Specify applications to start");
332+
System.out.println(" -h dir Specify hop home directory");
333+
System.out.println(" -f file Specify server.properties file");
338334
System.out.println(" -c jetty.xml Specify Jetty XML configuration file");
339335
System.out.println(" -w [ip:]port Specify embedded web server address/port");
340336
System.out.println(" -x [ip:]port Specify XML-RPC address/port");
@@ -478,7 +474,7 @@ public void init() throws IOException {
478474
if (sysProps.getProperty("extensions") != null) {
479475
initExtensions();
480476
}
481-
jetty = JettyServer.init(this);
477+
jetty = JettyServer.init(this, config);
482478
}
483479

484480

@@ -562,7 +558,8 @@ public void shutdown() {
562558
*/
563559
public void run() {
564560
try {
565-
if (xmlrpcPort != null) {
561+
if (config.hasXmlrpcPort()) {
562+
InetSocketAddress xmlrpcPort = config.getXmlrpcPort();
566563
String xmlparser = sysProps.getProperty("xmlparser");
567564

568565
if (xmlparser != null) {
@@ -591,7 +588,8 @@ public void run() {
591588
logger.info("Starting XML-RPC server on port " + (xmlrpcPort));
592589
}
593590

594-
if (rmiPort != null) {
591+
if (config.hasRmiPort()) {
592+
InetSocketAddress rmiPort = config.getRmiPort();
595593
if (paranoid) {
596594
HelmaSocketFactory factory = new HelmaSocketFactory();
597595
String rallow = sysProps.getProperty("allowWeb");
@@ -731,6 +729,14 @@ public File getHopHome() {
731729
return hopHome;
732730
}
733731

732+
/**
733+
* Get the explicit list of apps if started with -a option
734+
* @return
735+
*/
736+
public String[] getApplicationsOption() {
737+
return config.getApps();
738+
}
739+
734740
/**
735741
* Get the main Server instance.
736742
*/

src/helma/main/ServerConfig.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ public class ServerConfig {
3232
private File propFile = null;
3333
private File homeDir = null;
3434
private File configFile = null;
35+
private String[] apps = null;
3536

3637
public boolean hasPropFile() {
3738
return (propFile != null);
3839
}
3940

41+
public boolean hasConfigFile() {
42+
return (configFile != null);
43+
}
44+
4045
public boolean hasHomeDir() {
4146
return (homeDir != null);
4247
}
@@ -57,6 +62,10 @@ public boolean hasAjp13Port() {
5762
return (ajp13Port != null);
5863
}
5964

65+
public boolean hasApps() {
66+
return (apps != null);
67+
}
68+
6069
public InetSocketAddress getRmiPort() {
6170
return rmiPort;
6271
}
@@ -112,4 +121,12 @@ public File getConfigFile() {
112121
public void setConfigFile(File configFile) {
113122
this.configFile = configFile == null ? null : configFile.getAbsoluteFile();
114123
}
124+
125+
public String[] getApps() {
126+
return apps;
127+
}
128+
129+
public void setApps(String[] apps) {
130+
this.apps = apps;
131+
}
115132
}

start.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ if not "%HOP_HOME%"=="" (
7676
)
7777

7878
:: Invoking the Java virtual machine
79-
%JAVACMD% %JAVA_OPTIONS% -jar "%INSTALL_DIR%\launcher.jar" %OPTIONS%
79+
%JAVACMD% %JAVA_OPTIONS% -jar "%INSTALL_DIR%\launcher.jar" %OPTIONS% %*

start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ if [ "$HOP_HOME" ]; then
7575
fi
7676

7777
# Invoke the Java VM
78-
$JAVACMD $JAVA_OPTIONS -jar "$INSTALL_DIR/launcher.jar" $SWITCHES
78+
$JAVACMD $JAVA_OPTIONS -jar "$INSTALL_DIR/launcher.jar" $SWITCHES $*

0 commit comments

Comments
 (0)