pier 00/11/22 11:26:12
Added: service README
service/native jsvc.h jsvc_help.c jsvc_parse.c
jsvc_service.c jsvc_unix.c
service/native/windows menu-quit.bmp menu-restart.bmp
menu-start.bmp menu-stop.bmp tomcat.ico
tray-default.ico tray-running.ico tray-stopped.ico
service/share/org/apache/service Service.java
ServiceException.java ServiceManager.java
service/share/org/apache/service/helpers
NativeServiceHelper.java NativeServiceManager.java
SimpleService.java
Log:
Added new "service" package (more structured version of the old invocation)
Revision Changes Path
1.1 jakarta-tomcat-4.0/service/README
Index: README
===================================================================
-------------------------------------------------------------------------
APACHE INVOCATION README
-------------------------------------------------------------------------
Abstract:
---------
Invocation is an abstraction of a generic invocation mechanism for
Java based services. It is composed of two major parts: a set of Java
classes (interfaces and exceptions) to be implemented by the service
provider, and some native code dealing with the underlying operating
system, accessing to the service thru JNI.
The Java portion of Invocation:
-------------------------------
While the usual main(String args[]) method is well suited for generic
applications, having only one entry point when developing networked
services is not enough.
In UNIX based operating systems, for example, a set of signals to be
sent to running processes expands the invocation paradigm, so that,
after the service process is usually started with a call to the
main(int argc, char *argv[]) function, signal handling provides
alternate ways to trigger events inside the process.
For example, it usually happens that UNIX daemons upon reception of
the HUP signal, the service is stopper, configuration are re-read
from disk, and the service is started againg with the new
configurations, or, upon reception of a TERM signal, the service is
stopped (freeing all resources allocated) and the process is
terminated.
The org.apache.invocation.InvocationAbstraction interface works in
the same way. It defines three major entry points:
- start(String args[]) is the parallel to the main(String args[])
method used by applications. Command line
parameters are passed to the instance and the
service is started.
- restart() this method is called when the service must be stopped,
configurations re-read from the disk, and the service
brought back on line with the new configuration. It's
behaviour is similar to the usual behaviour of the HUP
signal in unix daemons.
- stop() this method is called before the Java VM is terminated. The
service should release all resources allocated during its
execution, save temporary data, and be prepared to exit.
It's behaviour is similar to the usual behaviour of the
TERM signal in unix daemons.
For more information on the behaviour of those methods and how they
work, please consult the JavaDOC documentation included into the
org.apache.invocation package.
The native portion of Invocation:
---------------------------------
The native portion of Invocation is made of two major components:
A system-indipendant library based on JNI handling the creation and
destruction of the Java Virtual Machine, and providing an easy way to
access to the service start(String argv[]), restart() and stop()
methods as described above.
An Operating-System dependant set of sources dealing with calls from
the underlying operating system:
- in UNIX operating systems we listen for TERM and HUP sinals, and
appropriate calls are made in the system-indipendant library to
access to the appropriate Java method in the service. This will
make the Java service behave like a standard UNIX daemon.
- in Microsoft Windows operating systems we provide two different
modes of operation: a GUI based one that will allow the user to
access to the above-mentioned methods thru a standard tray-icon
menu (there's no console allocated for the Java Process, wich is
for most of us Windows users a major pain). Another mode to operate
under Windows is thru the Win32 Service API (WinNT and Win2K only)
thru the standard Control-Panel Service tab.
Future Plans:
-------------
Fix, debug and correct (that's the first major issue), and think
about ports to different operating systems (MacOS/9, IBM...).
-------------------------------------------------------------------------
Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
$Revision: 1.1 $ $Date: 2000/11/22 19:26:04 $
-------------------------------------------------------------------------
1.1 jakarta-tomcat-4.0/service/native/jsvc.h
Index: jsvc.h
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 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", "Tomcat", 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/>. *
* *
* ========================================================================= */
#ifndef _JSVC_H_
#define _JSVC_H_
#include <sys/systeminfo.h>
#include <strings.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <jni.h>
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef int boolean;
#define JSVC_VERSION_NO 0 // Don't show any version information
#define JSVC_VERSION_EXIT 1 // Show version information and exit
#define JSVC_VERSION_SHOW 2 // Show version information and continue
#define JSVC_MARK __FILE__, __LINE__ // Marker for debug information
/* ********************************************* */
/* The main Java Service configuration structure */
/* ********************************************* */
typedef struct jsvc_config {
char *binary; // The name of the binary file
char *root; // The root path of jservice
char *home; // The root path of the JDK or JRE
char *vm; // The Java Virtual Machine name
char *parfile; // The default file where command line params are read
#ifndef WIN32
char *pidfile; // The default file where the PID is written
char *user; // The user name of the JVM process
char *group; // The group name of the JVM process
boolean detach; // Wether to detach and fork in background or not
#endif
int showversion; // How to handle version display (no, show, show/exit)
char *class; // The class to execute
int vmargc; // The number of arguments in vmargv
char *vmargv[1024]; // The java virtual machine command line arguments
int clargc; // The number of arguments in clargv
char *clargv[1024]; // The class command line arguments
JavaVM *jnivm; // The pointer to the Java Virtual Machine
JNIEnv *jnienv; // The pointer to the Java Native Interface Environment
jclass jniclass; // The helper class accessed thru JNI
} jsvc_config;
/* ***************************************************** */
/* The native service helper and service manager classes */
/* ***************************************************** */
#define JSVC_HELPER "org.apache.service.helpers.NativeServiceHelper"
#define JSVC_MANAGER "org.apache.service.helpers.NativeServiceManager"
/* ********************** */
/* Defined in jsvc_help.c */
/* ********************** */
// Display the standard help message
int jsvc_help(jsvc_config *);
/* *********************** */
/* Defined in jsvc_parse.c */
/* *********************** */
// Parse command line options and return a jsvc_config pointer or null
jsvc_config *jsvc_parse(char *, char *, char *, int, char **);
// Parse one single command line argument
boolean jsvc_parse_argument(char *, jsvc_config *);
// Parse command line arguments from a file
boolean jsvc_parse_file(char *, jsvc_config *);
/* **************************************** */
/* Defined in jsvc_unix.c or jsvc_windows.c */
/* **************************************** */
// System dependand virtual machine creation
boolean jsvc_createvm(jsvc_config *);
// System dependant error display
void jsvc_error(const char *, int, const char *, ...);
// Used for dumping debug information
void jsvc_debug(const char *, int, const char *, ...);
/* ************************* */
/* Defined in jsvc_service.c */
/* ************************* */
// Register native methods and retrieve the native service helper class
boolean jsvc_prepare(jsvc_config *);
// Display version information depending on jsvc_config.showversion
boolean jsvc_version(jsvc_config *);
// Initialize the service
boolean jsvc_init(jsvc_config *);
// Starts the service
boolean jsvc_start(jsvc_config *);
// Restarts the service
boolean jsvc_restart(jsvc_config *);
// Stop the service
boolean jsvc_stop(jsvc_config *);
#endif // #ifndef _JSVC_H_
1.1 jakarta-tomcat-4.0/service/native/jsvc_help.c
Index: jsvc_help.c
===================================================================
#include <jsvc.h>
int jsvc_help(jsvc_config *config) {
printf("Usage: %s [@file] [-options] class [args...]\n",config->binary);
printf("\n");
printf("Where options include:\n");
printf("\n");
printf(" @[file]\n");
printf(" read command line options from the specified file\n");
printf(" if [file] wasn't specified, or there were no other\n");
printf(" arguments specified on the command line, the default\n");
printf(" default arguments are read from the default file:\n");
printf(" %s\n",config->parfile);
printf("\n");
printf(" -h, -? or -help\n");
printf(" print this help message and exit\n");
printf("\n");
printf(" -vm:[server|client|<jvm>]\n");
printf(" select the server, client or another virtual machine,\n");
printf(" where <jvm> is the name of the virtual machine to be\n");
printf(" used\n");
printf("\n");
printf(" -cp <classpath> or -classpath <classpath>\n");
printf(" set search path for application classes and resources\n");
printf(" this is equal to -Djava.class.path=<classpath> where\n");
printf(" <classpath> is a list of directories and/or jar/zip\n");
printf(" files separated by \":\"\n");
printf(" (example: -classpath /usr/java/lib:/home/user/lib.jar)\n");
printf("\n");
printf(" -verbose:[class|gc|jni]\n");
printf(" enable verbose options\n");
printf(" multiple options can be separated with \",\"\n");
printf(" (example: -verbose:class,gc)\n");
printf("\n");
printf(" -version\n");
printf(" print product version and exit\n");
printf("\n");
printf(" -showversion\n");
printf(" print product version and continue\n");
printf("\n");
#ifndef WIN32
printf(" -user:<username>\n");
printf(" change the user of the virtual machine process after\n");
printf(" startup\n");
printf("\n");
printf(" -group:<username>\n");
printf(" change the group of the virtual machine process after\n");
printf(" startup\n");
printf("\n");
printf(" -pidfile:<file>\n");
printf(" specify the file name where the pid will be written to\n");
printf(" this option is ignored in case -nodetach is specified\n");
printf(" (default: %s)\n",config->pidfile);
printf("\n");
printf(" -nodetach\n");
printf(" don't detach from the console and fork in background\n");
printf(" after initialization\n");
printf("\n");
#endif
printf(" -D<name>=<value>\n");
printf(" set a system property\n");
printf("\n");
printf(" -X<...>\n");
printf(" set a non standard java virtual machine option\n");
printf(" to check what non standard options your java virtual\n");
printf(" supports try to invoke \"java -X\"\n");
printf("\n");
}
1.1 jakarta-tomcat-4.0/service/native/jsvc_parse.c
Index: jsvc_parse.c
===================================================================
#include <jsvc.h>
// Temporary variable used to process the classpath entry
static boolean classpath=FALSE;
jsvc_config *jsvc_parse(char *b, char *r, char *h, int argc, char *argv[]) {
jsvc_config *config=(jsvc_config *)malloc(sizeof(jsvc_config));
char *buffer=(char *)malloc(PATH_MAX*sizeof(char));
int x=0;
// Fill the first element of the configuration structure
if (b==NULL) {
jsvc_error(JSVC_MARK, "Binary filename unspecified");
return(NULL);
} else config->binary=strdup(b);
if (r==NULL) {
jsvc_error(JSVC_MARK, "Default configuration filename unspecified");
return(NULL);
} else config->root=strdup(r);
if (h==NULL) {
jsvc_error(JSVC_MARK, "Virtual machine home path unspecified");
return(NULL);
} else config->home=strdup(h);
config->vm=NULL;
sprintf(buffer, "%s/%s.conf", config->root, config->binary);
config->parfile=strdup(buffer);
#ifndef WIN32
sprintf(buffer, "%s/%s.pid", config->root, config->binary);
config->pidfile=strdup(buffer);
config->user=NULL;
config->group=NULL;
config->detach=TRUE;
#endif
config->showversion=JSVC_VERSION_NO;
config->class=NULL;
config->vmargc=0;
config->vmargv[0]=NULL;
config->clargc=0;
config->clargv[0]=NULL;
// Check if we have some parameters on command line (otherwise parse
// default config file)
if (argc==0) {
// We don't have any command line argument, parse the default file
if (!jsvc_parse_file("",config)) return(NULL);
} else {
// We have some command line arguments, parse them one by one
for (x=0; x<argc; x++)
if (!jsvc_parse_argument(argv[x], config)) return(NULL);
}
return(config);
}
boolean jsvc_parse_argument(char *a, jsvc_config *conf) {
if (a==NULL) {
jsvc_error(JSVC_MARK, "Null argument specified");
return(FALSE);
}
jsvc_debug(JSVC_MARK,"Command line arg: \"%s\" Classpath: %d",a,classpath);
if (a[0]=='@') {
jsvc_debug(JSVC_MARK,"Reading command lines from \"%s\"",a+1);
return(jsvc_parse_file(a+1,conf));
}
if (conf->class!=NULL) {
jsvc_debug(JSVC_MARK,"Class specific command line argument \"%s\"",a);
conf->clargv[conf->clargc++]=strdup(a);
return(TRUE);
}
if (classpath) {
jsvc_debug(JSVC_MARK, "Class path argument: \"%s\"",a);
classpath=FALSE;
conf->vmargv[conf->vmargc]=(char *)malloc((strlen(a)+20)*sizeof(char));
sprintf(conf->vmargv[conf->vmargc],"-Djava.class.path=%s",a);
conf->vmargc++;
return(TRUE);
}
if ((strcmp(a,"-help")==0)||(strcmp(a,"-h")==0)||(strcmp(a,"-?")==0)) {
jsvc_debug(JSVC_MARK,"Display help screen");
jsvc_help(conf);
exit(0);
}
if ((strcmp(a,"-cp")==0)||(strcmp(a,"-classpath")==0)) {
jsvc_debug(JSVC_MARK,"Setup classpath from next argument");
classpath=TRUE;
return(TRUE);
}
if (strcmp(a,"-version")==0) {
jsvc_debug(JSVC_MARK,"Display version information and exit");
conf->showversion=JSVC_VERSION_EXIT;
return(TRUE);
}
if (strcmp(a,"-showversion")==0) {
jsvc_debug(JSVC_MARK,"Display version information and continue");
conf->showversion=JSVC_VERSION_SHOW;
return(TRUE);
}
if (strstr(a,"-verbose")==a) {
jsvc_debug(JSVC_MARK,"Enabling verbose output");
conf->vmargv[conf->vmargc++]=strdup(a);
return(TRUE);
}
if (strstr(a,"-D")==a) {
jsvc_debug(JSVC_MARK,"Adding system property \"%s\"",a+2);
conf->vmargv[conf->vmargc++]=strdup(a);
return(TRUE);
}
if (strstr(a,"-vm:")==a) {
jsvc_debug(JSVC_MARK,"Setting virtual machine to \"%s\"",a+4);
conf->vm=strdup(a+4);
return(TRUE);
}
if (strstr(a,"-X")==a) {
jsvc_debug(JSVC_MARK,"Non standard vm option \"%s\"",a);
conf->vmargv[conf->vmargc++]=strdup(a);
return(TRUE);
}
#ifndef WIN32
if (strcmp(a,"-nodetach")==0) {
jsvc_debug(JSVC_MARK,"Don't detach and fork in background");
conf->detach=FALSE;
return(TRUE);
}
if (strstr(a,"-user:")==a) {
jsvc_debug(JSVC_MARK,"Setting process user to \"%s\"",a+6);
conf->user=strdup(a+6);
return(TRUE);
}
if (strstr(a,"-group:")==a) {
jsvc_debug(JSVC_MARK,"Setting process group to \"%s\"",a+6);
conf->group=strdup(a+6);
return(TRUE);
}
#endif
if (a[0]=='-') {
jsvc_error(JSVC_MARK,"Unknown command line argument %s",a);
return(FALSE);
}
conf->class=strdup(a);
return(TRUE);
}
boolean jsvc_parse_file(char *f, jsvc_config *conf) {
char *filename=f;
if (filename==NULL) {
jsvc_error(JSVC_MARK, "Null filename specified");
return(FALSE);
}
if (strlen(filename)==0) filename=conf->parfile;
jsvc_error(JSVC_MARK, "Cannot read parameters from \"%s\"", filename);
jsvc_error(JSVC_MARK, "Method not implemented");
return(FALSE);
}
1.1 jakarta-tomcat-4.0/service/native/jsvc_service.c
Index: jsvc_service.c
===================================================================
#include <jsvc.h>
void jsvc_log(JNIEnv *env, jobject obj, jstring msg) {
jboolean copy=JNI_TRUE;
const char *message=(*env)->GetStringUTFChars(env, msg, ©);
jsvc_error(JSVC_MARK, message);
(*env)->ReleaseStringUTFChars(env, msg, message);
}
boolean jsvc_prepare(jsvc_config *cfg) {
JNINativeMethod log;
jmethodID method;
jstring name;
jclass class;
jboolean ret;
jobjectArray arg;
int x;
// Register the native logging method for messages
jsvc_debug(JSVC_MARK, "Registering natives");
log.name="log";
log.signature="(Ljava/lang/String;)V";
log.fnPtr=jsvc_log;
class=(*cfg->jnienv)->FindClass(cfg->jnienv, JSVC_MANAGER);
if (class==NULL) {
jsvc_error(JSVC_MARK, "Cannot find class \"%s\"",JSVC_MANAGER);
return(FALSE);
}
if ((*cfg->jnienv)->RegisterNatives(cfg->jnienv,class,&log,1)!=0) {
jsvc_error(JSVC_MARK, "Can't register native methods");
return(FALSE);
}
// Try to get a hold on the service helper class
jsvc_debug(JSVC_MARK, "Resolving class \"%s\"",JSVC_HELPER);
cfg->jniclass=(*cfg->jnienv)->FindClass(cfg->jnienv, JSVC_HELPER);
if (cfg->jniclass==NULL) {
jsvc_error(JSVC_MARK, "Cannot find class \"%s\"",JSVC_HELPER);
return(FALSE);
}
return(TRUE);
}
boolean jsvc_version(jsvc_config *cfg) {
JNINativeMethod log;
jmethodID method;
jstring name;
jboolean ret;
jobjectArray arg;
int x;
if (cfg->showversion==JSVC_VERSION_NO) return(TRUE);
// Retrieve the version static method in the helper class
jsvc_debug(JSVC_MARK, "Locating version method in \"%s\"",JSVC_HELPER);
method=(*cfg->jnienv)->GetStaticMethodID(cfg->jnienv,cfg->jniclass,"version","()V");
if (method==NULL) {
jsvc_error(JSVC_MARK, "Cannot locate version method");
return(FALSE);
}
// Call the init method in the helper class
jsvc_debug(JSVC_MARK, "Calling version method in \"%s\"",JSVC_HELPER);
(*cfg->jnienv)->CallStaticBooleanMethod(cfg->jnienv, cfg->jniclass, method);
// Normalize the return value (just in case)
if (cfg->showversion==JSVC_VERSION_EXIT) return(FALSE);
if (cfg->showversion==JSVC_VERSION_SHOW) return(TRUE);
jsvc_error(JSVC_MARK, "Unknown value for showversion %d",cfg->showversion);
return(FALSE);
}
boolean jsvc_init(jsvc_config *cfg) {
JNINativeMethod log;
jmethodID method;
jstring name;
jclass class;
jboolean ret;
jobjectArray arg;
int x;
// Retrieve the init static method in the helper class
jsvc_debug(JSVC_MARK, "Locating init method in \"%s\"",JSVC_HELPER);
method=(*cfg->jnienv)->GetStaticMethodID(cfg->jnienv,cfg->jniclass,"init",
"(Ljava/lang/String;[Ljava/lang/String;)Z");
if (method==NULL) {
jsvc_error(JSVC_MARK, "Cannot locate init method");
return(FALSE);
}
// Prepare a string containing the class name of the service
name=(*cfg->jnienv)->NewStringUTF(cfg->jnienv, cfg->class);
// Prepare an array of strings with the command line options
arg=(*cfg->jnienv)->NewObjectArray(cfg->jnienv, cfg->clargc,
(*cfg->jnienv)->FindClass(cfg->jnienv, "java/lang/String"),NULL);
for (x=0; x< cfg->clargc; x++)
(*cfg->jnienv)->SetObjectArrayElement(cfg->jnienv, arg, x,
(*cfg->jnienv)->NewStringUTF(cfg->jnienv, cfg->clargv[x]));
// Call the init method in the helper class
jsvc_debug(JSVC_MARK, "Calling init method in \"%s\"",JSVC_HELPER);
ret=(*cfg->jnienv)->CallStaticBooleanMethod(cfg->jnienv, cfg->jniclass, method,
name, arg);
// Normalize the return value (just in case)
if (ret) return(TRUE);
else return(FALSE);
}
boolean jsvc_start(jsvc_config *cfg) {
JNINativeMethod log;
jmethodID method;
jstring name;
jboolean ret;
jobjectArray arg;
int x;
// Retrieve the start static method in the helper class
jsvc_debug(JSVC_MARK, "Locating start method in \"%s\"",JSVC_HELPER);
method=(*cfg->jnienv)->GetStaticMethodID(cfg->jnienv,cfg->jniclass,"start","()Z");
if (method==NULL) {
jsvc_error(JSVC_MARK, "Cannot locate start method");
return(FALSE);
}
// Call the init method in the helper class
jsvc_debug(JSVC_MARK, "Calling start method in \"%s\"",JSVC_HELPER);
ret=(*cfg->jnienv)->CallStaticBooleanMethod(cfg->jnienv, cfg->jniclass, method);
// Normalize the return value (just in case)
if (ret) return(TRUE);
else return(FALSE);
}
boolean jsvc_restart(jsvc_config *cfg) {
JNINativeMethod log;
jmethodID method;
jstring name;
jboolean ret;
jobjectArray arg;
int x;
// Retrieve the restart static method in the helper class
jsvc_debug(JSVC_MARK, "Locating restart method in \"%s\"",JSVC_HELPER);
method=(*cfg->jnienv)->GetStaticMethodID(cfg->jnienv,cfg->jniclass,"restart","()Z");
if (method==NULL) {
jsvc_error(JSVC_MARK, "Cannot locate restart method");
return(FALSE);
}
// Call the restart method in the helper class
jsvc_debug(JSVC_MARK, "Calling restart method in \"%s\"",JSVC_HELPER);
ret=(*cfg->jnienv)->CallStaticBooleanMethod(cfg->jnienv, cfg->jniclass, method);
// Normalize the return value (just in case)
if (ret) return(TRUE);
else return(FALSE);
}
boolean jsvc_stop(jsvc_config *cfg) {
JNINativeMethod log;
jmethodID method;
jstring name;
jboolean ret;
jobjectArray arg;
int x;
// Retrieve the stop static method in the helper class
jsvc_debug(JSVC_MARK, "Locating stop method in \"%s\"",JSVC_HELPER);
method=(*cfg->jnienv)->GetStaticMethodID(cfg->jnienv,cfg->jniclass,"stop","()Z");
if (method==NULL) {
jsvc_error(JSVC_MARK, "Cannot locate stop method");
return(FALSE);
}
// Call the stop method in the helper class
jsvc_debug(JSVC_MARK, "Calling stop method in \"%s\"",JSVC_HELPER);
ret=(*cfg->jnienv)->CallStaticBooleanMethod(cfg->jnienv, cfg->jniclass, method);
// Normalize the return value (just in case)
if (ret) return(TRUE);
else return(FALSE);
}
1.1 jakarta-tomcat-4.0/service/native/jsvc_unix.c
Index: jsvc_unix.c
===================================================================
#include <jsvc.h>
int main(int argc, char *argv[]) {
jsvc_config *config;
char *bin;
char *root;
char *home;
int x;
// Resolve the real full path name of the binary
root=(char *)malloc(PATH_MAX*sizeof(char));
if (realpath(argv[0], root)==NULL) {
// jsvc_error(JSVC_MARK, "Cannot resolve base path name");
return(1);
}
// Split the full path name of the binary in file and dir
bin=strrchr(root,'/');
bin[0]='\0';
bin++;
// Check out the JAVA_HOME variable
home=getenv("JAVA_HOME");
if (home==NULL) home="/usr/java";
// Create a configuration structure from command line arguments
config=jsvc_parse(bin, root, home, argc-1, &argv[1]);
if (config==NULL) {
jsvc_error(JSVC_MARK, "Cannot process command line parameters");
return(1);
}
// Dump the current configuration if we're debugging
#ifdef DEBUG
jsvc_debug(JSVC_MARK, "config->binary \"%s\"",
config->binary==NULL?"[NULL]":config->binary);
jsvc_debug(JSVC_MARK, "config->root \"%s\"",
config->root==NULL?"[NULL]":config->root);
jsvc_debug(JSVC_MARK, "config->home \"%s\"",
config->home==NULL?"[NULL]":config->home);
jsvc_debug(JSVC_MARK, "config->vm \"%s\"",
config->vm==NULL?"[NULL]":config->vm);
jsvc_debug(JSVC_MARK, "config->parfile \"%s\"",
config->parfile==NULL?"[NULL]":config->parfile);
jsvc_debug(JSVC_MARK, "config->pidfile \"%s\"",
config->pidfile==NULL?"[NULL]":config->pidfile);
jsvc_debug(JSVC_MARK, "config->user \"%s\"",
config->user==NULL?"[NULL]":config->user);
jsvc_debug(JSVC_MARK, "config->group \"%s\"",
config->group==NULL?"[NULL]":config->group);
jsvc_debug(JSVC_MARK, "config->detach \"%d\"",
config->detach);
jsvc_debug(JSVC_MARK, "config->showversion \"%d\"",
config->showversion);
jsvc_debug(JSVC_MARK, "config->class \"%s\"",
config->class==NULL?"[NULL]":config->class);
jsvc_debug(JSVC_MARK, "config->vmargc \"%d\"",
config->vmargc);
for(x=0; x<config->vmargc; x++)
jsvc_debug(JSVC_MARK,"config->vmargv[%3d] \"%s\"",x,
config->vmargv[x]==NULL?"[NULL]":config->vmargv[x]);
jsvc_debug(JSVC_MARK, "config->clargc \"%d\"", config->clargc);
for(x=0; x<config->clargc; x++)
jsvc_debug(JSVC_MARK,"config->clargv[%3d] \"%s\"",x,
config->clargv[x]==NULL?"[NULL]":config->clargv[x]);
#endif
if (!jsvc_createvm(config)) return(1);
if (!jsvc_prepare(config)) return(1);
if (!jsvc_version(config)) return(1);
if (!jsvc_init(config)) return(1);
if (!jsvc_start(config)) return(1);
while(1) pause();
return(0);
}
boolean jsvc_createvm(jsvc_config *cfg) {
char lib[PATH_MAX];
char arc[32];
char *xvm;
void *hnd;
JavaVMInitArgs *arg;
JavaVMOption *opt;
int x=-1;
jint (*cre)(JavaVM **,JNIEnv **, void *);
// Check if a VM variant was specified
if (cfg->vm==NULL) xvm="";
else xvm=strcat(strdup(cfg->vm),"/");
// Check the processor architecture
sysinfo(SI_ARCHITECTURE,arc,32);
// Calculate the Java Virtual Machine library filename (for JRE standard)
sprintf(lib,"%s/lib/%s/%slibjvm.so",cfg->home,arc,xvm);
jsvc_debug(JSVC_MARK, "Attempting to load library from \"%s\"",lib);
x=open(lib,O_RDONLY);
if (x<0) {
sprintf(lib,"%s/jre/lib/%s/%slibjvm.so",cfg->home,arc,xvm);
jsvc_debug(JSVC_MARK, "Attempting to load library from \"%s\"",lib);
x=open(lib,O_RDONLY);
if (x<0) {
jsvc_error(JSVC_MARK, "VM library \"libjvm.so\" not found");
return(FALSE);
} else close(x);
} else close(x);
// We found the appropriate libjvm.so, attempt to load and link
hnd=dlopen(lib,RTLD_NOW|RTLD_GLOBAL);
if (hnd==NULL) {
jsvc_error(JSVC_MARK, "Cannot load VM \"%s\": %s\n", lib, dlerror());
return(FALSE);
}
// Check if we can find the JNI_CreateJavaVM in the library
cre=dlsym(hnd,"JNI_CreateJavaVM");
if (cre==NULL) {
jsvc_error(JSVC_MARK, "Cannot found JNI_CreateJavaVM in \"%s\"",lib);
return(FALSE);
}
// Setup the Java VM initialization arguments
arg=(JavaVMInitArgs *)malloc(sizeof(JavaVMInitArgs));
arg->version=JNI_VERSION_1_2;
arg->ignoreUnrecognized=JNI_FALSE;
arg->nOptions=cfg->vmargc;
opt=(JavaVMOption *)malloc((arg->nOptions)*sizeof(JavaVMOption));
for (x=0; x<arg->nOptions; x++) opt[x].optionString=cfg->vmargv[x];
arg->options=opt;
// Attempt to create the virtual machine
if((*cre)(&cfg->jnivm,&cfg->jnienv,arg)<0) {
printf("Cannot create virtual machine\n");
return(FALSE);
}
return(TRUE);
}
void jsvc_error(const char *file, int line, const char *fmt, ...) {
va_list args;
#ifdef DEBUG
fprintf(stderr, "[%s %d] ", file, line);
#endif
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
fflush(stderr);
}
void jsvc_debug(const char *file, int line, const char *fmt, ...) {
#ifdef DEBUG
va_list args;
fprintf(stderr, "[%s %d] ", file, line);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
fflush(stderr);
#endif
}
1.1 jakarta-tomcat-4.0/service/native/windows/menu-quit.bmp
<<Binary file>>
1.1 jakarta-tomcat-4.0/service/native/windows/menu-restart.bmp
<<Binary file>>
1.1 jakarta-tomcat-4.0/service/native/windows/menu-start.bmp
<<Binary file>>
1.1 jakarta-tomcat-4.0/service/native/windows/menu-stop.bmp
<<Binary file>>
1.1 jakarta-tomcat-4.0/service/native/windows/tomcat.ico
<<Binary file>>
1.1 jakarta-tomcat-4.0/service/native/windows/tray-default.ico
<<Binary file>>
1.1 jakarta-tomcat-4.0/service/native/windows/tray-running.ico
<<Binary file>>
1.1 jakarta-tomcat-4.0/service/native/windows/tray-stopped.ico
<<Binary file>>
1.1 jakarta-tomcat-4.0/service/share/org/apache/service/Service.java
Index: Service.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 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", "Tomcat", 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/>. *
* *
* ========================================================================= */
package org.apache.service;
/**
* The <code>Service</code> interface abstracts the concept of a service
* provider (usually referred as "daemon" in Unix land).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>,
* Sun Microsystems, Inc.
* @author Copyright © 1999-2000 <a href="http://www.apache.org">The
* Apache Software Foundation</a>
* @version CVS $Revision: 1.1 $ $Date: 2000/11/22 19:26:10 $
*/
public interface Service {
/**
* Initializes this <code>Service</code> instance.
* <p>
* This method must return to the caller as soon as this
* <code>Service</code> instance has been initialized.
* </p>
*
* @param manager A <code>ServiceManager</code> instance used by this
* to control its restart, shutdown and to log.
* @param arguments The command line arguments (as they would have been
* passed to the <code>main(...)</code> static method in
* a generic application.
* @exception ServiceException If this <code>Service</code> instance cannot
* be initialized properly.
*/
public void init(ServiceManager manager, String arguments[])
throws ServiceException;
/**
* Starts this <code>Service</code> instance.
* <p>
* This method must return to the caller as soon as this
* <code>Service</code> instance has been started.
* </p>
* <p>
* A <code>Service</code> implementation must not try to call this
* method directly but rather wait for the underlying native library
* to invoke it.
* </p>
*
* @exception ServiceException If this <code>Service</code> instance cannot
* be started properly.
*/
public void start()
throws ServiceException;
/**
* Stop this <code>Service</code> instance.
* <p>
* This method must return to the caller as soon as this
* <code>Service</code> instance has been stopped.
* </p>
* <p>
* A <code>Service</code> implementation must not try to call this
* method directly but rather wait for the underlying native library
* to invoke it. In the event a <code>Service</code> wants to stop
* itself, the <code>ServiceManager.queryStop()</code> method must
* be used.
* </p>
*
* @exception ServiceException If this <code>Service</code> instance cannot
* be stopped properly.
*/
public void stop()
throws ServiceException;
/**
* Restarts this <code>Service</code> instance.
* <p>
* This method must return to the caller as soon as this
* <code>Service</code> instance has been been restarted.
* </p>
* <p>
* A <code>Service</code> implementation must not try to call this
* method directly but rather wait for the underlying native library
* to invoke it. In the event a <code>Service</code> wants to restart
* itself, the <code>ServiceManager.queryRestart()</code> method must
* be used.
* </p>
*
* @exception ServiceException If this <code>Service</code> instance cannot
* be restarted properly. (No further attempts
* are made, and the <code>shutdown()</code>
* method is called, and the VM exits).
* @exception UnsupportedOperationException If this <code>Service</code>
* instance cannot be restarted.
* (The <code>shutdown()</code>
* method is called, the entire
* VM is restarted, and then the
* <code>startup()</code> method
* is finally called).
*/
public void restart()
throws ServiceException, UnsupportedOperationException;
}
1.1
jakarta-tomcat-4.0/service/share/org/apache/service/ServiceException.java
Index: ServiceException.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 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", "Tomcat", 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/>. *
* *
* ========================================================================= */
package org.apache.service;
public class ServiceException extends Exception {
public ServiceException() {
super();
}
public ServiceException(String message) {
super(message);
}
}
1.1
jakarta-tomcat-4.0/service/share/org/apache/service/ServiceManager.java
Index: ServiceManager.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 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", "Tomcat", 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/>. *
* *
* ========================================================================= */
package org.apache.service;
public interface ServiceManager {
public void queryRestart();
public void queryStop();
public void log(String message);
public void log(Exception exception);
}
1.1
jakarta-tomcat-4.0/service/share/org/apache/service/helpers/NativeServiceHelper.java
Index: NativeServiceHelper.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 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", "Tomcat", 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/>. *
* *
* ========================================================================= */
package org.apache.service.helpers;
import org.apache.service.Service;
import org.apache.service.ServiceManager;
public class NativeServiceHelper {
private static Service service=null;
private static NativeServiceManager manager=null;
public static void version() {
System.err.print("java version \"");
System.err.print(System.getProperty("java.version"));
System.err.print("\"");
System.err.println();
System.err.print(System.getProperty("java.runtime.name"));
System.err.print(" (build ");
System.err.print(System.getProperty("java.runtime.version"));
System.err.print(")");
System.err.println();
System.err.print(System.getProperty("java.vm.name"));
System.err.print(" (build ");
System.err.print(System.getProperty("java.vm.version"));
System.err.print(", ");
System.err.print(System.getProperty("java.vm.info"));
System.err.print(")");
System.err.println();
System.err.flush();
}
public static boolean init(String classname, String arguments[]) {
try {
manager=new NativeServiceManager();
try {
service=(Service)Class.forName(classname).newInstance();
service.init(manager, arguments);
return(true);
} catch (Exception e) {
manager.log(e);
return(false);
}
} catch (Throwable t) {
t.printStackTrace();
return(false);
}
}
public static boolean start() {
try {
service.start();
return(true);
} catch (Exception e) {
manager.log(e);
return(false);
}
}
public static boolean restart() {
try {
service.restart();
return(true);
} catch (Exception e) {
manager.log(e);
return(false);
}
}
public static boolean stop() {
try {
service.stop();
return(true);
} catch (Exception e) {
manager.log(e);
return(false);
}
}
public static void main(String argv[]) {
init(argv[0],argv);
}
}
1.1
jakarta-tomcat-4.0/service/share/org/apache/service/helpers/NativeServiceManager.java
Index: NativeServiceManager.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 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", "Tomcat", 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/>. *
* *
* ========================================================================= */
package org.apache.service.helpers;
import org.apache.service.Service;
import org.apache.service.ServiceManager;
public class NativeServiceManager implements ServiceManager {
public NativeServiceManager() {
super();
}
public void queryRestart() {
throw new UnsupportedOperationException();
}
public void queryStop() {
throw new UnsupportedOperationException();
}
public native void log(String message);
public void log(Exception exception) {
log(exception.getClass().getName()+": "+exception.getMessage());
exception.printStackTrace(System.err);
}
}
1.1
jakarta-tomcat-4.0/service/share/org/apache/service/helpers/SimpleService.java
Index: SimpleService.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999, 2000 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", "Tomcat", 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/>. *
* *
* ========================================================================= */
package org.apache.service.helpers;
import org.apache.service.Service;
import org.apache.service.ServiceManager;
public class SimpleService implements Service, Runnable {
private ServiceManager manager=null;
private Thread thread=null;
private boolean running=false;
public SimpleService() {
super();
}
public void init(ServiceManager manager, String arguments[]) {
this.manager=manager;
this.manager.log("Init");
for (int x=0; x<arguments.length; x++) {
this.manager.log("Argument: \""+arguments[x]+"\"");
}
}
public void start() {
this.manager.log("Start");
this.running=true;
this.thread=new Thread(this);
this.thread.start();
}
public void stop() {
this.manager.log("Stop");
this.running=false;
try {
this.thread.join();
} catch (Exception e) {
this.manager.log(e);
}
this.manager.log("Stopped");
}
public void restart() {
this.manager.log("Restart");
}
public void run() {
while (true) {
try {
if (!this.running) {
this.manager.log("Stopping");
return;
}
this.manager.log("Running");
Thread.currentThread().sleep(5000);
} catch (Exception e) {
this.manager.log(e);
}
}
}
}