You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2010/03/19 17:55:14 UTC
svn commit: r925323 - in /commons/proper/daemon/trunk/src/samples:
ProcrunService.java build.xml
Author: sebb
Date: Fri Mar 19 16:55:14 2010
New Revision: 925323
URL: http://svn.apache.org/viewvc?rev=925323&view=rev
Log:
Sample Procrun service implementation
Added:
commons/proper/daemon/trunk/src/samples/ProcrunService.java (with props)
Modified:
commons/proper/daemon/trunk/src/samples/build.xml
Added: commons/proper/daemon/trunk/src/samples/ProcrunService.java
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/samples/ProcrunService.java?rev=925323&view=auto
==============================================================================
--- commons/proper/daemon/trunk/src/samples/ProcrunService.java (added)
+++ commons/proper/daemon/trunk/src/samples/ProcrunService.java Fri Mar 19 16:55:14 2010
@@ -0,0 +1,100 @@
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/*
+ * 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.
+ *
+ */
+
+/**
+ * Sample service implementation for use with Windows Procrun.
+ */
+public class ProcrunService implements Runnable {
+
+ private static final int DEFAULT_PAUSE = 60; // Wait 1 minute
+ private static final long MS_PER_SEC = 1000L; // Milliseconds in a second
+
+ private static volatile Thread thrd; // start and stop are called from different threads
+
+ private final long pause; // How long to pause in service loop
+
+ private ProcrunService(long wait){
+ pause=wait;
+ }
+
+ private static void usage(){
+ System.err.println("Must supply the argument 'start' or 'stop'");
+ }
+
+ /**
+ * Common entry point for start and stop service functions.
+ *
+ * @param args [start [pause time] | stop]
+ */
+ public static void main(String[] args) {
+ final int argc = args.length;
+ log("ProcrunService called with "+argc+" arguments from thread: "+Thread.currentThread());
+ for(int i=0; i < argc; i++) {
+ System.out.println("["+i+"] "+args[i]);
+ }
+ String mode=null;
+ if (argc > 0) {
+ mode = args[0];
+ if ("start".equals(mode)){
+ long wait = DEFAULT_PAUSE;
+ if (argc > 1) {
+ wait = Integer.valueOf(args[1]).intValue();
+ }
+ log("Starting the thread, wait(seconds): "+wait);
+ thrd = new Thread(new ProcrunService(wait*MS_PER_SEC));
+ thrd.start();
+ } else
+ if ("stop".equals(mode)) {
+ if (thrd != null) {
+ log("Interrupting the thread");
+ thrd.interrupt();
+ }
+ } else {
+ usage();
+ }
+ } else {
+ usage();
+ }
+ }
+
+ /**
+ * This method performs the work of the service.
+ * In this case, it just logs a message every so often.
+ */
+ public void run() {
+ log("Started thread in "+System.getProperty("user.dir"));
+ while(true){
+ try {
+ log("pausing...");
+ Thread.sleep(pause);
+ } catch (InterruptedException e) {
+ log("Exitting");
+ break;
+ }
+ }
+ }
+
+ private static void log(String msg){
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
+ System.out.println(df.format(new Date())+msg);
+ }
+}
Propchange: commons/proper/daemon/trunk/src/samples/ProcrunService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/daemon/trunk/src/samples/ProcrunService.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: commons/proper/daemon/trunk/src/samples/build.xml
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/samples/build.xml?rev=925323&r1=925322&r2=925323&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/samples/build.xml (original)
+++ commons/proper/daemon/trunk/src/samples/build.xml Fri Mar 19 16:55:14 2010
@@ -26,7 +26,7 @@
<property name="maven.repo.local" value="${user.home}/.m2/repository"/>
<property name="commons-collections.jar" value="${maven.repo.local}/commons-collections/commons-collections/3.1/commons-collections-3.1.jar"/>
- <target name="jars" depends="SimpleDaemon,ServiceDaemon,AloneService"/>
+ <target name="jars" depends="SimpleDaemon,ServiceDaemon,AloneService,ProcrunService"/>
<target name="clean" description="Remove output files">
<delete quiet="true">
@@ -78,6 +78,20 @@
</jar>
</target>
+ <target name="ProcrunService" depends="compile"
+ description="Create ProcrunService.jar">
+ <mkdir dir="${dist.home}"/>
+ <jar jarfile="${dist.home}/ProcrunService.jar">
+ <metainf dir="../..">
+ <include name="NOTICE.txt"/>
+ <include name="LICENSE.txt"/>
+ </metainf>
+ <fileset dir="${build.home}/classes">
+ <include name="ProcrunService.class" />
+ </fileset>
+ </jar>
+ </target>
+
<target name="compile" depends="prepare"
description="Create class files">
<javac srcdir="${source.home}"