<commit_before>//
// $Id: InvocationDirector.java,v 1.11 2001/10/03 03:42:31 mdb Exp $

package com.threerings.cocktail.cher.client;

import java.lang.reflect.Method;
import java.util.HashMap;

import com.samskivert.util.HashIntMap;
import com.samskivert.util.StringUtil;

import com.threerings.cocktail.cher.Log;
import com.threerings.cocktail.cher.data.*;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.cher.util.ClassUtil;

/**
 * The invocation services provide client to server invocations (service
 * requests) and server to client invocations (responses and
 * notifications). Via this mechanism, the client can make requests of the
 * server, be notified of its response and the server can asynchronously
 * invoke code on the client.
 *
 * <p> Invocations are like remote procedure calls in that they are named
 * and take arguments. They are simple in that the arguments can only be
 * of a small set of supported types (the set of distributed object field
 * types) and there is no special facility provided for referencing
 * non-local objects (it is assumed that the distributed object facility
 * will already be in use for any objects that should be shared).
 *
 * <p> The client invocation director delivers invocation requests to the
 * server invocation manager and maps the responses back to the proper
 * response target objects when they arrive. It also maintains the mapping
 * of invocation receivers that can receive asynchronous invocation
 * notifications at any time from the server.
 */
public class InvocationDirector
    implements Subscriber
{
    /**
     * Initializes the invocation director with the specified invocation
     * manager oid. It will obtain its distributed object manager and
     * client object references from the supplied client instance. The
     * invocation manager oid is the oid of the object on the server to
     * which to deliver invocation requests.
     */
    public void init (Client client, int imoid)
    {
        _client = client;
        _omgr = client.getDObjectManager();
        _imoid = imoid;

        // add ourselves as a subscriber to the client object
        _omgr.subscribeToObject(client.getClientOid(), this);
    }

    /**
     * Sends an invocation request to the server. If a response target is
     * supplied, the response will be delivered to that object by calling
     * a member function on it whose name is defined in the response
     * generated by the invocation implementation. In general, this is a
     * derivative of the invocation procedure name. For example, if the
     * caller invoked a procedure named <code>Switch</code>, the response
     * may be delivered via a call to the <code>handleSwitchSuccess</code>
     * method on the response target object. The signature of that method
     * would be defined by the arguments provided in the response message
     * with the addition of a first argument which is the invocation
     * identifier for this particular request (that is also returned by
     * this function).
     *
     * @param module the name of the invocation module to use.
     * @param procedure the name of the procedure within that module.
     * @param args the arguments of the invocation.
     * @param rsptarget the object that will receive the response, or null
     * if no response is desired.
     *
     * @return a unique identifier associated with this invocation
     * request. This identifier will be passed as the first argument to
     * the response function.
     */
    public int invoke (String module, String procedure, Object[] args,
                       Object rsptarget)
    {
        int invid = nextInvocationId();

        // we need an args array for a message that can contain the
        // invocation names, an invocation id and the invocation arguments
        Object[] iargs = new Object[args.length+3];
        iargs[0] = module;
        iargs[1] = procedure;
        iargs[2] = new Integer(invid);
        System.arraycopy(args, 0, iargs, 3, args.length);

        // create a message event on the invocation manager object
        MessageEvent event = new MessageEvent(
            _imoid, InvocationObject.REQUEST_NAME, iargs);

        // if we have a response target, register that for later receipt
        // of the response
        if (rsptarget != null) {
            _targets.put(invid, rsptarget);
        }

        // and finally ship off the invocation message
        _omgr.postEvent(event);

        return invid;
    }
<commit_msg>Deal with a null arguments array being provided to invoke().<commit_after>//
// $Id: InvocationDirector.java,v 1.12 2001/10/04 20:02:13 mdb Exp $

package com.threerings.cocktail.cher.client;

import java.lang.reflect.Method;
import java.util.HashMap;

import com.samskivert.util.HashIntMap;
import com.samskivert.util.StringUtil;

import com.threerings.cocktail.cher.Log;
import com.threerings.cocktail.cher.data.*;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.cher.util.ClassUtil;

/**
 * The invocation services provide client to server invocations (service
 * requests) and server to client invocations (responses and
 * notifications). Via this mechanism, the client can make requests of the
 * server, be notified of its response and the server can asynchronously
 * invoke code on the client.
 *
 * <p> Invocations are like remote procedure calls in that they are named
 * and take arguments. They are simple in that the arguments can only be
 * of a small set of supported types (the set of distributed object field
 * types) and there is no special facility provided for referencing
 * non-local objects (it is assumed that the distributed object facility
 * will already be in use for any objects that should be shared).
 *
 * <p> The client invocation director delivers invocation requests to the
 * server invocation manager and maps the responses back to the proper
 * response target objects when they arrive. It also maintains the mapping
 * of invocation receivers that can receive asynchronous invocation
 * notifications at any time from the server.
 */
public class InvocationDirector
    implements Subscriber
{
    /**
     * Initializes the invocation director with the specified invocation
     * manager oid. It will obtain its distributed object manager and
     * client object references from the supplied client instance. The
     * invocation manager oid is the oid of the object on the server to
     * which to deliver invocation requests.
     */
    public void init (Client client, int imoid)
    {
        _client = client;
        _omgr = client.getDObjectManager();
        _imoid = imoid;

        // add ourselves as a subscriber to the client object
        _omgr.subscribeToObject(client.getClientOid(), this);
    }

    /**
     * Sends an invocation request to the server. If a response target is
     * supplied, the response will be delivered to that object by calling
     * a member function on it whose name is defined in the response
     * generated by the invocation implementation. In general, this is a
     * derivative of the invocation procedure name. For example, if the
     * caller invoked a procedure named <code>Switch</code>, the response
     * may be delivered via a call to the <code>handleSwitchSuccess</code>
     * method on the response target object. The signature of that method
     * would be defined by the arguments provided in the response message
     * with the addition of a first argument which is the invocation
     * identifier for this particular request (that is also returned by
     * this function).
     *
     * @param module the name of the invocation module to use.
     * @param procedure the name of the procedure within that module.
     * @param args the arguments of the invocation.
     * @param rsptarget the object that will receive the response, or null
     * if no response is desired.
     *
     * @return a unique identifier associated with this invocation
     * request. This identifier will be passed as the first argument to
     * the response function.
     */
    public int invoke (String module, String procedure, Object[] args,
                       Object rsptarget)
    {
        int invid = nextInvocationId();

        // if null arguments were supplied, assume zero arguments
        if (args == null) {
            args = new Object[0];
        }

        // we need an args array for a message that can contain the
        // invocation names, an invocation id and the invocation arguments
        Object[] iargs = new Object[args.length+3];
        iargs[0] = module;
        iargs[1] = procedure;
        iargs[2] = new Integer(invid);
        System.arraycopy(args, 0, iargs, 3, args.length);

        // create a message event on the invocation manager object
        MessageEvent event = new MessageEvent(
            _imoid, InvocationObject.REQUEST_NAME, iargs);

        // if we have a response target, register that for later receipt
        // of the response
        if (rsptarget != null) {
            _targets.put(invid, rsptarget);
        }

        // and finally ship off the invocation message
        _omgr.postEvent(event);

        return invid;
    }

{'fraction_non_alphanumeric': 0.06317378180250108, 'fraction_numerical': 0.005066839154808107, 'mean_word_length': 2.932598558711318, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2275579', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2270, 'n_words': 1101}