You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Stanton <pa...@mapshed.com.au> on 2010/11/29 06:28:09 UTC

tapestry-hibernate, hsqldb and registry shutdown

Hi all,

I'm using tapestry-hibernate and an embedded HSQLDB database.

As you might know, it's important to tell HSQLDB to shutdown when you 
are terminating the vm.

You do this by executing a proprietary SQL query "SHUTDOWN" before 
closing your last connection.

Ideally I'd like to use hibernate to execute the SQL query since it is 
already configured to connect to the database.

Currently I am trying to do it like so:

public class DbShutdownImpl implements DbShutdown, RegistryShutdownListener
{
     @Inject
     private Session session;

     private final static Logger LOG = 
Logger.getLogger(DbShutdownImpl.class);

     @PostInjection
     public void startupService(RegistryShutdownHub shutdownHub)
     {
         shutdownHub.addRegistryShutdownListener(this);
     }

     @Override
     @CommitAfter
     public void registryDidShutdown()
     {
         LOG.error("shutdown called");
         session.createSQLQuery("SHUTDOWN").executeUpdate();
     }
}

However, I am getting the exception:

java.lang.RuntimeException: Exception constructing service 'Session': 
Proxy for service Session is no longer active because the IOC Registry 
has been shut down.
     at 
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78)
     at 
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)
     at $Session_12c96175d35.delegate($Session_12c96175d35.java)
     at $Session_12c96175d35.createSQLQuery($Session_12c96175d35.java)
     at mypackage.DbShutdownImpl.registryDidShutdown(DbShutdownImpl.java:29)
     at 
org.apache.tapestry5.ioc.internal.services.RegistryShutdownHubImpl.fireRegistryDidShutdown(RegistryShutdownHubImpl.java:57)
     at 
org.apache.tapestry5.ioc.internal.RegistryImpl.shutdown(RegistryImpl.java:411)
     at 
org.apache.tapestry5.ioc.internal.RegistryWrapper.shutdown(RegistryWrapper.java:41)
     at org.apache.tapestry5.TapestryFilter.destroy(TapestryFilter.java:169)

I understand that the registry is shutting down and therefore won't 
handle new requests for managed services.

How do I get around this problem without creating my own JDBC connection 
in my shutdown handler?

Regards, p.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Tom van Dijk <to...@tvandijk.nl>.
Wouldn't registryWillShutdown be used to /prepare/ the session (request 
a session object) which can then be used in registryDidShutdown? It's 
the same thread, after all.

