Package org.jboss.invocation

Examples of org.jboss.invocation.InterceptorContext


                    clientEntryPoints.put(method, clientInterceptorFactories.get(method).create(factoryContext));
                }
                final Interceptor postConstructInterceptor = clientPostConstruct.create(factoryContext);
                try {
                    Object object = proxyFactory.newInstance(new ProxyInvocationHandler(clientEntryPoints, component, View.this, this));
                    InterceptorContext interceptorContext = new InterceptorContext();
                    interceptorContext.putPrivateData(ComponentView.class, View.this);
                    interceptorContext.putPrivateData(ComponentViewInstance.class, this);
                    interceptorContext.putPrivateData(Component.class, component);
                    try {
                        postConstructInterceptor.processInvocation(interceptorContext);
                    } catch (Exception e) {
                        InstantiationException exception = new InstantiationException("Post-construct lifecycle failed");
                        exception.initCause(e);
View Full Code Here


                return false;
            }

            public void destroy() {
                try {
                    InterceptorContext interceptorContext = new InterceptorContext();
                    interceptorContext.putPrivateData(ComponentView.class, View.this);
                    interceptorContext.putPrivateData(ComponentViewInstance.class, this);
                    interceptorContext.putPrivateData(Component.class, component);
                    preDestroyInterceptor.processInvocation(interceptorContext);
                } catch (Exception e) {
                    logger.warn("Exception while invoking pre-destroy interceptor for component class: " + this.getComponent().getComponentClass(), e);
                }
            }
View Full Code Here

        final SessionBeanComponent component = (SessionBeanComponent) context.getContextData().get(Component.class);

        return new Interceptor() {
            @Override
            public Object processInvocation(final InterceptorContext context) throws Exception {
                final InterceptorContext asyncInterceptorContext = context.clone();
                final CancellationFlag flag = new CancellationFlag();
                final AsyncInvocationTask task = new AsyncInvocationTask( flag) {

                    @Override
                    protected Object runInvocation() throws Exception {
                        return asyncInterceptorContext.proceed();
                    }
                };
                asyncInterceptorContext.putPrivateData(CancellationFlag.class, flag);
                component.getAsynchronousExecutor().execute(task);
                return task;
            }
        };
    }
View Full Code Here

    protected void assertTimerState() {
        if (timerState == TimerState.EXPIRED)
            throw MESSAGES.timerHasExpired();
        if (timerState == TimerState.CANCELED)
            throw MESSAGES.timerWasCanceled();
        final InterceptorContext ctx = CurrentInvocationContext.get();
        if(ctx != null) {
            if(ctx.getPrivateData(Component.class) instanceof StatefulSessionComponent) {
                if(ctx.getMethod() == null) {
                    throw new IllegalStateException("Timer methods may not be invoked from lifecycle methods of a stateful session bean");
                }
            }
        }
    }
