Package org.rhq.enterprise.communications.command.impl.remotepojo

Examples of org.rhq.enterprise.communications.command.impl.remotepojo.RemotePojoInvocationCommandResponse


         */
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            String methodName = method.getName();
            String[] paramSig = createParamSignature(method.getParameterTypes());
            NameBasedInvocation invocation = new NameBasedInvocation(methodName, args, paramSig);
            RemotePojoInvocationCommandResponse response = null;
            Throwable throwable = null;

            RemotePojoInvocationCommand cmd = new RemotePojoInvocationCommand();
            cmd.setNameBasedInvocation(invocation);
            cmd.setTargetInterfaceName(m_targetInterfaceName);

            boolean async_mode_enabled = determineAsynchronous(method);
            Long timeout = determineTimeout(method);
            boolean guaranteed_delivery = determineGuaranteedDelivery(method);
            boolean send_throttle_enabled = determineSendThrottling(method);

            if (send_throttle_enabled) {
                cmd.getConfiguration().setProperty(ClientCommandSender.CMDCONFIG_PROP_SEND_THROTTLE,
                    Boolean.toString(true));
            }

            if (timeout != null) {
                cmd.getConfiguration().setProperty(ClientCommandSender.CMDCONFIG_PROP_TIMEOUT, timeout.toString());
            }

            try {
                if (async_mode_enabled) {
                    if (guaranteed_delivery) {
                        m_clientCommandSender.sendAsynchGuaranteed(cmd, m_proxyHandlerAsyncCallback);
                    } else {
                        m_clientCommandSender.sendAsynch(cmd, m_proxyHandlerAsyncCallback);
                    }
                } else {
                    CommandResponse sendsync_response = m_clientCommandSender.sendSynch(cmd);
                    response = new RemotePojoInvocationCommandResponse(sendsync_response);

                    // throw the exception if one occurred
                    if (response.getException() != null) {
                        throw response.getException();
                    }
                }
            } catch (CannotConnectException cce) {
                // we can perform some retry or failover mechanism here - see JBoss/Remoting TransporterClient for an example
                throwable = cce;
            } catch (InvocationTargetException ite) {
                Throwable root = ite.getCause();
                throwable = (root == null) ? ite : root;
            } catch (Throwable e) {
                throwable = e;
            }

            // if some failure occured, we need to do different things depending on the enablement of the async mode.
            // if async mode is enabled, let's create a command response to indicate the error and notify the callback
            // if async mode is disabled (i.e. we are in sync mode), then just throw the exception.
            // TODO [mazz]: do we want this behavior - the callback will get the failure response and that same response
            //              will be returned not sure if we just want to throw the exception no matter what
            if (throwable != null) {
                LOG.debug(CommI18NResourceKeys.CLIENT_REMOTE_POJO_INVOKER_EXECUTION_FAILURE, methodName, ThrowableUtil
                    .getAllMessages(throwable, true));

                if (async_mode_enabled) {
                    response = new RemotePojoInvocationCommandResponse(cmd, throwable);

                    if (m_proxyHandlerAsyncCallback != null) {
                        m_proxyHandlerAsyncCallback.commandSent(response);
                    }
                } else {
                    throw throwable;
                }
            }

            Object invoke_return = null;

            if (response != null) {
                invoke_return = response.getResults();

                // if the returned object is a remote stream, we need to tell it how to request stream data
                // by giving it the client command sender that will be used to send those requests
                if (invoke_return instanceof RemoteInputStream) {
                    ((RemoteInputStream) invoke_return).setClientCommandSender(m_clientCommandSender);
View Full Code Here


        Class<?>[] class_signature = new Class[signature.length];

        Permit permit = null;
        Method pojo_method = null;

        RemotePojoInvocationCommandResponse response;

        ConcurrencyManager concurrency_manager = getServiceContainer().getConcurrencyManager();

        try {
            // look up the remote POJO that has the target interface
            Object pojo = m_remotedPojos.get(target_interface_name);

            if (pojo == null) {
                throw new NoSuchMethodException(LOG.getMsgString(CommI18NResourceKeys.NO_POJO_SERVICE, command));
            }

            for (int x = 0; x < signature.length; x++) {
                class_signature[x] = ClassUtil.getClassFromTypeName(signature[x]);
            }

            // If the remote POJO interface method has limited concurrency allowed, we need to make
            // sure we have permission to invoke that method. None of these calls should throw an exception.
            Class<?> target_interface = Class.forName(target_interface_name);
            Method target_method = target_interface.getMethod(method_name, class_signature);
            LimitedConcurrency limited_concurrency = target_method.getAnnotation(LimitedConcurrency.class);
            if ((limited_concurrency != null) && (concurrency_manager != null)) {
                permit = concurrency_manager.getPermit(limited_concurrency.value());
            }

            // if a parameter is a remote stream, we have to create a sender for it to use
            // this is needed in case the remote server that is serving the stream data requires SSL - in that
            // case, our sender needs to have SSL configured properly
            for (int x = 0; x < signature.length; x++) // yes use signature, not param - avoids possible NPE
            {
                if (params[x] instanceof RemoteInputStream) {
                    prepareRemoteInputStream((RemoteInputStream) params[x]);
                } else if (params[x] instanceof RemoteOutputStream) {
                    prepareRemoteOutputStream((RemoteOutputStream) params[x]);
                }
            }

            // use reflection to make the call
            pojo_method = pojo.getClass().getMethod(method_name, class_signature);
            Object response_object = pojo_method.invoke(pojo, params);

            response = new RemotePojoInvocationCommandResponse(remote_pojo_command, response_object);
        } catch (InvocationTargetException e) {
            // we want to make sure we keep the exception as intact as possible
            // so we still want to put the invocation target exception in the response,
            // but that is a java.* exception, so we need to drill down into the cause and wrap that if need be
            Throwable response_exception;

            if (e.getCause() != null) {
                response_exception = new InvocationTargetException(getWrappedException(e.getCause(), pojo_method), e
                    .getMessage());
            } else {
                response_exception = getWrappedException(e, pojo_method);
            }

            response = new RemotePojoInvocationCommandResponse(remote_pojo_command, response_exception);
        } catch (NotPermittedException npe) {
            LOG.debug(CommI18NResourceKeys.COMMAND_NOT_PERMITTED, target_interface_name + '.' + method_name, npe
                .getSleepBeforeRetry());
            response = new RemotePojoInvocationCommandResponse(remote_pojo_command, npe);
        } catch (Exception e) {
            LOG.warn(e, CommI18NResourceKeys.REMOTE_POJO_EXECUTE_FAILURE);
            response = new RemotePojoInvocationCommandResponse(remote_pojo_command, getWrappedException(e, pojo_method));
        } finally {
            if (concurrency_manager != null) {
                concurrency_manager.releasePermit(permit);
            }
        }
View Full Code Here

    public void commandSent(CommandResponse response) {
        synchronized (this) {
            if (response instanceof RemotePojoInvocationCommandResponse) {
                m_results = (RemotePojoInvocationCommandResponse) response;
            } else {
                m_results = new RemotePojoInvocationCommandResponse(response);
            }

            this.notifyAll();
        }
View Full Code Here

     * @throws InterruptedException if the current thread waiting for the results is interrupted
     * @throws ExecutionException   if the remote invocation threw an exception.
     * @throws TimeoutException     if the given amount of time has expired before the results have been received
     */
    public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        RemotePojoInvocationCommandResponse result;
        long wait_ms = unit.toMillis(timeout);

        synchronized (this) {
            if (m_results == null) {
                this.wait(wait_ms);
            }

            result = m_results;
        }

        if (result == null) {
            throw new TimeoutException();
        } else if (!result.isSuccessful()) {
            ExecutionException exc_to_throw;
            Throwable result_exc = result.getException();

            if ((result_exc instanceof InvocationTargetException) && (result_exc.getCause() != null)) {
                exc_to_throw = new ExecutionException(result_exc.getCause());
            } else {
                exc_to_throw = new ExecutionException(result_exc);
            }

            throw exc_to_throw;
        }

        // the command response results object is the object returned by the remote method
        return result.getResults();
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.communications.command.impl.remotepojo.RemotePojoInvocationCommandResponse

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.