db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kathey Marsden <kmarsdende...@sbcglobal.net>
Subject Re: [jira] Commented: (DERBY-214) Remove System.exit() calls from the DB2jServerImpl.java
Date Thu, 28 Apr 2005 23:19:25 GMT
David Van Couvering wrote:

> Hi, all.  I have done further investigation, and conversations I have
> had convince me that (a) System.exit() is the proper way to set an
> exit code and (b) embedding apps in general should not be calling
> main(), and (c) since we have a policy of always expecting to be
> embedded, tools should have a policy of providing a callable execute()
> method that doesn't do System.exit() but instead throws exceptions.

> DB2jServerImpl.main(new String[] { "ping", "-p", "2000"} );
> rather than
> DB2jServerImpl impl = new DB2jServerImpl()
> impl.setCommand("ping");
> impl.setPort("2000");
> impl.execute();
DB2jServerImpl  is not a public class. NetworkServerControl is where the
public api lives, so if we did use the JavaBean
or execute approach the methods would live  there.

> So, I would like to propose the following:
> - Define a new abstract class, e.g. org.apache.derby.tools.BaseTool,
> that looks something like this:
> public abstract class BaseTool
> {

I feel a little funny about NetworkServer being called a tool, but maybe
it's ok for NetworkServerControl  (a tool that controls the server?). 

>   public abstract void execute(String[] args) throws Exception;
>   /**
>   * Basic main routine, can be overridden if needed
>   */
>   public static void main(String[] args)
>   {
>     try
>     {
>       execute(args);
>     }
>     catch ( Exception e )
>     {
>       e.printStackTrace();
>       System.exit(1);
>     }
>     System.exit(0);
>   }
> }
> and then have our tools implement this, e.g.
> public class MyTool extends BaseTool
> {
>   public void execute(String[] args) throws Exception

Should this be:
    public static void execute(String[] args) throws Exception?

>   {
>     // yada yada
>   }
> }
> and then applications can do
> MyTool.execute(new String{ "ping" });
> Comments?

Well my comment is that I am glad I took this off the starter task list
when I saw you picked it up.

But I  have a question.  With regard to Network Server, would this just
be an additional way to control network server if you would prefer to
use execute instead of the existing NetworkServerControl API?  If so, 
would one be preferred over the other?

I asked Rajesh to respond regarding his original Eclipse requirements,
but while the execute thing sounds interesting, I  wonder how it
addresses the Eclipse calling model?  Maybe  a static method is all that
is needed and  execute would suffice if it is a static method.

Still also I wonder about  what Dan said:

Never make assumptions that your Java program is controlling the JVM and
has the right to call methods like System.exit, then multiple Java
"main" programs can hook up together without problems.

I guess that is how I would like to see it in an ideal world. Maybe that is not possible,
but   I would like to hear a little bit more input before we make such a decision about the
public API's.  



View raw message