You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by David Avenante <d....@gmail.com> on 2007/05/22 23:09:21 UTC

T5 initialize and start a service through the ioc container

Hi,

I try to initialize and start a service when my webapp start.

My service is a simple Quartz scheduler with a job. But i've some trouble to
start the service.
As i can see Tapestry IOC use lazy initialization so my service is build
only when used.

My code in my Appodule.java is like :

   // The scheduler
   public Scheduler buildScheduler() throws SchedulerException {

        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();
        scheduler.start();

        return scheduler;
    }

    // Register my service
    public static void bind(ServiceBinder binder) {
        binder.bind(IndexScheduler.class, IndexSchedulerImpl.class);
    }

    // The trigger
    public Trigger buildTrigger() {
        return TriggerUtils.makeMinutelyTrigger(5);
    }


My IndexSchedulerImpl take two contructor's parameters  : scheduler and
trigger.
The probleme is my object is never instanciate if nobody call us (lazy
initialization)

I reach my goal if i pass my indexscheduler in a method used by tapestry
like contributeRequestHandler(OrderedConfiguration<RequestFilter>
configuration ...
IndexScheduler indexScheduler) and add @EagerLoad to my bind method.

But i'm sure there is a more clean practice to reach my goal.

Thank's.

Re: T5 initialize and start a service through the ioc container

Posted by Howard Lewis Ship <hl...@gmail.com>.
I think you are on the right track.  @EagerLoad on the service builder
method (or on the service implementation class if using the ServiceBinder)
will generally do the trick.

However, if you have any dependencies, it gets trickier because Tapestry has
to fully initialize before some dependencies can be resolved.  For the
moment, you should use @InjectService to explicitly identify any
dependencies.

On 5/22/07, David Avenante <d....@gmail.com> wrote:
>
> Hi,
>
> I try to initialize and start a service when my webapp start.
>
> My service is a simple Quartz scheduler with a job. But i've some trouble
> to
> start the service.
> As i can see Tapestry IOC use lazy initialization so my service is build
> only when used.
>
> My code in my Appodule.java is like :
>
>    // The scheduler
>    public Scheduler buildScheduler() throws SchedulerException {
>
>         SchedulerFactory schedulerFactory = new StdSchedulerFactory();
>         Scheduler scheduler = schedulerFactory.getScheduler();
>         scheduler.start();
>
>         return scheduler;
>     }
>
>     // Register my service
>     public static void bind(ServiceBinder binder) {
>         binder.bind(IndexScheduler.class, IndexSchedulerImpl.class);
>     }
>
>     // The trigger
>     public Trigger buildTrigger() {
>         return TriggerUtils.makeMinutelyTrigger(5);
>     }
>
>
> My IndexSchedulerImpl take two contructor's parameters  : scheduler and
> trigger.
> The probleme is my object is never instanciate if nobody call us (lazy
> initialization)
>
> I reach my goal if i pass my indexscheduler in a method used by tapestry
> like contributeRequestHandler(OrderedConfiguration<RequestFilter>
> configuration ...
> IndexScheduler indexScheduler) and add @EagerLoad to my bind method.
>
> But i'm sure there is a more clean practice to reach my goal.
>
> Thank's.
>



-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com