Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sisu-users] Should I be able to use @PostConstruct on an abstract class?

On 15 February 2014 16:20, Benson Margulies <benson@xxxxxxxxxxxxx> wrote:
On Sat, Feb 15, 2014 at 11:15 AM, Stuart McCulloch <mcculls@xxxxxxxxx> wrote:
On 15 February 2014 02:23, Benson Margulies <benson@xxxxxxxxxxxxx> wrote:
Correct, at the moment the new LifecycleModule is not installed by default in InjectedTest(Case). Similarly it's not installed by default in the other launch-related classes. I wanted to give people a chance to install it and try it out first before enabling it everywhere, and even then we should give people a way to disable it so they can use alternative @PostConstruct/@PreDestroy lifecycle extensions such as the one from Apache/Onami.

Btw, InjectedTest(Case) has a configure(Binder) method that lets you install modules or add bindings:

    @Override
    public void configure( Binder binder )
    {
        binder.install( new LifecycleModule() );
    }

Oh! I had no idea you could add one later. I guess that means that it does not need to be inside of WireModule.

It will be inside the WireModule because the first thing that SetUpModule does is install the actual test class (which is itself a module)

    final class SetUpModule
        implements Module
    {
        public void configure( final Binder binder )
        {
            binder.install( InjectedTest.this );    //  <--- this refers to the current test class instance
            // ...etc...

and this ends up calling the configure(Binder) method of the test class. This part of the codebase does need updating though to match the fluent style used in BundleModule and other classes, so something like a setUpModule() method would probably make sense.
 
However, my patch might be helpful for someone who _does_ need to be inside of WireModule, I suppose.

Note you're currently responsible for deciding when to call the unmanage method of the BeanManager which kicks off the @PreDestroy cycle:

    public void tearDown()
        throws Exception
    {
        lookup( BeanManager.class ).unmanage();
    }

This is so you can tie this to other shutdown hooks that you might already have in your launcher, but I'm also looking at alternative ways to trigger this.
 
M3?

0.2.0 passed its release review, so unless there's a blocker this weekend the next release will be 0.2.0 - soon to be followed by the first 0.3.0 milestone.
 
Can anyone tell me how to make IntelliJ and the sisu source get along?

When editing InjectTest, IntelliJ claims that it does not have junit or testng in the classpath. I don't understand why.

Looks like IntelliJ doesn't fully support Maven/Tycho based projects:


We might be able to work round this by duplicating the dependencies defined in the target platform (which tycho adds as dependencies at build time) - it's just a bit annoying managing versions in multiple places (target platform vs pom) and keeping them all in sync, especially when the versions differ slightly between central and the Eclipse Orbit repository.

 
Get along in what way?
 
On Fri, Feb 14, 2014 at 9:01 PM, Benson Margulies <benson@xxxxxxxxxxxxx> wrote:
The PostConstruct is not called. I'm using 0.2.M2

@Named
public abstract class AbstractWsBusComponent implements WsBusComponent {
    @Inject
    protected MetricRegistry metrics;
    private Timer requests;

    @PostConstruct
    public void postConstruct() {
        requests = metrics.timer(name(getClass(), "requests"));
    }


    @Override
    public final Text process(WsBusComponentInput input) {
        Timer.Context context = requests.time();
        try {
            return processImplementation(input);
        } finally {
            context.stop();
        }
    }

    protected abstract Text processImplementation(WsBusComponentInput input);
}

--
Cheers, Stuart

Back to the top