Op 29-11-2010 21:52, Kalle Korhonen schreef:
> Perhaps you should read this as well:
> http://www.mail-archive.com/users@tapestry.apache.org/msg41237.html.
> But overall, not necessarily a good idea to shut down services before
> their time. For your specific case though, why not just use h2
> (http://h2database.com) and DB_CLOSE_ON_EXIT=TRUE instead and be done
> with the issue.
>
> Kalle
>
>
> On Mon, Nov 29, 2010 at 12:43 PM, Paul Stanton<pa...@mapshed.com.au>  wrote:
>> Javier,
>>
>> I agree re registryIsShuttingDown .. that is what i'm looking for.
>>
>> something that is called after new httprequests have been stopped, but
>> before the registry becomes broken.
>>
>> there would need to be some ordered configuration to control the process
>> however.
>>
>> i'm guessing this doesn't currently exist, should i create a jira issue?
>>
>> in the mean time i have solved my problem by recording the connection info
>> at startup so i don't need to inject a service at shutdown:
>>
>> public class DbShutdownImpl implements DbShutdown, RegistryShutdownListener
>> {
>>     private Properties hibConfig;
>>
>>     private final static Logger LOG = Logger.getLogger(DbShutdownImpl.class);
>>
>>     public DbShutdownImpl(HibernateSessionSource sessionSource)
>>     {
>>         hibConfig = sessionSource.getConfiguration().getProperties();
>>     }
>>
>>     @PostInjection
>>     public void startupService(RegistryShutdownHub shutdownHub)
>>     {
>>         shutdownHub.addRegistryShutdownListener(this);
>>     }
>>
>>     @Override
>>     public void registryDidShutdown()
>>     {
>>         Connection con = null;
>>         try
>>         {
>>             String driver =
>> hibConfig.getProperty("hibernate.connection.driver_class");
>>             String url = hibConfig.getProperty("hibernate.connection.url");
>>             String username =
>> hibConfig.getProperty("hibernate.connection.username");
>>             String password =
>> hibConfig.getProperty("hibernate.connection.password");
>>             con = JdbcUs.getConnection(driver, url, username, password);
>>             JdbcUs.executeUpdate("SHUTDOWN", con);
>>             LOG.debug("database shutdown cleanly");
>>         }
>>         catch (Throwable e)
>>         {
>>             LOG.error("database shutdown failed", e);
>>         }
>>         finally
>>         {
>>             JdbcUs.closeQuietly(con);
>>         }
>>     }
>> }
>>
>> NOTE: This won't work for everyone.
>>
>> p.
>>
>> On 29/11/2010 11:16 PM, Javier Molina wrote:
>>> Overriding the filter might look ugly, but it was designed for that; see
>>> the comments on destroy() and destroy(Registry registry).
>>>
>>> You might find it less ugly to have a ServletContextListener and do the
>>> cleanup in contextDestroyed.
>>>
>>> The real solution would be to have a registryIsShuttingDown()
>>> notification, fired before registryDidShutdown(). I haven't found it,
>>> though.
>>>
>>>
>>> El 29/11/10 12:53, Tom van Dijk escribió:
>>>> Which service would that be? Could you provide a stack trace?
>>>>
>>>> Perhaps you could make your service contribute to RegistryStartup as
>>>> well,
>>>> to make sure the DbShutdownImpl service is realized and that the
>>>> sessionSource is realized. The "startupService" would then be the
>>>> registry
>>>> startup method.
>>>>
>>>> I agree that modifying TapestryFilter is an ugly solution and should be
>>>> avoided if possible.
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Kalle Korhonen <ka...@gmail.com>.
Perhaps you should read this as well:
http://www.mail-archive.com/users@tapestry.apache.org/msg41237.html.
But overall, not necessarily a good idea to shut down services before
their time. For your specific case though, why not just use h2
(http://h2database.com) and DB_CLOSE_ON_EXIT=TRUE instead and be done
with the issue.

Kalle


On Mon, Nov 29, 2010 at 12:43 PM, Paul Stanton <pa...@mapshed.com.au> wrote:
> Javier,
>
> I agree re registryIsShuttingDown .. that is what i'm looking for.
>
> something that is called after new httprequests have been stopped, but
> before the registry becomes broken.
>
> there would need to be some ordered configuration to control the process
> however.
>
> i'm guessing this doesn't currently exist, should i create a jira issue?
>
> in the mean time i have solved my problem by recording the connection info
> at startup so i don't need to inject a service at shutdown:
>
> public class DbShutdownImpl implements DbShutdown, RegistryShutdownListener
> {
>    private Properties hibConfig;
>
>    private final static Logger LOG = Logger.getLogger(DbShutdownImpl.class);
>
>    public DbShutdownImpl(HibernateSessionSource sessionSource)
>    {
>        hibConfig = sessionSource.getConfiguration().getProperties();
>    }
>
>    @PostInjection
>    public void startupService(RegistryShutdownHub shutdownHub)
>    {
>        shutdownHub.addRegistryShutdownListener(this);
>    }
>
>    @Override
>    public void registryDidShutdown()
>    {
>        Connection con = null;
>        try
>        {
>            String driver =
> hibConfig.getProperty("hibernate.connection.driver_class");
>            String url = hibConfig.getProperty("hibernate.connection.url");
>            String username =
> hibConfig.getProperty("hibernate.connection.username");
>            String password =
> hibConfig.getProperty("hibernate.connection.password");
>            con = JdbcUs.getConnection(driver, url, username, password);
>            JdbcUs.executeUpdate("SHUTDOWN", con);
>            LOG.debug("database shutdown cleanly");
>        }
>        catch (Throwable e)
>        {
>            LOG.error("database shutdown failed", e);
>        }
>        finally
>        {
>            JdbcUs.closeQuietly(con);
>        }
>    }
> }
>
> NOTE: This won't work for everyone.
>
> p.
>
> On 29/11/2010 11:16 PM, Javier Molina wrote:
>>
>> Overriding the filter might look ugly, but it was designed for that; see
>> the comments on destroy() and destroy(Registry registry).
>>
>> You might find it less ugly to have a ServletContextListener and do the
>> cleanup in contextDestroyed.
>>
>> The real solution would be to have a registryIsShuttingDown()
>> notification, fired before registryDidShutdown(). I haven't found it,
>> though.
>>
>>
>> El 29/11/10 12:53, Tom van Dijk escribió:
>>>
>>> Which service would that be? Could you provide a stack trace?
>>>
>>> Perhaps you could make your service contribute to RegistryStartup as
>>> well,
>>> to make sure the DbShutdownImpl service is realized and that the
>>> sessionSource is realized. The "startupService" would then be the
>>> registry
>>> startup method.
>>>
>>> I agree that modifying TapestryFilter is an ugly solution and should be
>>> avoided if possible.
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Paul Stanton <pa...@mapshed.com.au>.
Javier,

I agree re registryIsShuttingDown .. that is what i'm looking for.

something that is called after new httprequests have been stopped, but 
before the registry becomes broken.

there would need to be some ordered configuration to control the process 
however.

i'm guessing this doesn't currently exist, should i create a jira issue?

in the mean time i have solved my problem by recording the connection 
info at startup so i don't need to inject a service at shutdown:

public class DbShutdownImpl implements DbShutdown, RegistryShutdownListener
{
     private Properties hibConfig;

     private final static Logger LOG = 
Logger.getLogger(DbShutdownImpl.class);

     public DbShutdownImpl(HibernateSessionSource sessionSource)
     {
         hibConfig = sessionSource.getConfiguration().getProperties();
     }

     @PostInjection
     public void startupService(RegistryShutdownHub shutdownHub)
     {
         shutdownHub.addRegistryShutdownListener(this);
     }

     @Override
     public void registryDidShutdown()
     {
         Connection con = null;
         try
         {
             String driver = 
hibConfig.getProperty("hibernate.connection.driver_class");
             String url = hibConfig.getProperty("hibernate.connection.url");
             String username = 
hibConfig.getProperty("hibernate.connection.username");
             String password = 
hibConfig.getProperty("hibernate.connection.password");
             con = JdbcUs.getConnection(driver, url, username, password);
             JdbcUs.executeUpdate("SHUTDOWN", con);
             LOG.debug("database shutdown cleanly");
         }
         catch (Throwable e)
         {
             LOG.error("database shutdown failed", e);
         }
         finally
         {
             JdbcUs.closeQuietly(con);
         }
     }
}

NOTE: This won't work for everyone.

p.

On 29/11/2010 11:16 PM, Javier Molina wrote:
> Overriding the filter might look ugly, but it was designed for that; 
> see the comments on destroy() and destroy(Registry registry).
>
> You might find it less ugly to have a ServletContextListener and do 
> the cleanup in contextDestroyed.
>
> The real solution would be to have a registryIsShuttingDown() 
> notification, fired before registryDidShutdown(). I haven't found it, 
> though.
>
>
> El 29/11/10 12:53, Tom van Dijk escribió:
>> Which service would that be? Could you provide a stack trace?
>>
>> Perhaps you could make your service contribute to RegistryStartup as 
>> well,
>> to make sure the DbShutdownImpl service is realized and that the
>> sessionSource is realized. The "startupService" would then be the 
>> registry
>> startup method.
>>
>> I agree that modifying TapestryFilter is an ugly solution and should be
>> avoided if possible.
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Tom van Dijk <to...@tvandijk.nl>.
Well, designed or not, I suppose overriding the filter is not a modular 
solution. You can't add a third party library and expect it to work, 
instead the application developer needs to do additional work by 
modifying web.xml and on top of that, if you use your service without 
tapestry-core, it won't work. You really need to listen to the Registry 
shutdown if you want to write your service as a general solution.


Regarding that last thing, the code of shutdown in the Registry is as 
follows:

     public synchronized void shutdown()
     {
         lock.lock();

         registryShutdownHub.fireRegistryDidShutdown();

         SerializationSupport.clearProvider(this);
     }

Your idea would look like this:

     public synchronized void shutdown()
     {
         lock.check();

         registryShutdownHub.fireRegistryWillShutdown();

         lock.lock();

         registryShutdownHub.fireRegistryDidShutdown();

         SerializationSupport.clearProvider(this);
     }


I suppose that the reason the lock is locked is that you want to 
guarantee that somehow that services that are listening to 
registryDidShutdown aren't used anymore after receiving the shutdown 
event. However, you may need certain services to be instantiated at 
registry shutdown. In case of per-thread services, there is no way to do 
this pre-shutdown work, so a RegistryWillShutdown thing might be useful.

The actual implementation would require an additional service interface, 
RegistryWillShutdownListener (well, one could add a method to 
RegistryShutdownListener but then lots of code will break because not 
all methods are implemented). Perhaps a committer might be willing to 
look at it.



Op 29-11-2010 13:16, Javier Molina schreef:
> Overriding the filter might look ugly, but it was designed for that; 
> see the comments on destroy() and destroy(Registry registry).
>
> You might find it less ugly to have a ServletContextListener and do 
> the cleanup in contextDestroyed.
>
> The real solution would be to have a registryIsShuttingDown() 
> notification, fired before registryDidShutdown(). I haven't found it, 
> though.
>
>
> El 29/11/10 12:53, Tom van Dijk escribió:
>> Which service would that be? Could you provide a stack trace?
>>
>> Perhaps you could make your service contribute to RegistryStartup as 
>> well,
>> to make sure the DbShutdownImpl service is realized and that the
>> sessionSource is realized. The "startupService" would then be the 
>> registry
>> startup method.
>>
>> I agree that modifying TapestryFilter is an ugly solution and should be
>> avoided if possible.
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Javier Molina <ja...@comunicamultimedia.com>.
Overriding the filter might look ugly, but it was designed for that; see 
the comments on destroy() and destroy(Registry registry).

You might find it less ugly to have a ServletContextListener and do the 
cleanup in contextDestroyed.

The real solution would be to have a registryIsShuttingDown() 
notification, fired before registryDidShutdown(). I haven't found it, 
though.


El 29/11/10 12:53, Tom van Dijk escribió:
> Which service would that be? Could you provide a stack trace?
>
> Perhaps you could make your service contribute to RegistryStartup as well,
> to make sure the DbShutdownImpl service is realized and that the
> sessionSource is realized. The "startupService" would then be the registry
> startup method.
>
> I agree that modifying TapestryFilter is an ugly solution and should be
> avoided if possible.
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Tom van Dijk <to...@tvandijk.nl>.
Which service would that be? Could you provide a stack trace?

Perhaps you could make your service contribute to RegistryStartup as well,
to make sure the DbShutdownImpl service is realized and that the
sessionSource is realized. The "startupService" would then be the registry
startup method.

I agree that modifying TapestryFilter is an ugly solution and should be
avoided if possible.


On Mon, 29 Nov 2010 21:06:50 +1100, Paul Stanton <pa...@mapshed.com.au>
wrote:
> same error, different service which can't be injected.
> 
> On 29/11/2010 8:13 PM, Tom van Dijk wrote:
>> What if you do this:
>>
>> public class DbShutdownImpl implements DbShutdown, 
>> RegistryShutdownListener
>> {
>>     @Inject
>>     private HibernateSessionSource sessionSource;
>>
>>     private final static Logger LOG = 
>> Logger.getLogger(DbShutdownImpl.class);
>>
>>     @PostInjection
>>     public void startupService(RegistryShutdownHub shutdownHub)
>>     {
>>         // make sure session source is real
>>         sessionSource.getSession();
>>         shutdownHub.addRegistryShutdownListener(this);
>>     }
>>
>>     @Override
>>     public void registryDidShutdown()
>>     {
>>         LOG.error("shutdown called");
>>         Session sess = sessionSource.getSession();
>>         Transaction tr = sess.beginTransaction();
>>         sess.createSQLQuery("SHUTDOWN").executeUpdate();
>>         tr.commit();
>>         sess.close();
>>     }
>> }
>>
>>
>>
>>
>>
>> Op 29-11-2010 6:28, Paul Stanton schreef:
>>> Hi all,
>>>
>>> I'm using tapestry-hibernate and an embedded HSQLDB database.
>>>
>>> As you might know, it's important to tell HSQLDB to shutdown when you 
>>> are terminating the vm.
>>>
>>> You do this by executing a proprietary SQL query "SHUTDOWN" before 
>>> closing your last connection.
>>>
>>> Ideally I'd like to use hibernate to execute the SQL query since it 
>>> is already configured to connect to the database.
>>>
>>> Currently I am trying to do it like so:
>>>
>>> public class DbShutdownImpl implements DbShutdown, 
>>> RegistryShutdownListener
>>> {
>>>     @Inject
>>>     private Session session;
>>>
>>>     private final static Logger LOG = 
>>> Logger.getLogger(DbShutdownImpl.class);
>>>
>>>     @PostInjection
>>>     public void startupService(RegistryShutdownHub shutdownHub)
>>>     {
>>>         shutdownHub.addRegistryShutdownListener(this);
>>>     }
>>>
>>>     @Override
>>>     @CommitAfter
>>>     public void registryDidShutdown()
>>>     {
>>>         LOG.error("shutdown called");
>>>         session.createSQLQuery("SHUTDOWN").executeUpdate();
>>>     }
>>> }
>>>
>>> However, I am getting the exception:
>>>
>>> java.lang.RuntimeException: Exception constructing service 'Session': 
>>> Proxy for service Session is no longer active because the IOC 
>>> Registry has been shut down.
>>>     at 
>>>
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78)
>>>     at 
>>>
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)
>>>     at $Session_12c96175d35.delegate($Session_12c96175d35.java)
>>>     at $Session_12c96175d35.createSQLQuery($Session_12c96175d35.java)
>>>     at 
>>> mypackage.DbShutdownImpl.registryDidShutdown(DbShutdownImpl.java:29)
>>>     at 
>>>
org.apache.tapestry5.ioc.internal.services.RegistryShutdownHubImpl.fireRegistryDidShutdown(RegistryShutdownHubImpl.java:57)
>>>     at 
>>>
org.apache.tapestry5.ioc.internal.RegistryImpl.shutdown(RegistryImpl.java:411)
>>>     at 
>>>
org.apache.tapestry5.ioc.internal.RegistryWrapper.shutdown(RegistryWrapper.java:41)
>>>     at 
>>> org.apache.tapestry5.TapestryFilter.destroy(TapestryFilter.java:169)
>>>
>>> I understand that the registry is shutting down and therefore won't 
>>> handle new requests for managed services.
>>>
>>> How do I get around this problem without creating my own JDBC 
>>> connection in my shutdown handler?
>>>
>>> Regards, p.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Paul Stanton <pa...@mapshed.com.au>.
same error, different service which can't be injected.

