jfclere 2003/09/27 08:45:03
Modified: daemon/src/samples README.txt build.xml
Added: daemon/src/samples AloneDaemon.sh AloneService.java
Log:
Add a new example. That does not use the Daemon interface.
Revision Changes Path
1.2 +5 -1 jakarta-commons/daemon/src/samples/README.txt
Index: README.txt
===================================================================
RCS file: /home/cvs/jakarta-commons/daemon/src/samples/README.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- README.txt 4 Sep 2003 23:28:20 -0000 1.1
+++ README.txt 27 Sep 2003 15:45:02 -0000 1.2
@@ -30,4 +30,8 @@
router2=/home/Standard/router/smtp smtp.example.net
socks5=/usr/local/bin/socks5 -f
-To run it adapt the ServiceDaemon.sh file.
+To run it adapt the ServiceDaemon.sh file.
+
+AloneService:
+
+AloneService is like ServiceDaemon except it does not use the Daemon interface.
1.3 +14 -1 jakarta-commons/daemon/src/samples/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/daemon/src/samples/build.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- build.xml 26 Sep 2003 21:15:24 -0000 1.2
+++ build.xml 27 Sep 2003 15:45:02 -0000 1.3
@@ -8,7 +8,7 @@
<property name="source.home" value="."/>
<property name="commons-collections.jar"
value="${user.home}/commons-collections-2.1/commons-collections.jar"/>
- <target name="jars" depends="SimpleDaemon,ServiceDaemon"/>
+ <target name="jars" depends="SimpleDaemon,ServiceDaemon,AloneService"/>
<target name="SimpleDaemon" depends="compile"
description="Create SimpleDaemon.jar">
@@ -36,6 +36,19 @@
</jar>
</target>
+ <target name="AloneService" depends="compile"
+ description="Create aloneservice.jar">
+ <mkdir dir="${dist.home}"/>
+ <mkdir dir="${build.home}/classes/META-INF"/>
+ <copy file="../../../LICENSE"
+ tofile="${build.home}/classes/META-INF/LICENSE.txt"/>
+ <jar jarfile="${dist.home}/aloneservice.jar">
+ <fileset dir="${build.home}/classes">
+ <include name="AloneService*.class" />
+ <include name="ServiceDaemonReadThread*.class" />
+ </fileset>
+ </jar>
+ </target>
<target name="compile" depends="prepare"
description="Create class files">
1.1 jakarta-commons/daemon/src/samples/AloneDaemon.sh
Index: AloneDaemon.sh
===================================================================
#!/bin/sh
#
# Small shell script to show how to start the sample services.
# That is for linux, if your are using cygwin look to ServiceDaemon.sh.
#
# Adapt the following lines to your configuration
JAVA_HOME=`echo $JAVA_HOME`
DAEMON_HOME=`(cd ../..; pwd)`
USER_HOME=`(cd ../../../..; pwd)`
TOMCAT_USER=`echo $USER`
CLASSPATH=\
$DAEMON_HOME/dist/commons-daemon.jar:\
$USER_HOME/commons-collections-2.1/commons-collections.jar:\
$DAEMON_HOME/dist/aloneservice.jar
$DAEMON_HOME/src/native/unix/jsvc \
-home $JAVA_HOME \
-cp $CLASSPATH \
-pidfile ./pidfile \
-debug \
AloneService
#
# To get a verbose JVM
#-verbose \
# To get a debug of jsvc.
#-debug \
# -user $TOMCAT_USER \
1.1 jakarta-commons/daemon/src/samples/AloneService.java
Index: AloneService.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999-2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* notice, this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: *
* *
* "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." *
* *
* Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. *
* *
* 4. The names "The Jakarta Project", "WebApp", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written *
* permission, please contact <[EMAIL PROTECTED]>. *
* *
* 5. Products derived from this software may not be called "Apache" nor may *
* "Apache" appear in their names without prior written permission of the *
* Apache Software Foundation. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *
* *
* This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
/* @version $Id: AloneService.java,v 1.1 2003/09/27 15:45:02 jfclere Exp $ */
import java.io.*;
import java.net.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import org.apache.commons.collections.ExtendedProperties;
import java.io.IOException;
import java.util.Iterator;
/*
* That is like the ServiceDaemon but it does used the interface.
*/
public class AloneService {
private ExtendedProperties prop = null;
private Process proc[] = null;
private ServiceDaemonReadThread readout[] = null;
private ServiceDaemonReadThread readerr[] = null;
protected void finalize() {
System.err.println("ServiceDaemon: instance "+this.hashCode()+
" garbage collected");
}
/**
* init and destroy were added in jakarta-tomcat-daemon.
*/
public void init(String[] arguments)
throws Exception {
/* Set the err */
System.setErr(new PrintStream(new FileOutputStream(new
File("/ServiceDaemon.err"),true)));
System.err.println("ServiceDaemon: instance "+this.hashCode()+
" init");
/* read the properties file */
prop = new ExtendedProperties("startfile");
/* create an array to store the processes */
int i=0;
for (Iterator e = prop.getKeys(); e.hasNext() ;) {
e.next();
i++;
}
System.err.println("ServiceDaemon: init for " + i + " processes");
proc = new Process[i];
readout = new ServiceDaemonReadThread[i];
readerr = new ServiceDaemonReadThread[i];
for (i=0;i<proc.length;i++) {
proc[i] = null;
readout[i] = null;
readerr[i] = null;
}
System.err.println("ServiceDaemon: init done ");
}
public void start() {
/* Dump a message */
System.err.println("ServiceDaemon: starting");
/* Start */
int i=0;
for (Iterator e = prop.getKeys(); e.hasNext() ;) {
String name = (String) e.next();
System.err.println("ServiceDaemon: starting: " + name + " : " +
prop.getString(name));
try {
proc[i] = Runtime.getRuntime().exec(prop.getString(name));
} catch(Exception ex) {
System.err.println("Exception: " + ex);
}
/* Start threads to read from Error and Out streams */
readerr[i] =
new ServiceDaemonReadThread(proc[i].getErrorStream());
readout[i] =
new ServiceDaemonReadThread(proc[i].getInputStream());
readerr[i].start();
readout[i].start();
i++;
}
}
public void stop()
throws IOException, InterruptedException {
/* Dump a message */
System.err.println("ServiceDaemon: stopping");
for (int i=0;i<proc.length;i++) {
if ( proc[i]==null)
continue;
proc[i].destroy();
try {
proc[i].waitFor();
} catch(InterruptedException ex) {
System.err.println("ServiceDaemon: exception while stopping:" +
ex);
}
}
System.err.println("ServiceDaemon: stopped");
}
public void destroy() {
System.err.println("ServiceDaemon: instance "+this.hashCode()+
" destroy");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]