Search in sources :

Example 1 with DRPCExecutionException

use of backtype.storm.generated.DRPCExecutionException in project jstorm by alibaba.

the class Drpc method execute.

@Override
public String execute(String function, String args) throws DRPCExecutionException, TException {
    LOG.info("Received DRPC request for " + function + " " + args + " at " + (System.currentTimeMillis()));
    int idinc = this.ctr.incrementAndGet();
    int maxvalue = 1000000000;
    int newid = idinc % maxvalue;
    if (idinc != newid) {
        this.ctr.compareAndSet(idinc, newid);
    }
    String strid = String.valueOf(newid);
    Semaphore sem = new Semaphore(0);
    DRPCRequest req = new DRPCRequest(args, strid);
    this.idtoStart.put(strid, TimeUtils.current_time_secs());
    this.idtoSem.put(strid, sem);
    this.idtoFunction.put(strid, function);
    this.idtoRequest.put(strid, req);
    ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(function);
    queue.add(req);
    LOG.info("Waiting for DRPC request for " + function + " " + args + " at " + (System.currentTimeMillis()));
    try {
        sem.acquire();
    } catch (InterruptedException e) {
        LOG.error("acquire fail ", e);
    }
    LOG.info("Acquired for DRPC request for " + function + " " + args + " at " + (System.currentTimeMillis()));
    Object result = this.idtoResult.get(strid);
    if (!this.idtoResult.containsKey(strid)) {
        // this request is timeout, set exception
        result = new DRPCExecutionException("Request timed out");
    }
    LOG.info("Returning for DRPC request for " + function + " " + args + " at " + (System.currentTimeMillis()));
    this.cleanup(strid);
    if (result instanceof DRPCExecutionException) {
        throw (DRPCExecutionException) result;
    }
    return String.valueOf(result);
}
Also used : DRPCRequest(backtype.storm.generated.DRPCRequest) DRPCExecutionException(backtype.storm.generated.DRPCExecutionException) Semaphore(java.util.concurrent.Semaphore)

Example 2 with DRPCExecutionException

use of backtype.storm.generated.DRPCExecutionException in project jstorm by alibaba.

the class Drpc method failRequest.

@Override
public void failRequest(String id) throws TException {
    Semaphore sem = this.idtoSem.get(id);
    LOG.info("failRequest result  for id " + id + " at " + (System.currentTimeMillis()));
    if (sem != null) {
        this.idtoResult.put(id, new DRPCExecutionException("Request failed"));
        sem.release();
    }
}
Also used : DRPCExecutionException(backtype.storm.generated.DRPCExecutionException) Semaphore(java.util.concurrent.Semaphore)

Aggregations

DRPCExecutionException (backtype.storm.generated.DRPCExecutionException)2 Semaphore (java.util.concurrent.Semaphore)2 DRPCRequest (backtype.storm.generated.DRPCRequest)1