On 29/11/2010 8:13 PM, Tom van Dijk wrote:
> What if you do this:
>
> public class DbShutdownImpl implements DbShutdown, 
> RegistryShutdownListener
> {
>     @Inject
>     private HibernateSessionSource sessionSource;
>
>     private final static Logger LOG = 
> Logger.getLogger(DbShutdownImpl.class);
>
>     @PostInjection
>     public void startupService(RegistryShutdownHub shutdownHub)
>     {
>         // make sure session source is real
>         sessionSource.getSession();
>         shutdownHub.addRegistryShutdownListener(this);
>     }
>
>     @Override
>     public void registryDidShutdown()
>     {
>         LOG.error("shutdown called");
>         Session sess = sessionSource.getSession();
>         Transaction tr = sess.beginTransaction();
>         sess.createSQLQuery("SHUTDOWN").executeUpdate();
>         tr.commit();
>         sess.close();
>     }
> }
>
>
>
>
>
> Op 29-11-2010 6:28, Paul Stanton schreef:
>> Hi all,
>>
>> I'm using tapestry-hibernate and an embedded HSQLDB database.
>>
>> As you might know, it's important to tell HSQLDB to shutdown when you 
>> are terminating the vm.
>>
>> You do this by executing a proprietary SQL query "SHUTDOWN" before 
>> closing your last connection.
>>
>> Ideally I'd like to use hibernate to execute the SQL query since it 
>> is already configured to connect to the database.
>>
>> Currently I am trying to do it like so:
>>
>> public class DbShutdownImpl implements DbShutdown, 
>> RegistryShutdownListener
>> {
>>     @Inject
>>     private Session session;
>>
>>     private final static Logger LOG = 
>> Logger.getLogger(DbShutdownImpl.class);
>>
>>     @PostInjection
>>     public void startupService(RegistryShutdownHub shutdownHub)
>>     {
>>         shutdownHub.addRegistryShutdownListener(this);
>>     }
>>
>>     @Override
>>     @CommitAfter
>>     public void registryDidShutdown()
>>     {
>>         LOG.error("shutdown called");
>>         session.createSQLQuery("SHUTDOWN").executeUpdate();
>>     }
>> }
>>
>> However, I am getting the exception:
>>
>> java.lang.RuntimeException: Exception constructing service 'Session': 
>> Proxy for service Session is no longer active because the IOC 
>> Registry has been shut down.
>>     at 
>> org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78)
>>     at 
>> org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)
>>     at $Session_12c96175d35.delegate($Session_12c96175d35.java)
>>     at $Session_12c96175d35.createSQLQuery($Session_12c96175d35.java)
>>     at 
>> mypackage.DbShutdownImpl.registryDidShutdown(DbShutdownImpl.java:29)
>>     at 
>> org.apache.tapestry5.ioc.internal.services.RegistryShutdownHubImpl.fireRegistryDidShutdown(RegistryShutdownHubImpl.java:57)
>>     at 
>> org.apache.tapestry5.ioc.internal.RegistryImpl.shutdown(RegistryImpl.java:411)
>>     at 
>> org.apache.tapestry5.ioc.internal.RegistryWrapper.shutdown(RegistryWrapper.java:41)
>>     at 
>> org.apache.tapestry5.TapestryFilter.destroy(TapestryFilter.java:169)
>>
>> I understand that the registry is shutting down and therefore won't 
>> handle new requests for managed services.
>>
>> How do I get around this problem without creating my own JDBC 
>> connection in my shutdown handler?
>>
>> Regards, p.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Tom van Dijk <to...@tvandijk.nl>.
What if you do this:

