Search in sources :

Example 1 with StreamRemoteCall

use of sun.rmi.transport.StreamRemoteCall in project jdk8u_jdk by JetBrains.

the class UnicastRef method invoke.

/**
     * Invoke a method. This form of delegating method invocation
     * to the reference allows the reference to take care of
     * setting up the connection to the remote host, marshalling
     * some representation for the method and parameters, then
     * communicating the method invocation to the remote host.
     * This method either returns the result of a method invocation
     * on the remote object which resides on the remote host or
     * throws a RemoteException if the call failed or an
     * application-level exception if the remote invocation throws
     * an exception.
     *
     * @param obj the proxy for the remote object
     * @param method the method to be invoked
     * @param params the parameter list
     * @param opnum  a hash that may be used to represent the method
     * @since 1.2
     */
public Object invoke(Remote obj, Method method, Object[] params, long opnum) throws Exception {
    if (clientRefLog.isLoggable(Log.VERBOSE)) {
        clientRefLog.log(Log.VERBOSE, "method: " + method);
    }
    if (clientCallLog.isLoggable(Log.VERBOSE)) {
        logClientCall(obj, method);
    }
    Connection conn = ref.getChannel().newConnection();
    RemoteCall call = null;
    boolean reuse = true;
    /* If the call connection is "reused" early, remember not to
         * reuse again.
         */
    boolean alreadyFreed = false;
    try {
        if (clientRefLog.isLoggable(Log.VERBOSE)) {
            clientRefLog.log(Log.VERBOSE, "opnum = " + opnum);
        }
        // create call context
        call = new StreamRemoteCall(conn, ref.getObjID(), -1, opnum);
        // marshal parameters
        try {
            ObjectOutput out = call.getOutputStream();
            marshalCustomCallData(out);
            Class<?>[] types = method.getParameterTypes();
            for (int i = 0; i < types.length; i++) {
                marshalValue(types[i], params[i], out);
            }
        } catch (IOException e) {
            clientRefLog.log(Log.BRIEF, "IOException marshalling arguments: ", e);
            throw new MarshalException("error marshalling arguments", e);
        }
        // unmarshal return
        call.executeCall();
        try {
            Class<?> rtype = method.getReturnType();
            if (rtype == void.class)
                return null;
            ObjectInput in = call.getInputStream();
            /* StreamRemoteCall.done() does not actually make use
                 * of conn, therefore it is safe to reuse this
                 * connection before the dirty call is sent for
                 * registered refs.
                 */
            Object returnValue = unmarshalValue(rtype, in);
            /* we are freeing the connection now, do not free
                 * again or reuse.
                 */
            alreadyFreed = true;
            /* if we got to this point, reuse must have been true. */
            clientRefLog.log(Log.BRIEF, "free connection (reuse = true)");
            /* Free the call's connection early. */
            ref.getChannel().free(conn, true);
            return returnValue;
        } catch (IOException e) {
            clientRefLog.log(Log.BRIEF, "IOException unmarshalling return: ", e);
            throw new UnmarshalException("error unmarshalling return", e);
        } catch (ClassNotFoundException e) {
            clientRefLog.log(Log.BRIEF, "ClassNotFoundException unmarshalling return: ", e);
            throw new UnmarshalException("error unmarshalling return", e);
        } finally {
            try {
                call.done();
            } catch (IOException e) {
                /* WARNING: If the conn has been reused early,
                     * then it is too late to recover from thrown
                     * IOExceptions caught here. This code is relying
                     * on StreamRemoteCall.done() not actually
                     * throwing IOExceptions.
                     */
                reuse = false;
            }
        }
    } catch (RuntimeException e) {
        /*
             * Need to distinguish between client (generated by the
             * invoke method itself) and server RuntimeExceptions.
             * Client side RuntimeExceptions are likely to have
             * corrupted the call connection and those from the server
             * are not likely to have done so.  If the exception came
             * from the server the call connection should be reused.
             */
        if ((call == null) || (((StreamRemoteCall) call).getServerException() != e)) {
            reuse = false;
        }
        throw e;
    } catch (RemoteException e) {
        /*
             * Some failure during call; assume connection cannot
             * be reused.  Must assume failure even if ServerException
             * or ServerError occurs since these failures can happen
             * during parameter deserialization which would leave
             * the connection in a corrupted state.
             */
        reuse = false;
        throw e;
    } catch (Error e) {
        /* If errors occurred, the connection is most likely not
             *  reusable.
             */
        reuse = false;
        throw e;
    } finally {
        /* alreadyFreed ensures that we do not log a reuse that
             * may have already happened.
             */
        if (!alreadyFreed) {
            if (clientRefLog.isLoggable(Log.BRIEF)) {
                clientRefLog.log(Log.BRIEF, "free connection (reuse = " + reuse + ")");
            }
            ref.getChannel().free(conn, reuse);
        }
    }
}
Also used : MarshalException(java.rmi.MarshalException) ObjectOutput(java.io.ObjectOutput) Connection(sun.rmi.transport.Connection) IOException(java.io.IOException) StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) UnmarshalException(java.rmi.UnmarshalException) RemoteObject(java.rmi.server.RemoteObject) ObjectInput(java.io.ObjectInput) RemoteException(java.rmi.RemoteException) StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) RemoteCall(java.rmi.server.RemoteCall)

