Search in sources :

Example 1 with JobResponse

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;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JobServiceStub(com.alibaba.pegasus.service.protocol.JobServiceGrpc.JobServiceStub) StreamIterator(com.alibaba.pegasus.common.StreamIterator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobResponse(com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse)

Example 2 with JobResponse

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();
}
Also used : JobRequest(com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest) ArrayList(java.util.ArrayList) JobBuilder(com.alibaba.pegasus.builder.JobBuilder) JobResponse(com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse) IOException(java.io.IOException) JobConfig(com.alibaba.pegasus.service.protocol.PegasusClient.JobConfig) IOException(java.io.IOException)

Aggregations

JobResponse (com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse)2 JobBuilder (com.alibaba.pegasus.builder.JobBuilder)1 StreamIterator (com.alibaba.pegasus.common.StreamIterator)1 JobServiceStub (com.alibaba.pegasus.service.protocol.JobServiceGrpc.JobServiceStub)1 JobConfig (com.alibaba.pegasus.service.protocol.PegasusClient.JobConfig)1 JobRequest (com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1