public class DbShutdownImpl implements DbShutdown, RegistryShutdownListener
{
     @Inject
     private HibernateSessionSource sessionSource;

     private final static Logger LOG = 
Logger.getLogger(DbShutdownImpl.class);

     @PostInjection
     public void startupService(RegistryShutdownHub shutdownHub)
     {
         // make sure session source is real
         sessionSource.getSession();
         shutdownHub.addRegistryShutdownListener(this);
     }

     @Override
     public void registryDidShutdown()
     {
         LOG.error("shutdown called");
         Session sess = sessionSource.getSession();
         Transaction tr = sess.beginTransaction();
         sess.createSQLQuery("SHUTDOWN").executeUpdate();
         tr.commit();
         sess.close();
     }
}





Op 29-11-2010 6:28, Paul Stanton schreef:
> Hi all,
>
> I'm using tapestry-hibernate and an embedded HSQLDB database.
>
> As you might know, it's important to tell HSQLDB to shutdown when you 
> are terminating the vm.
>
> You do this by executing a proprietary SQL query "SHUTDOWN" before 
> closing your last connection.
>
> Ideally I'd like to use hibernate to execute the SQL query since it is 
> already configured to connect to the database.
>
> Currently I am trying to do it like so:
>
> public class DbShutdownImpl implements DbShutdown, 
> RegistryShutdownListener
> {
>     @Inject
>     private Session session;
>
>     private final static Logger LOG = 
> Logger.getLogger(DbShutdownImpl.class);
>
>     @PostInjection
>     public void startupService(RegistryShutdownHub shutdownHub)
>     {
>         shutdownHub.addRegistryShutdownListener(this);
>     }
>
>     @Override
>     @CommitAfter
>     public void registryDidShutdown()
>     {
>         LOG.error("shutdown called");
>         session.createSQLQuery("SHUTDOWN").executeUpdate();
>     }
> }
>
> However, I am getting the exception:
>
> java.lang.RuntimeException: Exception constructing service 'Session': 
> Proxy for service Session is no longer active because the IOC Registry 
> has been shut down.
>     at 
> org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78)
>     at 
> org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)
>     at $Session_12c96175d35.delegate($Session_12c96175d35.java)
>     at $Session_12c96175d35.createSQLQuery($Session_12c96175d35.java)
>     at 
> mypackage.DbShutdownImpl.registryDidShutdown(DbShutdownImpl.java:29)
>     at 
> org.apache.tapestry5.ioc.internal.services.RegistryShutdownHubImpl.fireRegistryDidShutdown(RegistryShutdownHubImpl.java:57)
>     at 
> org.apache.tapestry5.ioc.internal.RegistryImpl.shutdown(RegistryImpl.java:411)
>     at 
> org.apache.tapestry5.ioc.internal.RegistryWrapper.shutdown(RegistryWrapper.java:41)
>     at 
> org.apache.tapestry5.TapestryFilter.destroy(TapestryFilter.java:169)
>
> I understand that the registry is shutting down and therefore won't 
> handle new requests for managed services.
>
> How do I get around this problem without creating my own JDBC 
> connection in my shutdown handler?
>
> Regards, p.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Paul Stanton <pa...@mapshed.com.au>.
Thanks Javier,

