|
From: Leif M. <le...@ta...> - 2004-03-31 01:47:19
|
Everett,
The feature to cause the System.in to block does not exist in
currently released
versions of the Wrapper. This will not be available until 3.1.0. Are
you using a
released version or building from CVS?
You could probably figure out what is going on a little better by
adding some
print statements after the call to read from System.in. But from
looking at your
code and the log output, I am betting that you are using 3.0.5 or
earlier and
the call to System.in.read is throwing an IOException. Your code is simply
ignoring any exceptions thrown and continuing on. Try printing out the
exception
you are catching.
Strong advice. Never, and I mean Never! simply eat an exception.
If you
are 100% sure that code will never actually throw an exception then printing
it out should never happen and will not hurt. If you do encounter an
unexpected
exception then you will save yourself hours of hair pulling trying to
figure out the
problem. :-) Speaking from experience.
Let me know if I was wrong in any of my assumptions, I had to guess
because
you didn't post the version you are using.
Cheers,
Leif
Everett Toews wrote:
> hi leif,
>
> this is exactly the behavior i'm looking for in an application i'm
> wrapping. but when i read from System.in it doesn't seem to block.
> this is the code:
>
> // an observer process is started here
>
> System.out.println("Events and errors will be logged to the log file.");
> System.out.println("**** Press [Enter] to stop receiving messages.
> ****");
> InputStream is = System.in;
> try
> {
> // wait for user input to stop receiving messages
> int x = is.read();
> is.close();
> }
> catch (IOException e)
> {
> }
>
> // shutdown the observer process
> System.exit(0);
>
> i get the following output from the wrapper:
>
> // start up messages
> INFO | 2004/03/30 16:35:22 | Events and errors will be logged to the
> log file.
> INFO | 2004/03/30 16:35:22 | **** Press [Enter] to stop receiving
> messages. ****
> INFO | 2004/03/30 16:35:22 | Wrapper Manager: ShutdownHook started
> INFO | 2004/03/30 16:35:22 | Send a packet STOP : 0
> DEBUG | 2004/03/30 16:35:22 | read a packet STOP : 0
> DEBUG | 2004/03/30 16:35:22 | JVM requested a shutdown. (0)
> DEBUG | 2004/03/30 16:35:22 | wrapperStopProcess(0) called.
> DEBUG | 2004/03/30 16:35:22 | Sending stop signal to JVM
> DEBUG | 2004/03/30 16:35:22 | send a packet STOP : NULL
> INFO | 2004/03/30 16:35:22 | WrapperSimpleApp: start(args) end.
> Main Completed=false, exitCode=null
> INFO | 2004/03/30 16:35:22 | returned from listener.start()
> INFO | 2004/03/30 16:35:22 | Send a packet STARTED :
> INFO | 2004/03/30 16:35:22 | Received a packet STOP :
> DEBUG | 2004/03/30 16:35:22 | read a packet STARTED :
> DEBUG | 2004/03/30 16:35:22 | JVM signalled that it was started.
> INFO | 2004/03/30 16:35:23 | Thread, Wrapper-Shutdown-Hook, handling
> the shutdown process.
> INFO | 2004/03/30 16:35:23 | calling listener.stop()
> INFO | 2004/03/30 16:35:23 | WrapperSimpleApp: stop(0)
> INFO | 2004/03/30 16:35:23 | returned from listener.stop()
> INFO | 2004/03/30 16:35:23 | Send a packet STOPPED : 0
> DEBUG | 2004/03/30 16:35:23 | read a packet STOPPED : 0
> DEBUG | 2004/03/30 16:35:23 | JVM signalled that it was stopped.
> INFO | 2004/03/30 16:35:23 | Closing socket.
> INFO | 2004/03/30 16:35:23 | Closed socket:
> java.net.SocketException: Socket operation on nonsocket: recv failed
> DEBUG | 2004/03/30 16:35:23 | socket read no code (closed?).
> INFO | 2004/03/30 16:35:24 | Server daemon shut down
> INFO | 2004/03/30 16:35:24 | Wrapper Manager: ShutdownHook complete
> DEBUG | 2004/03/30 16:35:24 | JVM exited normally.
> STATUS | 2004/03/30 16:35:24 | <-- Wrapper Stopped
>
> any idea why the call to read() isn't blocking?
>
> thanks,
> everett
>
> At 10:40 AM Saturday 3/27/2004, you wrote:
>
>> Barney,
>> You are actually the second person this month to run into problems
>> with the way I
>> had implemented this.
>>
>> For a number of reasons, it is not possible for the System.in
>> InputStream to be used
>> when running under the Java Service Wrapper. Doing so was resulting
>> in a very
>> cryptic exception from deep within Java. To clear things up for
>> users, I had replaced
>> that exception with one of my own which provided a more useful
>> explanation of the
>> cause of the problem.
>>
>> The problem now is that when users try to integrate various
>> applications with the
>> Wrapper, some of those applications are making use of System.in.
>> Even though
>> the console input is not actually being used in some cases, the above
>> exception is
>> preventing those applications from being started.
>>
>> I have modified the Wrapper so that rather than throwing an
>> exception, calls to
>> read from System.in will now simply block forever. By doing this
>> applications that
>> make use of System.in will simply behave as if there is no console
>> input.
>>
>> Never the less. I do have the Wrapper print the following message
>> to the console
>> whenever a thread attempts to read from System.in. I was worried
>> that not doing
>> something would cause users endless hours of frustration as they
>> tried to figure out
>> why they were unable to read any input.
>>
>> WARNING - System.in can not be used when the JVM is being controlled
>> by the Java
>> Service Wrapper. Calls will block indefinitely.
>>
>> Let me know if you have any comments on this. If no reasons why
>> this would be
>> a problem pop up then this will be in the 3.1.0 release.
>>
>> Cheers,
>> Leif
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Wrapper-user mailing list
> Wra...@li...
> https://lists.sourceforge.net/lists/listinfo/wrapper-user
>
|