Search in sources :

Example 1 with PluginSerializable

use of com.cinchapi.concourse.server.plugin.io.PluginSerializable in project concourse by cinchapi.

the class RemoteInvocationThread method run.

@Override
public final void run() {
    int argCount = request.args.size() + (useLocalThriftArgs ? 3 : 0);
    Object[] jargs = new Object[argCount];
    int i = 0;
    for (; i < request.args.size(); ++i) {
        Object jarg = request.args.get(i).getJavaObject();
        if (jarg instanceof ByteBuffer) {
            // If any of the arguments are BINARY, we assume that the caller
            // manually serialized a PluginSerializable object, so we must
            // try to convert to the actual object so that the method is
            // actually called.
            jarg = serializer().deserialize((ByteBuffer) jarg);
        }
        jargs[i] = jarg;
    }
    if (useLocalThriftArgs) {
        jargs[i++] = request.creds;
        jargs[i++] = request.transaction;
        jargs[i++] = request.environment;
    }
    RemoteMethodResponse response = null;
    try {
        if (request.method.equals("getServerVersion")) {
            // getServerVersion, for some reason doesn't take any
            // arguments...not even the standard meta arguments that all
            // other methods take
            jargs = new Object[0];
        }
        Object result0 = Reflection.callIf((method) -> Modifier.isPublic(method.getModifiers()) && !Reflection.isDeclaredAnnotationPresentInHierarchy(method, PluginRestricted.class), invokable, request.method, jargs);
        if (result0 instanceof PluginSerializable) {
            // CON-509: PluginSerializable objects must be wrapped as BINARY
            // within a ComplexTObject
            result0 = serializer().serialize(result0);
        }
        ComplexTObject result = ComplexTObject.fromJavaObject(result0);
        response = new RemoteMethodResponse(request.creds, result);
    } catch (Exception e) {
        e = (Exception) Throwables.getRootCause(e);
        response = new RemoteMethodResponse(request.creds, e);
        logger.error("Remote invocation error: {}", e, e);
    }
    ByteBuffer buffer = serializer().serialize(response);
    outgoing.write(buffer);
}
Also used : ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) PluginSerializable(com.cinchapi.concourse.server.plugin.io.PluginSerializable) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) ByteBuffer(java.nio.ByteBuffer)

Aggregations

PluginSerializable (com.cinchapi.concourse.server.plugin.io.PluginSerializable)1 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)1 ByteBuffer (java.nio.ByteBuffer)1