use of com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse in project GraphScope by alibaba.
the class RpcClient method submit.
public CloseableIterator<JobResponse> submit(JobRequest jobRequest) throws InterruptedException {
StreamIterator<JobResponse> responseIterator = new StreamIterator<>();
AtomicInteger counter = new AtomicInteger(this.channels.size());
AtomicBoolean finished = new AtomicBoolean(false);
for (RpcChannel rpcChannel : channels) {
JobServiceStub asyncStub = JobServiceGrpc.newStub(rpcChannel.getChannel());
// todo: make timeout configurable
asyncStub.withDeadlineAfter(600000, TimeUnit.MILLISECONDS).submit(jobRequest, new JobResponseObserver(responseIterator, finished, counter));
}
return responseIterator;
}
use of com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse in project GraphScope by alibaba.
the class ClientExample method main.
public static void main(String[] args) throws Exception {
RpcChannel rpcChannel0 = new RpcChannel("localhost", 1234);
RpcChannel rpcChannel1 = new RpcChannel("localhost", 1235);
List<RpcChannel> channels = new ArrayList<>();
channels.add(rpcChannel0);
channels.add(rpcChannel1);
RpcClient rpcClient = new RpcClient(channels);
logger.info("Will try to send request");
JobConfig confPb = JobConfig.newBuilder().setJobId(2).setJobName("ping_pong_example").setWorkers(2).setAll(PegasusClient.Empty.newBuilder().build()).build();
// for job build
JobBuilder jobBuilder = new JobBuilder(confPb);
// for nested task
JobBuilder start = new JobBuilder();
// construct job
jobBuilder.addSource(getSeed(0)).repeat(3, start.exchange(getRoute()).map(add(1)).flatMap(copy(8))).sink(getSink());
JobRequest req = jobBuilder.build();
CloseableIterator<JobResponse> iterator = rpcClient.submit(req);
// process response
try {
while (iterator.hasNext()) {
JobResponse response = iterator.next();
process(response);
}
} catch (Exception e) {
if (iterator != null) {
try {
iterator.close();
} catch (IOException ioe) {
// Ignore
}
}
error(Status.fromThrowable(e));
throw e;
}
finish();
rpcClient.shutdown();
}
Aggregations