this sounds like it would work, but then it also doesn't sound very 
'tapestry-ish' and if it's the only way to achieve this, shows a bit of 
a hole in the tapestry/tapestry-ioc implementation...

is there a better solution?

On 29/11/2010 8:17 PM, Javier Molina wrote:
> Subclass TapestryFilter, map your class instead of Tapestry's in 
> web.xml and override destroy(Registry registry).
>
> There you can use something like:
>
> DbShutdown dbShutdown = registry.getService(DbShutdown.class);
> // add this new method and close the database there
> dbShutdown.shutdownDatabase();
>
>
>
> El 29/11/10 06:28, Paul Stanton escribió:
>> Hi all,
>>
>> I'm using tapestry-hibernate and an embedded HSQLDB database.
>>
>> As you might know, it's important to tell HSQLDB to shutdown when you
>> are terminating the vm.
>>
>> You do this by executing a proprietary SQL query "SHUTDOWN" before
>> closing your last connection.
>>
>> Ideally I'd like to use hibernate to execute the SQL query since it is
>> already configured to connect to the database.
>>
>> Currently I am trying to do it like so:
>>
>> public class DbShutdownImpl implements DbShutdown, 
>> RegistryShutdownListener
>> {
>> @Inject
>> private Session session;
>>
>> private final static Logger LOG = 
>> Logger.getLogger(DbShutdownImpl.class);
>>
>> @PostInjection
>> public void startupService(RegistryShutdownHub shutdownHub)
>> {
>> shutdownHub.addRegistryShutdownListener(this);
>> }
>>
>> @Override
>> @CommitAfter
>> public void registryDidShutdown()
>> {
>> LOG.error("shutdown called");
>> session.createSQLQuery("SHUTDOWN").executeUpdate();
>> }
>> }
>>
>> However, I am getting the exception:
>>
>> java.lang.RuntimeException: Exception constructing service 'Session':
>> Proxy for service Session is no longer active because the IOC Registry
>> has been shut down.
>> at
>> org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78) 
>>
>>
>> at
>> org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57) 
>>
>>
>> at $Session_12c96175d35.delegate($Session_12c96175d35.java)
>> at $Session_12c96175d35.createSQLQuery($Session_12c96175d35.java)
>> at mypackage.DbShutdownImpl.registryDidShutdown(DbShutdownImpl.java:29)
>> at
>> org.apache.tapestry5.ioc.internal.services.RegistryShutdownHubImpl.fireRegistryDidShutdown(RegistryShutdownHubImpl.java:57) 
>>
>>
>> at
>> org.apache.tapestry5.ioc.internal.RegistryImpl.shutdown(RegistryImpl.java:411) 
>>
>>
>> at
>> org.apache.tapestry5.ioc.internal.RegistryWrapper.shutdown(RegistryWrapper.java:41) 
>>
>>
>> at org.apache.tapestry5.TapestryFilter.destroy(TapestryFilter.java:169)
>>
>> I understand that the registry is shutting down and therefore won't
>> handle new requests for managed services.
>>
>> How do I get around this problem without creating my own JDBC connection
>> in my shutdown handler?
>>
>> Regards, p.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Javier Molina <ja...@comunicamultimedia.com>.
Subclass TapestryFilter, map your class instead of Tapestry's in web.xml 
and override destroy(Registry registry).

