Java Code Examples for com.google.protobuf.RpcController

The following examples show how to use com.google.protobuf.RpcController. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public ListCachePoolsResponseProto listCachePools(RpcController controller,
    ListCachePoolsRequestProto request) throws ServiceException {
  try {
    BatchedEntries<CachePoolEntry> entries =
      server.listCachePools(request.getPrevPoolName());
    ListCachePoolsResponseProto.Builder responseBuilder =
      ListCachePoolsResponseProto.newBuilder();
    responseBuilder.setHasMore(entries.hasMore());
    for (int i=0, n=entries.size(); i<n; i++) {
      responseBuilder.addEntries(PBHelper.convert(entries.get(i)));
    }
    return responseBuilder.build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 2
@Override
public GetEZForPathResponseProto getEZForPath(
    RpcController controller, GetEZForPathRequestProto req)
    throws ServiceException {
  try {
    GetEZForPathResponseProto.Builder builder =
        GetEZForPathResponseProto.newBuilder();
    final EncryptionZone ret = server.getEZForPath(req.getSrc());
    if (ret != null) {
      builder.setZone(PBHelper.convert(ret));
    }
    return builder.build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 3
Source Project: protobuf-socket-rpc   Source File: RpcForwarder.java    License: MIT License 6 votes vote down vote up
private void forwardToService(SocketRpcProtos.Request rpcRequest,
    RpcCallback<Message> callback, Service service,
    RpcController socketController) throws RpcException {
  // Get matching method
  MethodDescriptor method = getMethod(rpcRequest,
      service.getDescriptorForType());

  // Create request for method
  Message request = getRequestProto(rpcRequest,
      service.getRequestPrototype(method));

  // Call method
  try {
    service.callMethod(method, socketController, request, callback);
  } catch (RuntimeException e) {
    throw new RpcException(ErrorReason.RPC_ERROR,
        "Error running method " + method.getFullName(), e);
  }
}
 
Example 4
@Override
public GetDelegationTokenResponseProto getDelegationToken(
    RpcController controller, GetDelegationTokenRequestProto req)
    throws ServiceException {
  try {
    Token<DelegationTokenIdentifier> token = server
        .getDelegationToken(new Text(req.getRenewer()));
    GetDelegationTokenResponseProto.Builder rspBuilder = 
        GetDelegationTokenResponseProto.newBuilder();
    if (token != null) {
      rspBuilder.setToken(PBHelper.convert(token));
    }
    return rspBuilder.build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 5
@Override
public void getActiveTransactionIds(RpcController controller,TxnMessage.ActiveTxnRequest request,RpcCallback<TxnMessage.ActiveTxnIdResponse> done){
    long endTxnId=request.getEndTxnId();
    long startTxnId=request.getStartTxnId();
    try (RpcUtils.RootEnv env = RpcUtils.getRootEnv()) {
        byte[] destTables=null;
        if(request.hasDestinationTables())
            destTables=request.getDestinationTables().toByteArray();
        long[] activeTxnIds=lifecycleStore.getActiveTransactionIds(destTables,startTxnId,endTxnId);
        TxnMessage.ActiveTxnIdResponse.Builder response=TxnMessage.ActiveTxnIdResponse.newBuilder();
        //noinspection ForLoopReplaceableByForEach
        for(int i=0;i<activeTxnIds.length;i++){
            response.addActiveTxnIds(activeTxnIds[i]);
        }
        done.run(response.build());
    }catch(IOException e){
        setControllerException(controller,e);
    }
}
 
Example 6
@Override
public GetEZForPathResponseProto getEZForPath(
    RpcController controller, GetEZForPathRequestProto req)
    throws ServiceException {
  try {
    GetEZForPathResponseProto.Builder builder =
        GetEZForPathResponseProto.newBuilder();
    final EncryptionZone ret = server.getEZForPath(req.getSrc());
    if (ret != null) {
      builder.setZone(PBHelper.convert(ret));
    }
    return builder.build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 7
@Override
public GetGroupsForUserResponseProto getGroupsForUser(
    RpcController controller, GetGroupsForUserRequestProto request)
    throws ServiceException {
  String[] groups;
  try {
    groups = impl.getGroupsForUser(request.getUser());
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  GetGroupsForUserResponseProto.Builder builder = GetGroupsForUserResponseProto
      .newBuilder();
  for (String g : groups) {
    builder.addGroups(g);
  }
  return builder.build();
}
 
Example 8
Source Project: tajo   Source File: TajoMasterClientService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public KeyValueSetResponse getAllSessionVariables(RpcController controller,
                                                             TajoIdProtos.SessionIdProto request)
    throws ServiceException {

  try {
    String sessionId = request.getId();
    KeyValueSet keyValueSet = new KeyValueSet();
    keyValueSet.putAll(context.getSessionManager().getAllVariables(sessionId));

    return KeyValueSetResponse.newBuilder()
        .setState(OK)
        .setValue(keyValueSet.getProto())
        .build();

  } catch (Throwable t) {
    printStackTraceIfError(LOG, t);
    return KeyValueSetResponse.newBuilder()
        .setState(returnError(t))
        .build();
  }
}
 
Example 9
Source Project: tajo   Source File: CatalogServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public GetTablesResponse getAllTables(RpcController controller, NullProto request) throws ServiceException {
  rlock.lock();
  try {
    return GetTablesResponse.newBuilder()
        .setState(OK)
        .addAllTable(store.getAllTables())
        .build();

  } catch (Throwable t) {
    printStackTraceIfError(LOG, t);

    return GetTablesResponse.newBuilder()
        .setState(returnError(t))
        .build();

  } finally {
    rlock.unlock();
  }
}
 
Example 10
@Override
public AddBlockResponseProto addBlock(RpcController controller,
    AddBlockRequestProto req) throws ServiceException {
  
  try {
    List<DatanodeInfoProto> excl = req.getExcludeNodesList();
    List<String> favor = req.getFavoredNodesList();
    LocatedBlock result = server.addBlock(
        req.getSrc(),
        req.getClientName(),
        req.hasPrevious() ? PBHelper.convert(req.getPrevious()) : null,
        (excl == null || excl.size() == 0) ? null : PBHelper.convert(excl
            .toArray(new DatanodeInfoProto[excl.size()])), req.getFileId(),
        (favor == null || favor.size() == 0) ? null : favor
            .toArray(new String[favor.size()]));
    return AddBlockResponseProto.newBuilder()
        .setBlock(PBHelper.convert(result)).build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 11
Source Project: tajo   Source File: CatalogServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public IndexListResponse getAllIndexes(RpcController controller, NullProto request) throws ServiceException {
  rlock.lock();
  try {
    return IndexListResponse.newBuilder().setState(OK).addAllIndexDesc(store.getAllIndexes()).build();

  } catch (Throwable t) {
    printStackTraceIfError(LOG, t);

    return IndexListResponse.newBuilder()
        .setState(returnError(t))
        .build();

  } finally {
    rlock.unlock();
  }
}
 
Example 12
Source Project: incubator-tajo   Source File: DummyProtocolAsyncImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void getNull(RpcController controller, EchoMessage request,
                    RpcCallback<EchoMessage> done) {
  getNullCalled = true;
  LOG.info("noCallback is called");
  done.run(null);
}
 
Example 13
Source Project: incubator-tajo   Source File: DummyProtocolBlockingImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SumResponse sum(RpcController controller, SumRequest request)
    throws ServiceException {
  return SumResponse.newBuilder().setResult(
      request.getX1()+request.getX2()+request.getX3()+request.getX4()
  ).build();
}
 
Example 14
Source Project: big-c   Source File: MRClientProtocolPBServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public KillJobResponseProto killJob(RpcController controller,
    KillJobRequestProto proto) throws ServiceException {
  KillJobRequest request = new KillJobRequestPBImpl(proto);
  try {
    KillJobResponse response = real.killJob(request);
    return ((KillJobResponsePBImpl)response).getProto();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 15
@Override
public AcceptRecoveryResponseProto acceptRecovery(RpcController controller,
    AcceptRecoveryRequestProto request) throws ServiceException {
  try {
    impl.acceptRecovery(convert(request.getReqInfo()),
        request.getStateToAccept(),
        new URL(request.getFromURL()));
    return AcceptRecoveryResponseProto.getDefaultInstance();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 16
@Override
public void rollbackTransactionsAfter(RpcController controller, TxnMessage.TxnRequest request, RpcCallback<TxnMessage.VoidResponse> done) {
    try (RpcUtils.RootEnv env = RpcUtils.getRootEnv()) {
        lifecycleStore.rollbackTransactionsAfter(request.getTxnId());
        done.run(TxnMessage.VoidResponse.getDefaultInstance());
    }catch(IOException ioe){
        setControllerException(controller,ioe);
    }
}
 
Example 17
Source Project: fuchsia   Source File: AddressBookServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
public void listPeople(RpcController controller,
                       AddressBookProtos.NamePattern request, RpcCallback<AddressBookProtos.AddressBook> done) {
    AddressBookProtos.AddressBook.Builder addressbook = AddressBookProtos.AddressBook
            .newBuilder();

    for (AddressBookProtos.Person person : records.values()) {
        if (person.getName().indexOf(request.getPattern()) >= 0) {
            addressbook.addPerson(person);
        }
    }

    done.run(addressbook.build());
}
 
Example 18
Source Project: hbase-indexer   Source File: BaseHRegionServer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public org.apache.hadoop.hbase.protobuf.generated.AdminProtos.UpdateConfigurationResponse updateConfiguration(
        com.google.protobuf.RpcController controller,
        org.apache.hadoop.hbase.protobuf.generated.AdminProtos.UpdateConfigurationRequest request)
        throws com.google.protobuf.ServiceException {
    throw new UnsupportedOperationException("Not implemented");
}
 
Example 19
Source Project: tajo   Source File: QueryMasterManagerService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void executeQuery(RpcController controller,
                         QueryExecutionRequest request,
                         RpcCallback<PrimitiveProtos.NullProto> done) {

  QueryId queryId = new QueryId(request.getQueryId());
  LOG.info("Receive executeQuery request:" + queryId);
  queryMaster.handle(new QueryStartEvent(queryId,
      new Session(request.getSession()),
      new QueryContext(workerContext.getQueryMaster().getContext().getConf(),
          request.getQueryContext()), request.getExprInJson().getValue(),
      request.getLogicalPlanJson().getValue(), new NodeResource(request.getAllocation().getResource())));
  done.run(TajoWorker.NULL_PROTO);
}
 
Example 20
Source Project: phoenix   Source File: MetaDataEndpointImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void clearCache(RpcController controller, ClearCacheRequest request,
        RpcCallback<ClearCacheResponse> done) {
    GlobalCache cache = GlobalCache.getInstance(this.env);
    Cache<ImmutableBytesPtr, PTable> metaDataCache =
            GlobalCache.getInstance(this.env).getMetaDataCache();
    metaDataCache.invalidateAll();
    cache.clearTenantCache();
}
 
Example 21
Source Project: tajo   Source File: CatalogServer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ReturnState dropTable(RpcController controller, TableIdentifierProto request) throws ServiceException {

  String dbName = request.getDatabaseName();
  String tbName = request.getTableName();

  if (linkedMetadataManager.existsDatabase(dbName)) {
    return errInsufficientPrivilege("drop a table in database '" + dbName + "'");
  }

  if (metaDictionary.isSystemDatabase(dbName)) {
    return errInsufficientPrivilege("drop a table in database '" + dbName + "'");
  }

  wlock.lock();
  try {
    store.dropTable(dbName, tbName);
    LOG.info(String.format("relation \"%s\" is deleted from the catalog (%s)",
        IdentifierUtil.getCanonicalTableName(dbName, tbName), bindAddress));

    return OK;

  } catch (Throwable t) {
    printStackTraceIfError(LOG, t);
    return returnError(t);

  } finally {
    wlock.unlock();
  }
}
 
Example 22
Source Project: gameserver   Source File: RpcTestService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void test(RpcController controller, RpcTestReq request,
		RpcCallback<RpcTestResp> done) {
	int sleep = request.getSleep();
	System.out.println("sleep: " + sleep);
	try {
		Thread.sleep(sleep);
	} catch (InterruptedException e) {
	}
	RpcTestResp.Builder respBuilder = RpcTestResp.newBuilder();
	respBuilder.setSleep(sleep);
	done.run(respBuilder.build());
}
 
Example 23
@Override
public DeleteBlockPoolResponseProto deleteBlockPool(RpcController unused,
    DeleteBlockPoolRequestProto request) throws ServiceException {
  try {
    impl.deleteBlockPool(request.getBlockPool(), request.getForce());
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return DELETE_BLOCKPOOL_RESP;
}
 
Example 24
Source Project: tajo   Source File: DummyProtocolAsyncImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void delay(RpcController controller, EchoMessage request,
                  RpcCallback<EchoMessage> done) {
  try {
    Thread.sleep(3000);
  } catch (InterruptedException e) {
    LOG.error(e.getMessage());
  }

  done.run(request);
}
 
Example 25
@Override
public DoRollbackResponseProto doRollback(RpcController controller, DoRollbackRequestProto request)
    throws ServiceException {
  try {
    impl.doRollback(convert(request.getJid()));
    return DoRollbackResponseProto.getDefaultInstance();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 26
@Override
public ListCorruptFileBlocksResponseProto listCorruptFileBlocks(
    RpcController controller, ListCorruptFileBlocksRequestProto req)
    throws ServiceException {
  try {
    CorruptFileBlocks result = server.listCorruptFileBlocks(
        req.getPath(), req.hasCookie() ? req.getCookie(): null);
    return ListCorruptFileBlocksResponseProto.newBuilder()
        .setCorrupt(PBHelper.convert(result))
        .build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 27
@Override
public DeleteSnapshotResponseProto deleteSnapshot(RpcController controller,
    DeleteSnapshotRequestProto req) throws ServiceException {
  try {
    server.deleteSnapshot(req.getSnapshotRoot(), req.getSnapshotName());
    return VOID_DELETE_SNAPSHOT_RESPONSE;
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 28
Source Project: tajo   Source File: TajoMasterClientService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetQueryListResponse getFinishedQueryList(RpcController controller, TajoIdProtos.SessionIdProto request)
    throws ServiceException {

  GetQueryListResponse.Builder builder = GetQueryListResponse.newBuilder();

  try {
    context.getSessionManager().touch(request.getId());

    Collection<QueryInfo> queries
        = context.getQueryJobManager().getFinishedQueries();

    BriefQueryInfo.Builder infoBuilder = BriefQueryInfo.newBuilder();

    for (QueryInfo queryInfo : queries) {
      infoBuilder.setQueryId(queryInfo.getQueryId().getProto());
      infoBuilder.setState(queryInfo.getQueryState());
      infoBuilder.setQuery(queryInfo.getSql());
      infoBuilder.setStartTime(queryInfo.getStartTime());
      infoBuilder.setFinishTime(queryInfo.getFinishTime());
      infoBuilder.setProgress(queryInfo.getProgress());
      if(queryInfo.getQueryMasterHost() != null){
        infoBuilder.setQueryMasterPort(queryInfo.getQueryMasterPort());
        infoBuilder.setQueryMasterHost(queryInfo.getQueryMasterHost());
      }

      builder.addQueryList(infoBuilder.build());
    }

    builder.setState(OK);

  } catch (Throwable t) {
    printStackTraceIfError(LOG, t);
    builder.setState(returnError(t));
  }

  return builder.build();
}
 
Example 29
@Override
public GetServiceStatusResponseProto getServiceStatus(RpcController controller,
    GetServiceStatusRequestProto request) throws ServiceException {
  HAServiceStatus s;
  try {
    s = server.getServiceStatus();
  } catch(IOException e) {
    throw new ServiceException(e);
  }
  
  HAServiceStateProto retState;
  switch (s.getState()) {
  case ACTIVE:
    retState = HAServiceStateProto.ACTIVE;
    break;
  case STANDBY:
    retState = HAServiceStateProto.STANDBY;
    break;
  case INITIALIZING:
  default:
    retState = HAServiceStateProto.INITIALIZING;
    break;
  }
  
  GetServiceStatusResponseProto.Builder ret =
    GetServiceStatusResponseProto.newBuilder()
      .setState(retState)
      .setReadyToBecomeActive(s.isReadyToBecomeActive());
  if (!s.isReadyToBecomeActive()) {
    ret.setNotReadyReason(s.getNotReadyReason());
  }
  return ret.build();
}
 
Example 30
Source Project: tajo   Source File: CatalogServer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ReturnState createTable(RpcController controller, TableDescProto request) {

  String [] splitted = IdentifierUtil.splitFQTableName(request.getTableName());

  String dbName = splitted[0];
  String tbName = splitted[1];

  if (linkedMetadataManager.existsDatabase(dbName)) {
    return errInsufficientPrivilege("drop a table in database '" + dbName + "'");
  }

  if (metaDictionary.isSystemDatabase(dbName)) {
    return errInsufficientPrivilege("create a table in database '" + dbName + "'");
  }

  wlock.lock();
  try {
    store.createTable(request);
    LOG.info(String.format("relation \"%s\" is added to the catalog (%s)",
        IdentifierUtil.getCanonicalTableName(dbName, tbName), bindAddress));
    return OK;

  } catch (Throwable t) {
    printStackTraceIfError(LOG, t);
    return returnError(t);

  } finally {
    wlock.unlock();
  }
}