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

Examples of org.rhq.enterprise.communications.command.impl.stream.RemoteInputStreamCommandResponse


        String method_name = invocation.getMethodName();
        Object[] params = invocation.getParameters();
        String[] signature = invocation.getSignature();
        Class<?>[] class_signature = new Class[signature.length];

        RemoteInputStreamCommandResponse response;

        try {
            // get the stream that the command wants to access
            Long stream_id = remote_command.getStreamId();
            InputStream the_stream;

            synchronized (m_lock) {
                the_stream = m_remotedInputStreams.get(stream_id);

                if (the_stream == null) {
                    throw new IllegalArgumentException(LOG.getMsgString(CommI18NResourceKeys.INVALID_STREAM_ID,
                        stream_id, remote_command));
                }

                setLastAccess(stream_id, System.currentTimeMillis());
            }

            LOG.debug(CommI18NResourceKeys.INVOKING_STREAM_FROM_REMOTE_CLIENT, stream_id, method_name);

            // use reflection to make the call
            for (int x = 0; x < signature.length; x++) {
                class_signature[x] = ClassUtil.getClassFromTypeName(signature[x]);
            }

            Method method = InputStream.class.getMethod(method_name, class_signature);
            Object results = method.invoke(the_stream, params);

            response = new RemoteInputStreamCommandResponse(remote_command, results);

            // if the client has asked to close the stream, then we will ask that this service be deregistered as soon as possible
            // one the stream is closed, a client should not request anything else from our service (obviously, there is nothing else
            // this service can provide since the stream is now useless)
            if ("close".equals(method_name)) {
                setLastAccess(stream_id, 0L);
            }
        } catch (Exception e) {
            LOG.warn(e, CommI18NResourceKeys.FAILED_TO_INVOKE_STREAM_METHOD, method_name, remote_command);
            response = new RemoteInputStreamCommandResponse(remote_command, e);
        }

        return response;
    }
View Full Code Here


        if (m_sender == null) {
            throw new RemoteIOException(LOG.getMsgString(CommI18NResourceKeys.REMOTE_INPUT_STREAM_HAS_NO_SENDER,
                m_streamId, m_serverEndpoint));
        }

        RemoteInputStreamCommandResponse response;
        RemoteInputStreamCommand cmd = new RemoteInputStreamCommand();

        cmd.setNameBasedInvocation(new NameBasedInvocation(method, args));
        cmd.setStreamId(m_streamId);

        try {
            response = new RemoteInputStreamCommandResponse(m_sender.sendSynch(cmd));
        } catch (Exception e) {
            throw new RemoteIOException(e);
        }

        if (!response.isSuccessful()) {
            throw new RemoteIOException(response.getException());
        }

        // let's mimic pass by reference by copying the bytes read into the byte[] array parameter.
        // note that the only way that read_bytes could be non-null was if our command had
        // a byte[] as its first parameter.  Therefore, read_bytes!=null directly infers that args[0] is a byte[]
        // and they will have identical sizes.
        byte[] read_bytes = response.getBytesReadFromStream();
        if (read_bytes != null) {
            // two sanity checks here:
            // first, args[0] should be a byte[], if not, it is a bug
            // second, the arrays passed in the command and got back in the response should be the same length, its a bug otherwise
            assert (args.length > 0) && (args[0] instanceof byte[]);
            assert read_bytes.length == ((byte[]) args[0]).length;

            System.arraycopy(read_bytes, 0, args[0], 0, read_bytes.length);
        }

        return response.getResults();
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.communications.command.impl.stream.RemoteInputStreamCommandResponse

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.