You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Lauren Commons <lh...@yahoo.com> on 2001/08/03 14:41:52 UTC

running daemons

I've looked for the answer to this, but couldn't find
it.  If I missed it in the docs, please let me know...
I am building and testing (!) an asynchronous
messaging system (based on JMS).  For automated
testing, I'm looking for a way to start the server in
it's own process then run a test script and retrieve
the output for comparison to expected results.
The problem is how do I have Ant kick off the server
then move on to the next task (calling a junit test)?

Thanks
Mr. Lauren Commons

=====
-------------------------
Mr Lauren Commons
A person of moderate zeal

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Re: running daemons

Posted by Matthew Inger <ma...@sedonacorp.com>.
Paul S. Kilroy wrote:

> Lauren Commons wrote:
>
>> I've looked for the answer to this, but couldn't find
>> it.  If I missed it in the docs, please let me know...
>> I am building and testing (!) an asynchronous
>> messaging system (based on JMS).  For automated
>> testing, I'm looking for a way to start the server in
>> it's own process then run a test script and retrieve
>> the output for comparison to expected results.
>> The problem is how do I have Ant kick off the server
>> then move on to the next task (calling a junit test)?
>>
>> Thanks
>> Mr. Lauren Commons
>>
> I wrote a task to do this. It also (since I needed this also...) lets 
> you specify standard input to the java process. Its called JavaInput...
>
>
> It entends the Java task to add parameters "spawn" (boolean) this 
> spawns off the Java code in a seperate thread (daemon), "sleep" (long) 
> milliseconds to wait before returning (so the daemon has time to 
> start), and nested "<input line="blah">" tags for specifying standard 
> input.
>
> Paul
>
>
>
>------------------------------------------------------------------------
>
>package com.channelpoint.build.ant.publiclib;
>
>import org.apache.tools.ant.*;
>import org.apache.tools.ant.taskdefs.*;
>
>import java.io.*;
>
>/**
> * This is an enhanced Java task. It can run java programs in another thread,
> * pause while they startup, and give them input.
> *
> * Arguments include:
> * <li>
> *   <ul>spawn (true or false to create a separate thread for this execution)
> *   <ul>sleep (milliseconds to pause before returning)
> *   <ul>input (nested ex. <input line="blah"/>)
> * </li>
> */
>public class JavaInputTask extends Java {
>    private Input _input = null;
>    private boolean _spawn = false;
>    private long _sleep = 0;
>
>    public void setSpawn( boolean spawn ) {
>        _spawn = spawn;
>    }
>
>    public void setSleep( long sleep ) {
>        _sleep = sleep;
>    }
>
>    public Input createInput() {
>        if( _input == null ) {
>            _input = new Input();
>        }
>        return _input;
>    }
>
>    public void doit() throws BuildException {
>        super.execute();
>    }
>    public void execute() throws BuildException {
>        InputStream old = null;
>        if( _input != null ) {
>            old = System.in;
>            System.setIn( new ByteArrayInputStream( _input.getBytes() ) );
>        }
>
>        if( _spawn ) {
>            Spawn s = new Spawn( this );
>            s.start();
>            try {
>                Thread.currentThread().sleep( _sleep );
>            } catch ( InterruptedException e ) {
>                throw new BuildException( e );
>            }
>        } else {
>            doit();
>        }
>
>        if( old != null ) {
>            System.setIn( old );
>        }
>    }
>
>    public class Spawn extends Thread {
>        private JavaInputTask _ji;
>
>        public Spawn( JavaInputTask ji ) {
>            _ji = ji;
>        }
>
>        public void run() {
>            _ji.doit();
>        }
>    }
>
>    public class Input {
>        private StringBuffer _buf = new StringBuffer();
>
>        public void setLine( String line ) {
>            _buf.append( line + "\n" );
>        }
>
>        public byte[] getBytes() {
>            return _buf.toString().getBytes();
>        }
>    }
>}
>
> JavaInputTask.java
>
> Content-Type:
>
> text/plain
> Content-Encoding:
>
> 7bit
>
>
isn't that a little unsafe?  resetting System.in?

What if:
    1) The thread isn't finished with the input before you set System.in 
back
         to it's original value (say for instance if it processes one 
line of input
         at a time, and then does some io over a slow network, though 
this is
         a bad design in general, but could happen)?

    2) You have multiple threads running which use standard input (though
         unlikely, it could happen)?

