Search in sources :

Example 1 with GridServiceProxy

use of org.apache.ignite.internal.processors.service.GridServiceProxy in project ignite by apache.

the class ClientServiceInvokeRequest method process.

/**
 * {@inheritDoc}
 */
@Override
public ClientResponse process(ClientConnectionContext ctx) {
    if (F.isEmpty(name))
        throw new IgniteException("Service name can't be empty");
    if (F.isEmpty(methodName))
        throw new IgniteException("Method name can't be empty");
    ServiceDescriptor desc = findServiceDescriptor(ctx, name);
    Class<?> svcCls = desc.serviceClass();
    ClusterGroupAdapter grp = ctx.kernalContext().cluster().get();
    grp = (ClusterGroupAdapter) (nodeIds.isEmpty() ? grp.forServers() : grp.forNodeIds(nodeIds));
    IgniteServices services = grp.services();
    try {
        Object res;
        if (PlatformService.class.isAssignableFrom(svcCls)) {
            // Never deserialize platform service arguments and result: may contain platform-only types.
            PlatformService proxy = ((IgniteServicesImpl) services).serviceProxy(name, PlatformService.class, false, timeout, true);
            res = proxy.invokeMethod(methodName, keepBinary(), false, args, callAttrs);
        } else {
            // Deserialize Java service arguments when not in keepBinary mode.
            if (!keepBinary() && args.length > 0) {
                for (int i = 0; i < args.length; i++) {
                    if (paramTypeIds != null)
                        // Skip parameter typeId, we already read it in constructor.
                        reader.readInt();
                    args[i] = reader.readObject();
                }
            }
            GridServiceProxy<?> proxy = new GridServiceProxy<>(grp, name, Service.class, false, timeout, ctx.kernalContext(), null, true);
            Method method = resolveMethod(ctx, svcCls);
            if (!BinaryArray.useBinaryArrays())
                PlatformServices.convertArrayArgs(args, method);
            res = proxy.invokeMethod(method, args, callAttrs);
        }
        return new ClientObjectResponse(requestId(), res);
    } catch (PlatformNativeException e) {
        ctx.kernalContext().log(getClass()).error("Failed to invoke platform service", e);
        throw new IgniteException("Failed to invoke platform service, see server logs for details");
    } catch (Throwable e) {
        throw new IgniteException(e);
    }
}
Also used : GridServiceProxy(org.apache.ignite.internal.processors.service.GridServiceProxy) IgniteServices(org.apache.ignite.IgniteServices) ClientObjectResponse(org.apache.ignite.internal.processors.platform.client.ClientObjectResponse) Method(java.lang.reflect.Method) PlatformService(org.apache.ignite.internal.processors.platform.services.PlatformService) ServiceDescriptor(org.apache.ignite.services.ServiceDescriptor) IgniteException(org.apache.ignite.IgniteException) PlatformNativeException(org.apache.ignite.internal.processors.platform.PlatformNativeException) IgniteServicesImpl(org.apache.ignite.internal.IgniteServicesImpl) ClusterGroupAdapter(org.apache.ignite.internal.cluster.ClusterGroupAdapter)

Aggregations

Method (java.lang.reflect.Method)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteServices (org.apache.ignite.IgniteServices)1 IgniteServicesImpl (org.apache.ignite.internal.IgniteServicesImpl)1 ClusterGroupAdapter (org.apache.ignite.internal.cluster.ClusterGroupAdapter)1 PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)1 ClientObjectResponse (org.apache.ignite.internal.processors.platform.client.ClientObjectResponse)1 PlatformService (org.apache.ignite.internal.processors.platform.services.PlatformService)1 GridServiceProxy (org.apache.ignite.internal.processors.service.GridServiceProxy)1 ServiceDescriptor (org.apache.ignite.services.ServiceDescriptor)1