javax.enterprise.context.Destroyed Java Examples

The following examples show how to use javax.enterprise.context.Destroyed. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextImpl.java    From weld-junit with Apache License 2.0 6 votes vote down vote up
public void deactivate() {
    Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get();
    if (ctx == null) {
        return;
    }
    for (ContextualInstance<?> instance : ctx.values()) {
        try {
            instance.destroy();
        } catch (Exception e) {
            LOGGER.warning("Unable to destroy instance" + instance.get() + " for bean: " + instance.getContextual());
        }
    }
    ctx.clear();
    currentContext.remove();
    beanManager.fireEvent(new Object(), Destroyed.Literal.of(scope));
}
 
Example #2
Source File: BeanArchives.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static IndexView buildAdditionalIndex() {
    Indexer indexer = new Indexer();
    // CDI API
    index(indexer, ActivateRequestContext.class.getName());
    index(indexer, Default.class.getName());
    index(indexer, Any.class.getName());
    index(indexer, Named.class.getName());
    index(indexer, Initialized.class.getName());
    index(indexer, BeforeDestroyed.class.getName());
    index(indexer, Destroyed.class.getName());
    index(indexer, Intercepted.class.getName());
    index(indexer, Model.class.getName());
    // Arc built-in beans
    index(indexer, ActivateRequestContextInterceptor.class.getName());
    index(indexer, InjectableRequestContextController.class.getName());
    return indexer.complete();
}
 
Example #3
Source File: H2DatabaseServiceInitializer.java    From apicurio-registry with Apache License 2.0 5 votes vote down vote up
@Override
public void afterAll(@Observes @Destroyed(ApplicationScoped.class) Object event) {
    log.info("Stopping H2 ...");
    if (service != null) {
        service.stop();
    }
}
 
Example #4
Source File: PubSubConnector.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
public void destroy(@Observes @Destroyed(ApplicationScoped.class) final Object context) {
    try {
        executorService.shutdown();
        executorService.awaitTermination(2, TimeUnit.SECONDS);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
 
Example #5
Source File: TransactionBeanWithEvents.java    From quarkus with Apache License 2.0 5 votes vote down vote up
void transactionScopeDestroyed(@Observes @Destroyed(TransactionScoped.class) final Object event,
        final BeanManager beanManager) throws SystemException {
    Transaction tx = tm.getTransaction();
    if (tx != null)
        throw new IllegalStateException("@Destroyed expects no transaction");
    try {
        Context ctx = beanManager.getContext(TransactionScoped.class);
        throw new IllegalStateException("No bean in context expected but it's " + ctx);
    } catch (final ContextNotActiveException expected) {
    }

    destroyedCount++;
}
 
Example #6
Source File: EmbeddedMongoDBSetup.java    From tutorials with MIT License 4 votes vote down vote up
public void destroy(@Observes @Destroyed(ApplicationScoped.class) Object init) {
    System.out.println("Stopping Embedded MongoDB");
    _mongod.stop();
    _mongodExe.stop();
    System.out.println("Embedded MongoDB stopped !");
}
 
Example #7
Source File: ContextLifecycleEventsObserver.java    From weld-junit with Apache License 2.0 4 votes vote down vote up
void onSessionContextDestroy(@Observes @Destroyed(SessionScoped.class) Object event) {
    EVENTS.add(Destroyed.class.getName() + SessionScoped.class.getName());
}
 
Example #8
Source File: ContextLifecycleEventsObserver.java    From weld-junit with Apache License 2.0 4 votes vote down vote up
void onRequestContextDestroy(@Observes @Destroyed(RequestScoped.class) Object event) {
    EVENTS.add(Destroyed.class.getName() + RequestScoped.class.getName());
}
 
Example #9
Source File: ContextLifecycleEventsTest.java    From weld-junit with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void afterAll() {
    // At this time @Destroyed from the previous test method should be fired
    assertTrue(ContextLifecycleEventsObserver.EVENTS.contains(Destroyed.class.getName() + RequestScoped.class.getName()));
    assertTrue(ContextLifecycleEventsObserver.EVENTS.contains(Destroyed.class.getName() + SessionScoped.class.getName()));
}
 
Example #10
Source File: ContextLifecycleEventsObserver.java    From weld-junit with Apache License 2.0 4 votes vote down vote up
void onSessionContextDestroy(@Observes @Destroyed(SessionScoped.class) Object event) {
    EVENTS.add(Destroyed.class.getName() + SessionScoped.class.getName());
}
 
Example #11
Source File: ContextLifecycleEventsObserver.java    From weld-junit with Apache License 2.0 4 votes vote down vote up
void onRequestContextDestroy(@Observes @Destroyed(RequestScoped.class) Object event) {
    EVENTS.add(Destroyed.class.getName() + RequestScoped.class.getName());
}
 
Example #12
Source File: ContextLifecycleEventsTest.java    From weld-junit with Apache License 2.0 4 votes vote down vote up
@AfterAll
public static void afterAll() {
    // At this time @Destroyed from the previous test method should be fired
    assertTrue(ContextLifecycleEventsObserver.EVENTS.contains(Destroyed.class.getName() + RequestScoped.class.getName()));
    assertTrue(ContextLifecycleEventsObserver.EVENTS.contains(Destroyed.class.getName() + SessionScoped.class.getName()));
}
 
Example #13
Source File: AxonCdiExtension.java    From cdi with Apache License 2.0 4 votes vote down vote up
void destroy(@Observes @Destroyed(ApplicationScoped.class) final Object destroyed) {
}
 
Example #14
Source File: ApplicationInitializedTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
void destroyed(@Observes @Destroyed(ApplicationScoped.class) Object container) {
    DESTROYED.set(true);
}
 
Example #15
Source File: ContextObserver.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void observeContextDestroyed(@Observes @Destroyed(RequestScoped.class) Object event) {
    destroyedObserved++;
}
 
Example #16
Source File: RequestContext.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static Notifier<Object> createDestroyedNotifier() {
    return EventImpl.createNotifier(Object.class, Object.class,
            new HashSet<>(Arrays.asList(Destroyed.Literal.REQUEST, Any.Literal.INSTANCE)),
            ArcContainerImpl.instance());
}
 
Example #17
Source File: MqttConnector.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
public void destroy(@Observes @Destroyed(ApplicationScoped.class) final Object context) {
    Clients.clear();
}
 
Example #18
Source File: ServiceInitializer.java    From apicurio-registry with Apache License 2.0 votes vote down vote up
default void afterAll(@Observes @Destroyed(ApplicationScoped.class) Object event) {}