incubator-s4-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leo Neumeyer <leoneume...@gmail.com>
Subject Re: Guice instantiation
Date Thu, 03 Nov 2011 20:53:00 GMT
The Server class is a singleton enforced by the Guice Module:

bind(Server.class).asEagerSingleton();

The Sender/Receiver objects are enforced using the @Singleton annotation:

@Singleton public class Sender { ...

@Singleton public class Receiver implements Runnable { ...


App programmers shouldn't have to deal with Sender/Receiver at all.

S4 developers shouldn't have to do anything if they use Server as the entry
point. If you create apps using some other method, then you need to enforce
it yourself. Guice will give you the same instance as long as you use the
same injector.

-leo

On Thu, Nov 3, 2011 at 1:40 PM, kishore g <g.kishore@gmail.com> wrote:

> I see, then the Module/injector must be created only once in a jvm ?
>
> When you say singleton are they enforced or responsibility of the developer
> ?, I created two apps from different modules and  both acquired different
> tasks.
>
> thanks,
> Kishore G
>
> On Thu, Nov 3, 2011 at 10:32 AM, Leo Neumeyer <leoneumeyer@gmail.com>
> wrote:
>
> > They are Singletons.
> >
> > Check this snippet from Server. The Server singleton has the reference to
> > the sender and receiver singletons. We pass the references via loadApp().
> > Does this make sense?
> >
> > /* After some indirection we get the injector. */
> >        injector = Guice.createInjector(module);
> >
> >        Sender sender = injector.getInstance(Sender.class);
> >        Receiver receiver = injector.getInstance(Receiver.class);
> >
> >        // File[] s4rFiles = new File(appsDir).listFiles(new
> > PatternFilenameFilter("\\w+\\.s4r"));
> >        File[] s4rFiles = new File(appsDir).listFiles(new
> > PatternFilenameFilter(".+.s4r"));
> >        for (File s4rFile : s4rFiles) {
> >            logger.info("Loading app: " + s4rFile.getPath());
> >            loadApp(sender, receiver, s4rFile);
> >        }
> >
> >        /* Now init + start apps. TODO: implement dynamic
> loading/unloading
> > using ZK. */
> >        for (App app : apps) {
> >            logger.info("Starting app " + app.getClass().getName());
> >            app.init();
> >            app.start();
> >        }
> >
> >
> >
> > Leo Neumeyer (@leoneu)
> >
> >
> >
> > On Nov 3, 2011, at 10:20 AM, kishore g wrote:
> >
> > > Hi,
> > >
> > > Will creation of every App create a new instance of sender/receiver
> which
> > > creates Assignment and Topology ?. How to share these between Apps
> > >
> > > thanks,
> > > Kishore G
> >
> >
>



-- 

Leo Neumeyer (@leoneu)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message