Search in sources :

Example 1 with DRPCInvocationsClient

use of backtype.storm.drpc.DRPCInvocationsClient in project storm by nathanmarz.

the class ReturnResultsReducer method complete.

@Override
public void complete(ReturnResultsState state, TridentCollector collector) {
    // only one of the multireducers will receive the tuples
    if (state.returnInfo != null) {
        String result = JSONValue.toJSONString(state.results);
        Map retMap = (Map) JSONValue.parse(state.returnInfo);
        final String host = (String) retMap.get("host");
        final int port = Utils.getInt(retMap.get("port"));
        String id = (String) retMap.get("id");
        DistributedRPCInvocations.Iface client;
        if (local) {
            client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
        } else {
            List server = new ArrayList() {

                {
                    add(host);
                    add(port);
                }
            };
            if (!_clients.containsKey(server)) {
                _clients.put(server, new DRPCInvocationsClient(host, port));
            }
            client = _clients.get(server);
        }
        try {
            client.result(id, result);
        } catch (TException e) {
            collector.reportError(e);
        }
    }
}
Also used : DRPCInvocationsClient(backtype.storm.drpc.DRPCInvocationsClient) TException(org.apache.thrift7.TException) ArrayList(java.util.ArrayList) DistributedRPCInvocations(backtype.storm.generated.DistributedRPCInvocations) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with DRPCInvocationsClient

use of backtype.storm.drpc.DRPCInvocationsClient in project jstorm by alibaba.

the class ReturnResultsReducer method complete.

@Override
public void complete(ReturnResultsState state, TridentCollector collector) {
    // only one of the multireducers will receive the tuples
    if (state.returnInfo != null) {
        String result = JSONValue.toJSONString(state.results);
        Map retMap = (Map) JSONValue.parse(state.returnInfo);
        final String host = (String) retMap.get("host");
        final int port = Utils.getInt(retMap.get("port"));
        String id = (String) retMap.get("id");
        DistributedRPCInvocations.Iface client;
        if (local) {
            client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
        } else {
            List server = new ArrayList() {

                {
                    add(host);
                    add(port);
                }
            };
            if (!_clients.containsKey(server)) {
                try {
                    _clients.put(server, new DRPCInvocationsClient(conf, host, port));
                } catch (TTransportException ex) {
                    throw new RuntimeException(ex);
                }
            }
            client = _clients.get(server);
        }
        try {
            client.result(id, result);
        } catch (AuthorizationException aze) {
            collector.reportError(aze);
        } catch (TException e) {
            collector.reportError(e);
        }
    }
}
Also used : DRPCInvocationsClient(backtype.storm.drpc.DRPCInvocationsClient) TException(org.apache.thrift.TException) AuthorizationException(backtype.storm.generated.AuthorizationException) ArrayList(java.util.ArrayList) DistributedRPCInvocations(backtype.storm.generated.DistributedRPCInvocations) TTransportException(org.apache.thrift.transport.TTransportException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DRPCInvocationsClient (backtype.storm.drpc.DRPCInvocationsClient)2 DistributedRPCInvocations (backtype.storm.generated.DistributedRPCInvocations)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AuthorizationException (backtype.storm.generated.AuthorizationException)1 TException (org.apache.thrift.TException)1 TTransportException (org.apache.thrift.transport.TTransportException)1 TException (org.apache.thrift7.TException)1