Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 37765 invoked from network); 19 Mar 2010 16:55:39 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 19 Mar 2010 16:55:39 -0000 Received: (qmail 83670 invoked by uid 500); 19 Mar 2010 16:55:39 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 83602 invoked by uid 500); 19 Mar 2010 16:55:39 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 83595 invoked by uid 99); 19 Mar 2010 16:55:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Mar 2010 16:55:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Mar 2010 16:55:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DE5AC2388A3B; Fri, 19 Mar 2010 16:55:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r925323 - in /commons/proper/daemon/trunk/src/samples: ProcrunService.java build.xml Date: Fri, 19 Mar 2010 16:55:14 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100319165514.DE5AC2388A3B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ - + @@ -78,6 +78,20 @@ + + + + + + + + + + + + +