It was appearently easy. Registry + PerThreadManager. The only thing I need
to learn now is how to invoke a method using the IOC.


2013/9/23 Martin Kersten <martin.kersten...@gmail.com>

> @Lance
> SessionSource is not perThread but HibernateManager is. And on
> instanciation the HibernateManager creates the session object. And the
> Session is retrieved by calling HibernateManager.getSession(). So
> SessionSource is global and you can create many sessions per thread but
> HibernateManager is thread aware and holds only one session object.
>
> So the only thing left to do is learn how to trigger a construction of my
> service or hibernate manager service in my own thread. I guess this is in
> the user guide somewhere.
>
>
> 2013/9/22 Martin Kersten <martin.kersten...@gmail.com>
>
>> @Lance
>> Using Hibernate SessionSource will just create a new session with no
>> thread local awareness. Is there another service that gives me a per thread
>> session? Would be nice to have a service that automatically gives the
>> session of the current thread? Especially if the thread local thingy is
>> working outside of the page processing?
>>
>> @Barry
>> I just managed to find out that my other service is also PerThread Scope
>> so I need support for this. I will check out if I can get the IOC to work
>> outside the page processing and have support for perThread scope.
>>
>> I will also try out a resteasy tapestry page to inject the service and
>> compose it as PerThread scope.
>> But I will use a simple worker thread to trigger the page call. Cron jobs
>> are good but I need the possibility to end the waiting phase and issue the
>> processing of tasks instantly.
>>
>>
>> 2013/9/22 Barry Books <trs...@gmail.com>
>>
>>> It's much easier to just create a page at let Tapestry handle the
>>> threading. That's what it's built to do.
>>>
>>> You can just add synchronized to method if you only want one invocation
>>> at
>>> a time.
>>>
>>> If you don't want Hudson. Then I'd create a cron service that takes a
>>> configuration of times/urls and calls the pages. That would make it easy
>>> to
>>> work either way. I have used Tapestry scheduling but found it's much
>>> better
>>> to to have external control over running tasks. I think someone said
>>>
>>> Any sufficiently complicated application contains an ad hoc,
>>> informally-specified, bug-ridden <
>>> http://en.wikipedia.org/wiki/Computer_bug>,
>>> slow implementation of half of Hudson.
>>>
>>>
>>> On Sun, Sep 22, 2013 at 4:53 AM, Martin Kersten <
>>> martin.kersten...@gmail.com
>>> > wrote:
>>>
>>> > Thanks Lance. This cleanup advise was what i was looking for. Cheers.
>>> >
>>> >
>>> > 2013/9/22 Lance Java <lance.j...@googlemail.com>
>>> >
>>> > > Igor has written a blog about scheduling jobs with tapestry here
>>> > >
>>> > >
>>> >
>>> http://blog.tapestry5.de/index.php/2011/09/18/scheduling-jobs-with-tapestry/
>>> > >
>>> > > The hibernate session provided by tapestry is a singleton and can be
>>> > > injected as any other service. The singleton is a proxy to a
>>> per-thread
>>> > > instance which is created on demand and cleaned up by
>>> > > PerThreadManager.cleanup().
>>> > > If you use the PeriodicExecutor or the ParallelExecutor then the (per
>>> > > thread) hibernate session will be cleaned up after your job runs. If
>>> you
>>> > > are not using these services (ie you are using java.util.concurrent.*
>>> > > directly) then you will need to call either
>>> PerThreadManager.cleanup() or
>>> > > Registry.cleanupThread() explicitly to close the hibernate session.
>>> > >
>>> > >
>>> > >
>>> > > On 22 September 2013 08:12, Martin Kersten <
>>> martin.kersten...@gmail.com
>>> > > >wrote:
>>> > >
>>> > > > :) I know Barry. I marked your former post about this. But I dont
>>> want
>>> > a
>>> > > > page right now.
>>> > > >
>>> > > > But this calling it directly ... well that is a good one. But
>>> > > object.notify
>>> > > > is also easy and makes it possible to assume only one invocation
>>> of the
>>> > > > processor is running once at a time per JVM.
>>> > > >
>>> > > > But sadly making the process a singleton I have again the Hibernate
>>> > > Session
>>> > > > stuff.
>>> > > >
>>> > > >
>>> > > > 2013/9/21 Barry Books <trs...@gmail.com>
>>> > > >
>>> > > > > Here is what I do:
>>> > > > >
>>> > > > > 1. Write a simple service that just performs the action you want
>>> > > > > 2. If you need real time processing just call it.
>>> > > > > 3. Create a page that just calls the service and schedule
>>> accessing
>>> > > that
>>> > > > > page with Hudson/curl
>>> > > > >
>>> > > > >
>>> > > > > On Sat, Sep 21, 2013 at 2:41 PM, Martin Kersten <
>>> > > > > martin.kersten...@gmail.com
>>> > > > > > wrote:
>>> > > > >
>>> > > > > > Hi there,
>>> > > > > >
>>> > > > > >
>>> > > > > >    I need to implement a service that reads tasks
>>> (descriptions)
>>> > from
>>> > > > the
>>> > > > > > database, does some tasks and sleeps again. The thread must be
>>> able
>>> > > to
>>> > > > > woke
>>> > > > > > up if an other service demands just in time processing.
>>> > > > > >
>>> > > > > > Requirements:
>>> > > > > > 1. Need a Hibernate Session inside the main loop.
>>> > > > > > 2. Needs to be able to woke up (just use Object.notify and
>>> > > > Object.wait).
>>> > > > > > 3. Needs to sleep for a couple of minutes, check db for work
>>> and
>>> > > sleep
>>> > > > > > again.
>>> > > > > > 4. On shut down it needs to suspend and decompose gracefully.
>>> > > > > >     What is the best way to do so?
>>> > > > > >
>>> > > > > > So first I looked at periodic job etc. Nothing to use. So it
>>> ends
>>> > up
>>> > > > > doing
>>> > > > > > some kind of a
>>> > > > > > service that spawns a thread and the thread does all the
>>> > progressing.
>>> > > > > >
>>> > > > > > The thread itself uses a runnable to guard against failures and
>>> > those
>>> > > > > > failures are logged
>>> > > > > > within each task during which the failure occures.
>>> > > > > >
>>> > > > > > So here comes the big question:
>>> > > > > >
>>> > > > > > What should I do.
>>> > > > > >
>>> > > > > > The naive answer is using a SessionSource and create a session
>>> each
>>> > > > time
>>> > > > > > the thread's
>>> > > > > > runnable starts the processing.
>>> > > > > >
>>> > > > > > Another idea would be set up the worker part as a service that
>>> is
>>> > > > created
>>> > > > > > every time and
>>> > > > > > let the IOC do all the session creation and handling. But I
>>> fear
>>> > that
>>> > > > > this
>>> > > > > > is way more
>>> > > > > > complicated then the SessionSource idea.
>>> > > > > >
>>> > > > > > The decomposition on the teardown of the tapestry application
>>> > > requires
>>> > > > to
>>> > > > > > deal with
>>> > > > > > certain kind of listeners. What is the best service to add the
>>> > > listener
>>> > > > > > too?
>>> > > > > >
>>> > > > > >
>>> > > > > > Thanks in advance,
>>> > > > > >
>>> > > > > > Martin (Kersten)
>>> > > > > >
>>> > > > >
>>> > > >
>>> > >
>>> >
>>>
>>
>>
>

Reply via email to