コード例 #1
0
  public void destroySession(@Observes BeforeUnDeploy event, WeldManager manager) {
    BoundSessionContext sessionContext = manager.instance().select(BoundSessionContext.class).get();

    CDISessionMap map = sessionMap.get();
    if (map != null) {
      try {
        sessionContext.invalidate();
        sessionContext.deactivate();
      } finally {
        sessionContext.dissociate(map);
      }
    }
  }
コード例 #2
0
    public Void call() throws Exception {

      sessionContext.associate(storage);
      sessionContext.activate();

      try {
        // Invoke the proxy - force bean instance creation
        product.ping();

        sessionContext.invalidate();
        sessionContext.deactivate();
      } finally {
        sessionContext.dissociate(storage);
      }
      return null;
    }
コード例 #3
0
  @SuppressWarnings("unchecked")
  public void teardown(Map<String, Object> properties) {
    try {
      final BeanManager manager =
          (BeanManager) new InitialContext().lookup("java:comp/BeanManager");

      if (manager != null && Container.available()) {
        final Bean<BoundSessionContext> sessionContextBean =
            (Bean<BoundSessionContext>)
                manager.resolve(manager.getBeans(BoundSessionContext.class, BoundLiteral.INSTANCE));
        CreationalContext<?> ctx = manager.createCreationalContext(sessionContextBean);
        final BoundSessionContext sessionContext =
            (BoundSessionContext)
                manager.getReference(sessionContextBean, BoundSessionContext.class, ctx);
        sessionContext.deactivate();
        sessionContext.dissociate(sessionContexts.get());

        final Bean<BoundRequestContext> requestContextBean =
            (Bean<BoundRequestContext>)
                manager.resolve(manager.getBeans(BoundRequestContext.class, BoundLiteral.INSTANCE));
        ctx = manager.createCreationalContext(requestContextBean);
        final BoundRequestContext requestContext =
            (BoundRequestContext)
                manager.getReference(requestContextBean, BoundRequestContext.class, ctx);
        requestContext.deactivate();
        requestContext.dissociate(requestContexts.get());

        final Bean<BoundConversationContext> conversationContextBean =
            (Bean<BoundConversationContext>)
                manager.resolve(
                    manager.getBeans(BoundConversationContext.class, BoundLiteral.INSTANCE));
        ctx = manager.createCreationalContext(conversationContextBean);
        final BoundConversationContext conversationContext =
            (BoundConversationContext)
                manager.getReference(conversationContextBean, BoundConversationContext.class, ctx);
        conversationContext.deactivate();
        conversationContext.dissociate(boundRequests.get());
      }
    } catch (NamingException e) {
      log.error("Failed to tear down Weld contexts", e);
    } finally {
      sessionContexts.remove();
      requestContexts.remove();
      boundRequests.remove();
    }
  }