Package org.jboss.invocation

Examples of org.jboss.invocation.InterceptorContext


    public final void destroy() {
        if (doneUpdater.compareAndSet(this, 0, 1)) try {
            preDestroy();
            final Object instance = getInstance();
            if (instance != null) {
                final InterceptorContext interceptorContext = prepareInterceptorContext();
                interceptorContext.setTarget(instance);
                interceptorContext.putPrivateData(InvocationType.class, InvocationType.PRE_DESTROY);
                preDestroy.processInvocation(interceptorContext);
            }
        } catch (Exception e) {
            ROOT_LOGGER.componentDestroyFailure(e, this);
        } finally {
View Full Code Here


    protected void preDestroy() {

    }

    protected InterceptorContext prepareInterceptorContext() {
        final InterceptorContext interceptorContext = new InterceptorContext();
        interceptorContext.putPrivateData(Component.class, component);
        interceptorContext.putPrivateData(ComponentInstance.class, this);
        interceptorContext.setContextData(new HashMap<String, Object>());
        return interceptorContext;
    }
View Full Code Here

    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
        final Interceptor interceptor = interceptors.get(method);
        if (interceptor == null) {
            throw new NoSuchMethodError(method.toString());
        }
        final InterceptorContext context = new InterceptorContext();
        // special location for original proxy
        context.putPrivateData(Object.class, proxy);
        context.putPrivateData(Component.class, componentView.getComponent());
        context.putPrivateData(ComponentView.class, componentView);
        instance.prepareInterceptorContext(context);
        context.setParameters(args);
        context.setMethod(method);
        // setup the public context data
        context.setContextData(new HashMap<String, Object>());
        return interceptor.processInvocation(context);
    }
View Full Code Here

     */
    public void destroy() {
        if (doneUpdater.compareAndSet(this, 0, 1)) try {
            final ManagedReference reference = instanceReference.get();
            if (reference != null) {
                final InterceptorContext interceptorContext = prepareInterceptorContext();
                interceptorContext.setTarget(reference.getInstance());
                preDestroy.processInvocation(interceptorContext);
            }
        } catch (Exception e) {
            ROOT_LOGGER.componentDestroyFailure(e, this);
        } finally {
View Full Code Here

            component.finishDestroy();
        }
    }

    protected InterceptorContext prepareInterceptorContext() {
        final InterceptorContext interceptorContext = new InterceptorContext();
        interceptorContext.putPrivateData(Component.class, component);
        interceptorContext.putPrivateData(ComponentInstance.class, this);
        interceptorContext.setContextData(new HashMap<String, Object>());
        return interceptorContext;
    }
View Full Code Here

        // create the component instance
        final BasicComponentInstance basicComponentInstance = this.instantiateComponentInstance(instanceReference, componentInstancePreDestroyInterceptor, interceptorMap, context);

        if (invokePostConstruct) {
            // now invoke the postconstruct interceptors
            final InterceptorContext interceptorContext = new InterceptorContext();
            interceptorContext.putPrivateData(Component.class, this);
            interceptorContext.putPrivateData(ComponentInstance.class, basicComponentInstance);
            interceptorContext.setContextData(new HashMap<String, Object>());

            try {
                componentInstancePostConstructInterceptor.processInvocation(interceptorContext);
            } catch (Exception e) {
                throw MESSAGES.componentConstructionFailure(e);
View Full Code Here

    /**
     * Checks that the current method
     */
    public static void checkAllowed(final MethodType methodType) {

        final InterceptorContext context = CurrentInvocationContext.get();
        if (context == null) {
            return;
        }

        final Component component = context.getPrivateData(Component.class);
        if (!(component instanceof EJBComponent)) {
            return;
        }
        final InvocationType invocationType = context.getPrivateData(InvocationType.class);

        ((EJBComponent) component).getAllowedMethodsInformation().realCheckPermission(methodType, invocationType);

    }
View Full Code Here

        final SessionID sessionID = statefulEJBLocator.getSessionId();
        return statefulSessionComponent.getCache().getWeakAffinity(sessionID);
    }

    private Object invokeMethod(final ComponentView componentView, final Method method, final Object[] args, final EJBLocator ejbLocator, final Map<String, Object> 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);
        interceptorContext.putPrivateData(InvocationType.class, InvocationType.REMOTE);
        if (attachments != null) {
            // attach the attachments which were passed from the remote client
            for (final Map.Entry<String, Object> attachment : attachments.entrySet()) {
                if (attachment == null) {
                    continue;
                }
                final String key = attachment.getKey();
                final Object value = attachment.getValue();
                // add it to the context
                interceptorContext.putPrivateData(key, value);
            }
        }
        // add the session id to the interceptor context, if it's a stateful ejb locator
        if (ejbLocator instanceof StatefulEJBLocator) {
            interceptorContext.putPrivateData(SessionID.class, ((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

    protected Object invokeEjbCreate(final Map<Object, Object> contextData, final Method ejbCreate, final EntityBeanComponentInstance instance, final Object[] params) throws Exception {

        //there will always be an invocation
        //as this is only used from home invocations
        final InterceptorContext context = CurrentInvocationContext.get();
        final InvocationType invocationType = context.getPrivateData(InvocationType.class);
        try {
            context.putPrivateData(InvocationType.class, InvocationType.ENTITY_EJB_CREATE);
            return ejbCreate.invoke(instance.getInstance(), params);
        } catch (InvocationTargetException e) {
            throw Interceptors.rethrow(e.getCause());
        }finally {
            context.putPrivateData(InvocationType.class, invocationType);
        }
    }
View Full Code Here

            for (int i = 0; i < parameters.length; ++i) {
                parameters[i] = clone(method.getParameterTypes()[i], parameterCloner, invocation.getParameters()[i], allowPassByReference);
            }
        }

        final InterceptorContext context = new InterceptorContext();
        context.setParameters(parameters);
        context.setMethod(method);
        context.setTarget(invocation.getInvokedProxy());
        context.setContextData(new HashMap<String, Object>());
        context.putPrivateData(Component.class, ejbComponent);
        context.putPrivateData(ComponentView.class, view);


        if (locator instanceof StatefulEJBLocator) {
            final SessionID sessionID = ((StatefulEJBLocator) locator).getSessionId();
            context.putPrivateData(SessionID.class, sessionID);
        } else if (locator instanceof EntityEJBLocator) {
            final Object primaryKey = ((EntityEJBLocator) locator).getPrimaryKey();
            context.putPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY, primaryKey);
        }

        final ClonerConfiguration config = new ClonerConfiguration();
        config.setClassCloner(new ClassLoaderClassCloner(invocation.getInvokedProxy().getClass().getClassLoader()));
        final ObjectCloner resultCloner = ObjectCloners.getSerializingObjectClonerFactory().createCloner(config);
        if (async) {
            if (ejbComponent instanceof SessionBeanComponent) {
                final SessionBeanComponent component = (SessionBeanComponent) ejbComponent;
                final CancellationFlag flag = new CancellationFlag();
                final AsyncInvocationTask task = new AsyncInvocationTask(flag) {

                    @Override
                    protected Object runInvocation() throws Exception {
                        return view.invoke(context);
                    }
                };
                context.putPrivateData(CancellationFlag.class, flag);
                component.getAsynchronousExecutor().submit(task);
                //TODO: we do not clone the result of an async task
                //TODO: we do not clone the exception of an async task
                receiverContext.resultReady(new ImmediateResultProducer(task));
            } else {
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.