Example 2 with StreamRemoteCall

use of sun.rmi.transport.StreamRemoteCall in project jdk8u_jdk by JetBrains.

the class UnicastRef method free.

/**
     * Private method to free a connection.
     */
private void free(RemoteCall call, boolean reuse) throws RemoteException {
    Connection conn = ((StreamRemoteCall) call).getConnection();
    ref.getChannel().free(conn, reuse);
}
Also used : StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) Connection(sun.rmi.transport.Connection)

Example 3 with StreamRemoteCall

use of sun.rmi.transport.StreamRemoteCall in project jdk8u_jdk by JetBrains.

the class UnicastRef method newCall.

/**
     * Create an appropriate call object for a new call on this object.
     * Passing operation array and index, allows the stubs generator to
     * assign the operation indexes and interpret them. The RemoteRef
     * may need the operation to encode in for the call.
     */
public RemoteCall newCall(RemoteObject obj, Operation[] ops, int opnum, long hash) throws RemoteException {
    clientRefLog.log(Log.BRIEF, "get connection");
    Connection conn = ref.getChannel().newConnection();
    try {
        clientRefLog.log(Log.VERBOSE, "create call context");
        /* log information about the outgoing call */
        if (clientCallLog.isLoggable(Log.VERBOSE)) {
            logClientCall(obj, ops[opnum]);
        }
        RemoteCall call = new StreamRemoteCall(conn, ref.getObjID(), opnum, hash);
        try {
            marshalCustomCallData(call.getOutputStream());
        } catch (IOException e) {
            throw new MarshalException("error marshaling " + "custom call data");
        }
        return call;
    } catch (RemoteException e) {
        ref.getChannel().free(conn, false);
        throw e;
    }
}
Also used : MarshalException(java.rmi.MarshalException) StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) Connection(sun.rmi.transport.Connection) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) RemoteCall(java.rmi.server.RemoteCall)

Example 4 with StreamRemoteCall

use of sun.rmi.transport.StreamRemoteCall in project jdk8u_jdk by JetBrains.

the class TCPTransport method handleMessages.

/**
     * handleMessages decodes transport operations and handles messages
     * appropriately.  If an exception occurs during message handling,
     * the socket is closed.
     */
void handleMessages(Connection conn, boolean persistent) {
    int port = getEndpoint().getPort();
    try {
        DataInputStream in = new DataInputStream(conn.getInputStream());
        do {
            // transport op
            int op = in.read();
            if (op == -1) {
                if (tcpLog.isLoggable(Log.BRIEF)) {
                    tcpLog.log(Log.BRIEF, "(port " + port + ") connection closed");
                }
                break;
            }
            if (tcpLog.isLoggable(Log.BRIEF)) {
                tcpLog.log(Log.BRIEF, "(port " + port + ") op = " + op);
            }
            switch(op) {
                case TransportConstants.Call:
                    // service incoming RMI call
                    RemoteCall call = new StreamRemoteCall(conn);
                    if (serviceCall(call) == false)
                        return;
                    break;
                case TransportConstants.Ping:
                    // send ack for ping
                    DataOutputStream out = new DataOutputStream(conn.getOutputStream());
                    out.writeByte(TransportConstants.PingAck);
                    conn.releaseOutputStream();
                    break;
                case TransportConstants.DGCAck:
                    DGCAckHandler.received(UID.read(in));
                    break;
                default:
                    throw new IOException("unknown transport op " + op);
            }
        } while (persistent);
    } catch (IOException e) {
        // exception during processing causes connection to close (below)
        if (tcpLog.isLoggable(Log.BRIEF)) {
            tcpLog.log(Log.BRIEF, "(port " + port + ") exception: ", e);
        }
    } finally {
        try {
            conn.close();
        } catch (IOException ex) {
        // eat exception
        }
    }
}
Also used : StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) DataOutputStream(java.io.DataOutputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) Endpoint(sun.rmi.transport.Endpoint) StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) RemoteCall(java.rmi.server.RemoteCall)

Aggregations

StreamRemoteCall (sun.rmi.transport.StreamRemoteCall)4 IOException (java.io.IOException)3 RemoteCall (java.rmi.server.RemoteCall)3 Connection (sun.rmi.transport.Connection)3 MarshalException (java.rmi.MarshalException)2 RemoteException (java.rmi.RemoteException)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 UnmarshalException (java.rmi.UnmarshalException)1 RemoteObject (java.rmi.server.RemoteObject)1 Endpoint (sun.rmi.transport.Endpoint)1