There you can use something like:

DbShutdown dbShutdown = registry.getService(DbShutdown.class);
// add this new method and close the database there
dbShutdown.shutdownDatabase();



El 29/11/10 06:28, Paul Stanton escribió:
> Hi all,
>
> I'm using tapestry-hibernate and an embedded HSQLDB database.
>
> As you might know, it's important to tell HSQLDB to shutdown when you
> are terminating the vm.
>
> You do this by executing a proprietary SQL query "SHUTDOWN" before
> closing your last connection.
>
> Ideally I'd like to use hibernate to execute the SQL query since it is
> already configured to connect to the database.
>
> Currently I am trying to do it like so:
>
> public class DbShutdownImpl implements DbShutdown, RegistryShutdownListener
> {
> @Inject
> private Session session;
>
> private final static Logger LOG = Logger.getLogger(DbShutdownImpl.class);
>
> @PostInjection
> public void startupService(RegistryShutdownHub shutdownHub)
> {
> shutdownHub.addRegistryShutdownListener(this);
> }
>
> @Override
> @CommitAfter
> public void registryDidShutdown()
> {
> LOG.error("shutdown called");
> session.createSQLQuery("SHUTDOWN").executeUpdate();
> }
> }
>
> However, I am getting the exception:
>
> java.lang.RuntimeException: Exception constructing service 'Session':
> Proxy for service Session is no longer active because the IOC Registry
> has been shut down.
> at
> org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78)
>
> at
> org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)
>
> at $Session_12c96175d35.delegate($Session_12c96175d35.java)
> at $Session_12c96175d35.createSQLQuery($Session_12c96175d35.java)
> at mypackage.DbShutdownImpl.registryDidShutdown(DbShutdownImpl.java:29)
> at
> org.apache.tapestry5.ioc.internal.services.RegistryShutdownHubImpl.fireRegistryDidShutdown(RegistryShutdownHubImpl.java:57)
>
> at
> org.apache.tapestry5.ioc.internal.RegistryImpl.shutdown(RegistryImpl.java:411)
>
> at
> org.apache.tapestry5.ioc.internal.RegistryWrapper.shutdown(RegistryWrapper.java:41)
>
> at org.apache.tapestry5.TapestryFilter.destroy(TapestryFilter.java:169)
>
> I understand that the registry is shutting down and therefore won't
> handle new requests for managed services.
>
> How do I get around this problem without creating my own JDBC connection
> in my shutdown handler?
>
> Regards, p.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by Paul Stanton <pa...@mapshed.com.au>.
thanks thiago, that would work too... however if using a embedded hsqldb 
in production the same problem would occur...

