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

Examples of org.rhq.enterprise.communications.command.impl.generic.GenericCommandResponse


    public CommandResponse execute(Command command, InputStream in, OutputStream out) {
        RemoteInputStream stream = (RemoteInputStream) command.getParameterValue(INPUT_STREAM_PARAM);

        prepareRemoteInputStream(stream);

        GenericCommandResponse response;

        if (command.hasParameterValue(RETURN_COUNT_ONLY_PARAM)) {
            try {
                long stream_length = count(stream);
                response = new GenericCommandResponse(command, true, new Long(stream_length), null);
            } catch (Exception e) {
                response = new GenericCommandResponse(command, false, null, e);
            }
        } else {
            byte[] stream_data = StreamUtil.slurp(stream);
            response = new GenericCommandResponse(command, true, new String(stream_data), null);
        }

        return response;
    }
View Full Code Here


        CommandResponse retResponse;

        try {
            retResponse = typeExecutor.getExecutor().execute(command, null, null);
        } catch (Throwable t) {
            retResponse = new GenericCommandResponse(command, false, null, t);
        }

        return retResponse;
    }
View Full Code Here

            throw m_sendException;
        }

        m_sentSuccessful.incrementAndGet();

        return new GenericCommandResponse(command, true, null, null);
    }
View Full Code Here

                String agent = m_sender.getRemoteCommunicator().toString();
                LOG.info(CommI18NResourceKeys.AGENT_PING_FAILED, agent);
            } else {
                LOG.error(t, CommI18NResourceKeys.SEND_FAILED, command, ThrowableUtil.getAllMessages(t));
            }
            response = new GenericCommandResponse(command, false, null, t);

            boolean retry = shouldCommandBeRetried(command, t);

            if (retry) {
                notify_callback = false; // since we are going to retry this command, do not notify the callback
View Full Code Here

    }

    // ServerInvocationHandler methods
    public Object invoke(InvocationRequest invocation) {
        if (invocation.getParameter() instanceof IdentifyCommand) {
            return new GenericCommandResponse(null, true, "foo", null);
        }

        return "foo";
    }
View Full Code Here

            // I purposefully did not throw an exception here because the command actually did make a successful
            // round trip, so I think we would want to have a CommandResponse sent back, not throw an exception.
            // However, we got an exception when casting the remote endpoint's reply (the most likely cause here
            // is a ClassCastException - the endpoint didn't reply with the expected CommandResponse).
            LOG.error(CommI18NResourceKeys.COMM_CCE, ret_response);
            return new GenericCommandResponse(command, false, ret_response, e);
        }
    }
View Full Code Here

                            LOG.debug(CommI18NResourceKeys.INITIALIZE_CALLBACK_DONE, m_needToCallInitializeCallback);
                        } catch (Throwable t) {
                            m_needToCallInitializeCallback = true; // callback failed, we'll want to call it again
                            LOG.error(t, CommI18NResourceKeys.INITIALIZE_CALLBACK_FAILED, ThrowableUtil
                                .getAllMessages(t));
                            return new GenericCommandResponse(command, false, null, t);
                        }
                    }
                } finally {
                    writeLock.unlock();
                }
            } else {
                Throwable t = new Throwable("Initialize callback lock could not be acquired");
                LOG.error(CommI18NResourceKeys.INITIALIZE_CALLBACK_FAILED, t.getMessage());
                return new GenericCommandResponse(command, false, null, t);
            }
        }
        return null;
    }
View Full Code Here

                            m_metrics.numberFailedCommands++;
                        }

                        String err = LOG
                            .getMsgString(CommI18NResourceKeys.COMMAND_PROCESSOR_FAILED_AUTHENTICATION, cmd);
                        ret_response = new GenericCommandResponse(null, false, null, new AuthenticationException(err));

                        notifyListenersOfProcessedCommand(cmd, ret_response);

                        return ret_response;
                    }
                }

                // get the command's type
                CommandType cmdType = cmd.getCommandType();

                // ask the directory what command service supports the command we want to execute
                CommandServiceDirectoryEntry entry = null;
                ObjectName cmdServiceName = null;

                entry = getCommandServiceDirectory().getCommandTypeProvider(subsystem, cmdType);

                if (entry != null) {
                    cmdServiceName = entry.getCommandServiceName();
                }

                if (cmdServiceName != null) {
                    // now delegate the execution of the command to the command service
                    CommandServiceMBean executor;

                    executor = (CommandServiceMBean) MBeanServerInvocationHandler.newProxyInstance(m_mBeanServer,
                        cmdServiceName, CommandServiceMBean.class, false);

                    LOG.debug(CommI18NResourceKeys.COMMAND_PROCESSOR_EXECUTING, cmd);
                    long start = System.currentTimeMillis();

                    ret_response = executor.execute(cmd, in, null);

                    elapsed = System.currentTimeMillis() - start;
                    LOG.debug(CommI18NResourceKeys.COMMAND_PROCESSOR_EXECUTED, ret_response);
                } else {
                    throw new InstanceNotFoundException(LOG.getMsgString(
                        CommI18NResourceKeys.COMMAND_PROCESSOR_UNSUPPORTED_COMMAND_TYPE, subsystem, cmdType));
                }
            } else {
                LOG.warn(CommI18NResourceKeys.COMMAND_PROCESSOR_MISSING_COMMAND);
                ret_response = new GenericCommandResponse(null, false, null, new Exception(LOG
                    .getMsgString(CommI18NResourceKeys.COMMAND_PROCESSOR_MISSING_COMMAND)));
            }
        } catch (Throwable t) {
            ret_response = new GenericCommandResponse(cmd, false, null, t);
        } finally {
            IncomingCommandTrace.finish(cmd, ret_response);

            // as per JBoss/Remoting docs, you must ensure you close the input stream
            if (in != null) {
                try {
                    in.close();
                } catch (Throwable t) {
                }
            }
        }

        // finish our processing
        try {
            if (ret_response == null) {
                ret_response = new GenericCommandResponse(cmd, false, null, new IllegalStateException(
                    "results are null"));
            }

            updateMetrics(cmd, ret_response, elapsed);
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.communications.command.impl.generic.GenericCommandResponse

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.