How to implement shutdown hook

View: New views
3 Messages — Rating Filter:   Alert me  

How to implement shutdown hook

by Riyaz Saiyed :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I tried extending WrapperSimpleApp to implement stop method and added some debugging statements. It seems to be not executing. What is the best way to implement shutdown hook?

class:
public class MyWrapperApplication extends WrapperSimpleApp
{
        ....
        ....
    @Override
    public int stop ( int exitCode )
    {
        if ( logService.isInfoEnabled ( ) )
        {
            logService.info ( "Print Service Shutting down." );
        }
        return super.stop ( exitCode );
    }
}

configuration:
#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=java

# Java Main class.  This class must implement the WrapperListener interface
#  or guarantee that the WrapperManager class is initialized.  Helper
#  classes are provided to do this for you.  See the Integration section
#  of the documentation for details.
wrapper.java.mainclass=printservice.bootstrap.MyWrapperApplication

# Java Classpath (include wrapper.jar)  Add class path elements as
#  needed starting from 1
wrapper.java.classpath.1=../wrapperLib/wrapper.jar
wrapper.java.classpath.2=../applicationLib/*.jar
wrapper.java.library.path.1=../wrapperLib  

# Java Library Path (location of Wrapper.DLL or libwrapper.so)

# Java Additional Parameters

# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3

# Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=64
Regards,
Riyaz..



Re: How to implement shutdown hook

by Leif Mortenson-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Riyaz,
Looking over your code, it appears to be written correctly with one
exception.  The problem is that your MyWrapperApplication class does
not define its own main method.  This means that it falls back to the
WrapperSimpleApp class's main method which creates a WrapperSimpleApp
instance, not a MyWrapperApplication instance.

Please add a method like the following to your class and it should
start working:
    public static void main( String args[] )
    {
        new MyWrapperApplication( args );
    }

Please let me know if you still have problems getting it work and I
will take another look.

Cheers,
Leif

On Mon, Oct 12, 2009 at 3:38 PM, Riyaz Saiyed <riyaz_saiyed@...> wrote:

>
> Hi,
>
> I tried extending WrapperSimpleApp to implement stop method and added some
> debugging statements. It seems to be not executing. What is the best way to
> implement shutdown hook?
>
> class:
> public class MyWrapperApplication extends WrapperSimpleApp
> {
>        ....
>        ....
>    @Override
>    public int stop ( int exitCode )
>    {
>        if ( logService.isInfoEnabled ( ) )
>        {
>            logService.info ( "Print Service Shutting down." );
>        }
>        return super.stop ( exitCode );
>    }
> }
>
> configuration:
> #********************************************************************
> # Wrapper Properties
> #********************************************************************
> # Java Application
> wrapper.java.command=java
>
> # Java Main class.  This class must implement the WrapperListener interface
> #  or guarantee that the WrapperManager class is initialized.  Helper
> #  classes are provided to do this for you.  See the Integration section
> #  of the documentation for details.
> wrapper.java.mainclass=printservice.bootstrap.MyWrapperApplication
>
> # Java Classpath (include wrapper.jar)  Add class path elements as
> #  needed starting from 1
> wrapper.java.classpath.1=../wrapperLib/wrapper.jar
> wrapper.java.classpath.2=../applicationLib/*.jar
> wrapper.java.library.path.1=../wrapperLib
>
> # Java Library Path (location of Wrapper.DLL or libwrapper.so)
>
> # Java Additional Parameters
>
> # Initial Java Heap Size (in MB)
> #wrapper.java.initmemory=3
>
> # Maximum Java Heap Size (in MB)
> wrapper.java.maxmemory=64
>
>
> -----
> Regards,
> Riyaz..

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Wrapper-user mailing list
Wrapper-user@...
https://lists.sourceforge.net/lists/listinfo/wrapper-user

Re: How to implement shutdown hook

by Riyaz Saiyed :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Leif,

Actually I switched back to the previous approach (integration method 1) and adding shutdown hook in my main class.

...
Runtime.getRuntime ( ).addShutdownHook ( new Thread ( )
            {
                public void run ( )
                {
                    if ( logService.isInfoEnabled ( ) )
                    {
                        logService.info ( "shutting down the print service" );
                    }
                    try
                    {
                        printService.stop();
                    }
                    catch ( ApplicationException e )
                    {
                        if ( logService.isErrorEnabled ( ) )
                        {
                            logService.error ( "error stopping print service", null, null, e );
                        }
                    }
                }
            } );
...
Everything is working fine now.

Leif Mortenson-3 wrote:
Riyaz,
Looking over your code, it appears to be written correctly with one
exception.  The problem is that your MyWrapperApplication class does
not define its own main method.  This means that it falls back to the
WrapperSimpleApp class's main method which creates a WrapperSimpleApp
instance, not a MyWrapperApplication instance.

Please add a method like the following to your class and it should
start working:
    public static void main( String args[] )
    {
        new MyWrapperApplication( args );
    }

Please let me know if you still have problems getting it work and I
will take another look.

Cheers,
Leif

On Mon, Oct 12, 2009 at 3:38 PM, Riyaz Saiyed <riyaz_saiyed@mindtree.com> wrote:
>
> Hi,
>
> I tried extending WrapperSimpleApp to implement stop method and added some
> debugging statements. It seems to be not executing. What is the best way to
> implement shutdown hook?
>
> class:
> public class MyWrapperApplication extends WrapperSimpleApp
> {
>        ....
>        ....
>    @Override
>    public int stop ( int exitCode )
>    {
>        if ( logService.isInfoEnabled ( ) )
>        {
>            logService.info ( "Print Service Shutting down." );
>        }
>        return super.stop ( exitCode );
>    }
> }
>
> configuration:
> #********************************************************************
> # Wrapper Properties
> #********************************************************************
> # Java Application
> wrapper.java.command=java
>
> # Java Main class.  This class must implement the WrapperListener interface
> #  or guarantee that the WrapperManager class is initialized.  Helper
> #  classes are provided to do this for you.  See the Integration section
> #  of the documentation for details.
> wrapper.java.mainclass=printservice.bootstrap.MyWrapperApplication
>
> # Java Classpath (include wrapper.jar)  Add class path elements as
> #  needed starting from 1
> wrapper.java.classpath.1=../wrapperLib/wrapper.jar
> wrapper.java.classpath.2=../applicationLib/*.jar
> wrapper.java.library.path.1=../wrapperLib
>
> # Java Library Path (location of Wrapper.DLL or libwrapper.so)
>
> # Java Additional Parameters
>
> # Initial Java Heap Size (in MB)
> #wrapper.java.initmemory=3
>
> # Maximum Java Heap Size (in MB)
> wrapper.java.maxmemory=64
>
>
> -----
> Regards,
> Riyaz..

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Wrapper-user mailing list
Wrapper-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wrapper-user
Regards,
Riyaz..