Search in sources :

Example 1 with ServiceInvocationStruct

use of org.teiid.net.socket.ServiceInvocationStruct in project teiid by teiid.

the class TestServiceInvocationStruct method testSerialize.

public void testSerialize() throws Exception {
    ServiceInvocationStruct struct = new ServiceInvocationStruct(new Object[] { new Integer(1), "hello" }, "doSomething", TestServiceInvocationStruct.class);
    Object serialized = UnitTestUtil.helpSerialize(struct);
    assertNotNull(serialized);
    assertTrue(serialized instanceof ServiceInvocationStruct);
    ServiceInvocationStruct copy = (ServiceInvocationStruct) serialized;
    assertTrue(Arrays.equals(struct.args, copy.args));
    assertEquals(struct.methodName, copy.methodName);
    assertEquals(struct.targetClass, copy.targetClass);
}
Also used : ServiceInvocationStruct(org.teiid.net.socket.ServiceInvocationStruct)

Example 2 with ServiceInvocationStruct

use of org.teiid.net.socket.ServiceInvocationStruct in project teiid by teiid.

the class PgBackendProtocol method write.

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    this.ctx = ctx;
    this.message = msg;
    ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct) msg;
    try {
        Method m = this.clientProxy.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
        try {
            m.invoke(this, serviceStruct.args);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    } catch (Throwable e) {
        terminate(e);
    }
}
Also used : Method(java.lang.reflect.Method) ServiceInvocationStruct(org.teiid.net.socket.ServiceInvocationStruct) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ServiceInvocationStruct

use of org.teiid.net.socket.ServiceInvocationStruct in project teiid by teiid.

the class ServerWorkItem method run.

/**
 * main entry point for remote method calls.
 */
public void run() {
    Message result = null;
    String loggingContext = null;
    final boolean encrypt = !(message.getContents() instanceof ServiceInvocationStruct);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        try {
            Thread.currentThread().setContextClassLoader(this.csr.getCallerClassloader());
        } catch (Throwable t) {
        // ignore
        }
        message.setContents(this.socketClientInstance.getCryptor().unsealObject(message.getContents()));
        if (!(message.getContents() instanceof ServiceInvocationStruct)) {
            // $NON-NLS-1$
            throw new AssertionError("unknown message contents");
        }
        final ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct) message.getContents();
        final ClientService clientService = this.csr.getClientService(serviceStruct.targetClass.getName());
        loggingContext = clientService.getLoggingContext();
        Method m = clientService.getReflectionHelper().findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
        Object methodResult;
        try {
            methodResult = m.invoke(clientService.getInstance(), serviceStruct.args);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
        if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
            ResultsFuture<Object> future = (ResultsFuture<Object>) methodResult;
            future.addCompletionListener(new ResultsFuture.CompletionListener<Object>() {

                public void onCompletion(ResultsFuture<Object> completedFuture) {
                    Message asynchResult = new Message();
                    try {
                        asynchResult.setContents(completedFuture.get());
                    } catch (InterruptedException e) {
                        asynchResult.setContents(processException(e, clientService.getLoggingContext()));
                    } catch (ExecutionException e) {
                        asynchResult.setContents(processException(e.getCause(), clientService.getLoggingContext()));
                    }
                    sendResult(asynchResult, encrypt);
                }
            });
        } else {
            // synch call
            Message resultHolder = new Message();
            resultHolder.setContents(methodResult);
            result = resultHolder;
        }
    } catch (Throwable t) {
        Message holder = new Message();
        holder.setContents(processException(t, loggingContext));
        result = holder;
    } finally {
        Thread.currentThread().setContextClassLoader(classLoader);
    }
    if (result != null) {
        sendResult(result, encrypt);
    }
}
Also used : Message(org.teiid.net.socket.Message) ClientService(org.teiid.transport.ClientServiceRegistryImpl.ClientService) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ResultsFuture(org.teiid.client.util.ResultsFuture) ExecutionException(java.util.concurrent.ExecutionException) ServiceInvocationStruct(org.teiid.net.socket.ServiceInvocationStruct)

Aggregations

ServiceInvocationStruct (org.teiid.net.socket.ServiceInvocationStruct)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ExecutionException (java.util.concurrent.ExecutionException)1 ResultsFuture (org.teiid.client.util.ResultsFuture)1 Message (org.teiid.net.socket.Message)1 ClientService (org.teiid.transport.ClientServiceRegistryImpl.ClientService)1