in order to solve my case, it's probably simpler to just create a new 
jdbc connection for shutdown (without hibernate support).

however i'm intrigued that there's no ability to do cross-service 
shutdown within tapestry-ioc?

shall i rephrase the question to

"how do i reference Service A when shutting down Service B" ?

I can see that this would be a reasonably common issue for people and am 
surprised it's not possible...

p.

On 29/11/2010 10:22 PM, Thiago H. de Paula Figueiredo wrote:
> On Mon, 29 Nov 2010 03:28:09 -0200, Paul Stanton <pa...@mapshed.com.au> 
> wrote:
>
>> Hi all,
>
> Hi!
>
>> I'm using tapestry-hibernate and an embedded HSQLDB database.
>
> Another suggestion: why don't you use a non-embedded HSQLDB database 
> while developing? That's what I do when I use HSQLDB. Or launch a 
> thread that sends the "checkpoint" command to HSQLDB every n seconds.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-hibernate, hsqldb and registry shutdown

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 29 Nov 2010 03:28:09 -0200, Paul Stanton <pa...@mapshed.com.au>  
wrote:

> Hi all,

Hi!

> I'm using tapestry-hibernate and an embedded HSQLDB database.

Another suggestion: why don't you use a non-embedded HSQLDB database while  
developing? That's what I do when I use HSQLDB. Or launch a thread that  
sends the "checkpoint" command to HSQLDB every n seconds.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org