Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void coreLifecycleExample()
- {
- Manager manager = ManagerBuilder.from()
- .context(SuiteContext.class)
- .extensions(
- ContainerStarter.class,
- ContainerCreator.class).create();
- manager.getContext(SuiteContext.class).activate();
- manager.fire(new BeforeSuite());
- ...
- manager.getContext(SuiteContext.class).detivate();
- }
- // A Extension for the Arquillian beta-1 core
- public class ContainerCreator
- {
- // inject a Instance/Provider style reference(similar to CDI/ATInject) to a Type in one of the active contexts
- @Inject
- private Instance<ServiceLoader> loaderInst;
- // get a reference to a Injector so we can inject Instance refs to non managed objects
- @Inject
- private Instance<Injector> injectorInst;
- // since we intend to set this value, we have to specify to which scope to export it to and use the InstanceProvider
- @Inject @SuiteScoped
- private InstanceProducer<DeployableContainer> deployInst;
- // A external source has fired a BeforeSuite event
- public void loadAndBindDeployableContainer(@Observes BeforeSuite event)
- {
- // load the instance like we normally would do in the SPI land.
- DeployableContainer container = loaderInst.get().onlyOne(DeployableContainer.class);
- // inject into the non managed instance
- injector.get().inject(container);
- // setting a value on a Instance will auto trigger a event of that type.
- // Some extension are not interested in a specific life cycle event, but rather when something becomes available in the Context.
- deployInst.set(container);
- }
- }
- public class ContainerStarter
- {
- // Like Instance, we can get a reference to fire a Event
- @Inject
- private Event<BeforeContainerStart> before;
- @Inject
- private Event<AfterContainerStart> after;
- // We are registered to listen to the availability of a DeployalbeContainer
- public void startContainer(@Observes DeployableContainer container)
- {
- // fire a event
- before.fire(new BeforeContainerStart(container));
- // do the actual work
- container.start();
- // fire a event
- after.fire(new AfterContainerStart(container));
- }
- }
Add Comment
Please, Sign In to add comment