The first one is really the one to worry about.  I would think
it's safer to just pass input like that in a file, or as command
line arguments.

Just my $.02


-- 
Matt Inger (matt.inger@sedonacorp.com)
Sedona Corporation
455 S. Gulph Road, Suite 300
King of Prussia, PA 19406
(484) 679-2213
"Self-respect - the secure feeling that no one,
 as yet, is suspicious." -H.L. Mencken 




Re: running daemons

Posted by "Paul S. Kilroy" <pk...@channelpoint.com>.
Lauren Commons wrote:

>I've looked for the answer to this, but couldn't find
>it.  If I missed it in the docs, please let me know...
>I am building and testing (!) an asynchronous
>messaging system (based on JMS).  For automated
>testing, I'm looking for a way to start the server in
>it's own process then run a test script and retrieve
>the output for comparison to expected results.
>The problem is how do I have Ant kick off the server
>then move on to the next task (calling a junit test)?
>
>Thanks
>Mr. Lauren Commons
>
I wrote a task to do this. It also (since I needed this also...) lets 
you specify standard input to the java process. Its called JavaInput...


It entends the Java task to add parameters "spawn" (boolean) this spawns 
off the Java code in a seperate thread (daemon), "sleep" (long) 
milliseconds to wait before returning (so the daemon has time to start), 
and nested "<input line="blah">" tags for specifying standard input.

Paul



Re: running daemons

Posted by Matthew Inger <ma...@sedonacorp.com>.
Conor MacNeill wrote:

>From: "Matthew Inger" <ma...@sedonacorp.com>
>To: <an...@jakarta.apache.org>
>Sent: Friday, August 03, 2001 11:34 PM
>Subject: Re: running daemons
>
>
>>I believe, if you tell your call to "<java>" (if that's what you're
>>using) to
>>"fork", then control should return to ant right away.  (ANT experts,
>>
>please
>
>>correct me if i'm wrong here.
>>
>
>I'm afraid you are wrong. Ant waits for the command to complete.
>
>Conor
>
>
>

what would be nice is if there were a way to tell it not to wait for it 
to return.


-- 
Matt Inger (matt.inger@sedonacorp.com)
Sedona Corporation
455 S. Gulph Road, Suite 300
King of Prussia, PA 19406
(484) 679-2213
"Self-respect - the secure feeling that no one,
 as yet, is suspicious." -H.L. Mencken 




Re: running daemons

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
From: "Matthew Inger" <ma...@sedonacorp.com>
To: <an...@jakarta.apache.org>
Sent: Friday, August 03, 2001 11:34 PM
Subject: Re: running daemons


> I believe, if you tell your call to "<java>" (if that's what you're
> using) to
> "fork", then control should return to ant right away.  (ANT experts,
please
> correct me if i'm wrong here.

I'm afraid you are wrong. Ant waits for the command to complete.

Conor



Re: running daemons

Posted by Matthew Inger <ma...@sedonacorp.com>.
I believe, if you tell your call to "<java>" (if that's what you're 
using) to
"fork", then control should return to ant right away.  (ANT experts, please
correct me if i'm wrong here.  If so, it would be a nice option to have).
If it's a shell command, on unix, append the '&' character to the command.
As far as windows, you'll have to ask a windows expert how to background
a program.



Lauren Commons wrote:

>I've looked for the answer to this, but couldn't find
>it.  If I missed it in the docs, please let me know...
>I am building and testing (!) an asynchronous
>messaging system (based on JMS).  For automated
>testing, I'm looking for a way to start the server in
>it's own process then run a test script and retrieve
>the output for comparison to expected results.
>The problem is how do I have Ant kick off the server
>then move on to the next task (calling a junit test)?
>
>Thanks
>Mr. Lauren Commons
>
>=====
>-------------------------
>Mr Lauren Commons
>A person of moderate zeal
>
>__________________________________________________
>Do You Yahoo!?
>Make international calls for as low as $.04/minute with Yahoo! Messenger
>http://phonecard.yahoo.com/
>


-- 
Matt Inger (matt.inger@sedonacorp.com)
Sedona Corporation
455 S. Gulph Road, Suite 300
King of Prussia, PA 19406
(484) 679-2213
"Self-respect - the secure feeling that no one,
 as yet, is suspicious." -H.L. Mencken