View Full Code Here

     * </p>
     *
     * @return
     */
    protected boolean isLifecycleCallbackInvocation() {
        final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
        if(currentInvocationContext == null) {
            return false;
        }
        // If the method in current invocation context is null,
        // then it represents a lifecycle callback invocation
        Method invokedMethod = currentInvocationContext.getMethod();
        if (invokedMethod == null) {
            // it's a lifecycle callback
            return true;
        }
        // not an lifecycle callback
View Full Code Here

    }

    private Object execute(final Interceptor interceptor, final Method method, final Object ... parameters) {
        if (interceptor == null)
            return null;
        final InterceptorContext interceptorContext = new InterceptorContext();
        //we need the method so this does not count as a lifecycle invocation
        interceptorContext.setMethod(method);
        interceptorContext.putPrivateData(Component.class, getComponent());
        interceptorContext.putPrivateData(ComponentInstance.class, this);
        interceptorContext.putPrivateData(InvokeMethodOnTargetInterceptor.PARAMETERS_KEY, parameters);
        interceptorContext.setContextData(new HashMap<String, Object>());
        try {
            return interceptor.processInvocation(interceptorContext);
        } catch (Error e) {
            throw e;
        } catch (RuntimeException e) {
View Full Code Here

        final Interceptor interceptor = timeoutInterceptors.get(method);
        if (interceptor == null) {
            throw MESSAGES.failToCallTimeOutMethod(method);
        }
        try {
            InterceptorContext context = prepareInterceptorContext();
            context.putPrivateData(MethodIntf.class, MethodIntf.TIMER);
            context.setMethod(method);
            context.setTimer(timer);
            context.setTarget(getInstance());
            final Object[] params;
            if (method.getParameterTypes().length == 1) {
                params = new Object[1];
                params[0] = timer;
            } else {
                params = EMPTY_OBJECT_ARRAY;
            }
            context.setParameters(params);
            interceptor.processInvocation(context);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

        }

    }

    private Object invokeMethod(final ComponentView componentView, final Method method, final Object[] args, final EJBLocator ejbLocator, final RemotingAttachments attachments) throws Throwable {
        final InterceptorContext interceptorContext = new InterceptorContext();
        interceptorContext.setParameters(args);
        interceptorContext.setMethod(method);
        interceptorContext.setContextData(new HashMap<String, Object>());
        interceptorContext.putPrivateData(Component.class, componentView.getComponent());
        interceptorContext.putPrivateData(ComponentView.class, componentView);
        if (attachments != null) {
            // attach the RemotingAttachments
            interceptorContext.putPrivateData(RemotingAttachments.class, attachments);
        }
        // add the session id to the interceptor context, if it's a stateful ejb locator
        if (ejbLocator instanceof StatefulEJBLocator) {
            interceptorContext.putPrivateData(SessionID.SESSION_ID_KEY, ((StatefulEJBLocator) ejbLocator).getSessionId());
        } else if (ejbLocator instanceof EntityEJBLocator) {
            final Object primaryKey = ((EntityEJBLocator) ejbLocator).getPrimaryKey();
            interceptorContext.putPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY, primaryKey);
        }
        if (componentView.isAsynchronous(method)) {
            final Component component = componentView.getComponent();
            if (!(component instanceof SessionBeanComponent)) {
                logger.warn("Asynchronous invocations are only supported on session beans. Bean class " + component.getComponentClass()
                        + " is not a session bean, invocation on method " + method + " will have no asynchronous semantics");
                // just invoke normally
                return componentView.invoke(interceptorContext);
            }
            // it's really a async method invocation on a session bean. So treat it accordingly
            final SessionBeanComponent sessionBeanComponent = (SessionBeanComponent) componentView.getComponent();
            final CancellationFlag cancellationFlag = new CancellationFlag();
            // add the cancellation flag to the interceptor context
            interceptorContext.putPrivateData(CancellationFlag.class, cancellationFlag);

            final AsyncInvocationTask asyncInvocationTask = new AsyncInvocationTask(cancellationFlag) {
                @Override
                protected Object runInvocation() throws Exception {
                    return componentView.invoke(interceptorContext);
View Full Code Here

        return utilities.getSecurityManager().getCallerPrincipal();
    }

    protected TransactionAttributeType getCurrentTransactionAttribute() {

        final InterceptorContext invocation = CurrentInvocationContext.get();
        //for timer invocations there is no view, so the methodInf is attached directly
        //to the context. Otherwise we retrive it from the invoked view
        MethodIntf methodIntf = invocation.getPrivateData(MethodIntf.class);
        if (methodIntf == null) {
            final ComponentView componentView = invocation.getPrivateData(ComponentView.class);
            if (componentView != null) {
                methodIntf = componentView.getPrivateData(MethodIntf.class);
            } else {
                methodIntf = MethodIntf.BEAN;
            }
        }

        return getTransactionAttributeType(methodIntf, invocation.getMethod());
    }
View Full Code Here

     * @param primaryKey The primary key to associate the entity with
     */
    public synchronized void associate(Object primaryKey) {
        this.primaryKey = primaryKey;
        try {
            final InterceptorContext context = prepareInterceptorContext();
            final EntityBeanComponent component = getComponent();
            final Method ejbActivateMethod = component.getEjbActivateMethod();
            context.setMethod(ejbActivateMethod);
            ejbActivate.processInvocation(context);
            final InterceptorContext loadContext = prepareInterceptorContext();
            loadContext.setMethod(component.getEjbLoadMethod());
            ejbLoad.processInvocation(loadContext);
        } catch (RemoteException e) {
            throw new WrappedRemoteException(e);
        } catch (RuntimeException e) {
            throw e;
View Full Code Here

TOP

Related Classes of org.jboss.invocation.InterceptorContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.