当前位置: 首页>>代码示例>>Java>>正文


Java Service类代码示例

本文整理汇总了Java中com.google.protobuf.Service的典型用法代码示例。如果您正苦于以下问题:Java Service类的具体用法?Java Service怎么用?Java Service使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Service类属于com.google.protobuf包,在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doStart

import com.google.protobuf.Service; //导入依赖的package包/类
@Override
protected void doStart() {

    try {

        log.load();

        RaftServiceEndpoint endpoint = new RaftServiceEndpoint(ctx);
        Service replicaService = RaftProto.RaftService.newReflectiveService(endpoint);
        rpcServer.registerService(replicaService);
        rpcServer.startAsync().addListener(new Listener() {
            @Override
            public void running() {
                ctx.setState(RaftStateContext.StateType.FOLLOWER);
            }
        }, MoreExecutors.sameThreadExecutor());
        rpcServer.awaitRunning();

        notifyStarted();

    } catch (Exception e) {
        notifyFailed(e);
    }

}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:26,代码来源:RaftService.java

示例2: registerService

import com.google.protobuf.Service; //导入依赖的package包/类
@Override
public boolean registerService(Service instance) {
  /*
   * No stacking of instances is allowed for a single service name
   */
  Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
  if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
    LOG.error("Coprocessor service "+serviceDesc.getFullName()+
        " already registered, rejecting request from "+instance
    );
    return false;
  }

  coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Registered master coprocessor service: service="+serviceDesc.getFullName());
  }
  return true;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:HMaster.java

示例3: registerService

import com.google.protobuf.Service; //导入依赖的package包/类
@Override public boolean registerService(Service instance) {
  /*
   * No stacking of instances is allowed for a single service name
   */
  Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
  if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
    LOG.error("Coprocessor service " + serviceDesc.getFullName()
        + " already registered, rejecting request from " + instance);
    return false;
  }

  coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
  if (LOG.isDebugEnabled()) {
    LOG.debug(
        "Registered regionserver coprocessor service: service=" + serviceDesc.getFullName());
  }
  return true;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:HRegionServer.java

示例4: registerService

import com.google.protobuf.Service; //导入依赖的package包/类
@Override public boolean registerService(Service instance) {
  /*
   * No stacking of instances is allowed for a single service name
   */
  Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
  if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
    LOG.error("Coprocessor service " + serviceDesc.getFullName()
        + " already registered, rejecting request from " + instance);
    return false;
  }

  coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Registered coprocessor service: region=" + Bytes
        .toStringBinary(getRegionInfo().getRegionName()) + " service=" + serviceDesc
        .getFullName());
  }
  return true;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:HRegion.java

示例5: coprocessorService

import com.google.protobuf.Service; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public <T extends Service, R> Map<byte[],R> coprocessorService(final Class<T> service,
    byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable)
    throws ServiceException, Throwable {
  final Map<byte[],R> results =  Collections.synchronizedMap(
      new TreeMap<byte[], R>(Bytes.BYTES_COMPARATOR));
  coprocessorService(service, startKey, endKey, callable, new Batch.Callback<R>() {
    @Override
    public void update(byte[] region, byte[] row, R value) {
      if (region != null) {
        results.put(region, value);
      }
    }
  });
  return results;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:HTable.java

示例6: doBlockingRpc

import com.google.protobuf.Service; //导入依赖的package包/类
/**
 * Handle the blocking RPC request by forwarding it to the correct
 * service/method.
 *
 * @throws RpcException If there was some error executing the RPC.
 */
public SocketRpcProtos.Response doBlockingRpc(
    SocketRpcProtos.Request rpcRequest) throws RpcException {
  // Get the service, first try BlockingService
  BlockingService blockingService = blockingServiceMap.get(
      rpcRequest.getServiceName());
  if (blockingService != null) {
    return forwardToBlockingService(rpcRequest, blockingService);
  }

  // Now try Service
  Service service = serviceMap.get(rpcRequest.getServiceName());
  if (service == null) {
    throw new RpcException(ErrorReason.SERVICE_NOT_FOUND,
        "Could not find service: " + rpcRequest.getServiceName(), null);
  }

  // Call service using an instant callback
  Callback<Message> callback = new Callback<Message>();
  SocketRpcController socketController = new SocketRpcController();
  forwardToService(rpcRequest, callback, service, socketController);

  // Build and return response (callback invocation is optional)
  return createRpcResponse(callback.response, callback.invoked,
      socketController);
}
 
开发者ID:sdeo,项目名称:protobuf-socket-rpc,代码行数:32,代码来源:RpcForwarder.java

示例7: forwardToService

import com.google.protobuf.Service; //导入依赖的package包/类
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);
  }
}
 
开发者ID:sdeo,项目名称:protobuf-socket-rpc,代码行数:20,代码来源:RpcForwarder.java

示例8: registerService

import com.google.protobuf.Service; //导入依赖的package包/类
@Override
public boolean registerService(Service instance) {
/*
 * No stacking of instances is allowed for a single service name
 */
    Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
    if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
        LOG.error("Coprocessor service " + serviceDesc.getFullName() +
                        " already registered, rejecting request from " + instance
        );
        return false;
    }

    coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Registered master coprocessor service: service=" + serviceDesc.getFullName());
    }
    return true;
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:20,代码来源:HMaster.java

示例9: registerService

import com.google.protobuf.Service; //导入依赖的package包/类
@Override
public boolean registerService(Service instance) {
/*
 * No stacking of instances is allowed for a single service name
 */
    Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
    if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
        LOG.error("Coprocessor service " + serviceDesc.getFullName()
                + " already registered, rejecting request from " + instance);
        return false;
    }

    coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Registered regionserver coprocessor service: service=" + serviceDesc.getFullName());
    }
    return true;
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:19,代码来源:HRegionServer.java

示例10: registerService

import com.google.protobuf.Service; //导入依赖的package包/类
/**
 * Registers a new protocol buffer {@link Service} subclass as a coprocessor endpoint to
 * be available for handling
 * {@link HRegion#execService(com.google.protobuf.RpcController,
 * org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceCall)}} calls.
 * <p/>
 * <p>
 * Only a single instance may be registered per region for a given {@link Service} subclass (the
 * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}.
 * After the first registration, subsequent calls with the same service name will fail with
 * a return value of {@code false}.
 * </p>
 *
 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
 * @return {@code true} if the registration was successful, {@code false}
 * otherwise
 */
public boolean registerService(Service instance) {
/*
 * No stacking of instances is allowed for a single service name
 */
    Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
    if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
        LOG.error("Coprocessor service " + serviceDesc.getFullName() +
                        " already registered, rejecting request from " + instance
        );
        return false;
    }

    coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Registered coprocessor service: region=" +
                Bytes.toStringBinary(getRegionName()) + " service=" + serviceDesc.getFullName());
    }
    return true;
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:37,代码来源:HRegion.java

示例11: registerService

import com.google.protobuf.Service; //导入依赖的package包/类
/**
 * Registers a new protocol buffer {@link Service} subclass as a coprocessor endpoint to
 * be available for handling
 * {@link HRegion#execService(com.google.protobuf.RpcController,
 *    org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceCall)}} calls.
 *
 * <p>
 * Only a single instance may be registered per region for a given {@link Service} subclass (the
 * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}.
 * After the first registration, subsequent calls with the same service name will fail with
 * a return value of {@code false}.
 * </p>
 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
 * @return {@code true} if the registration was successful, {@code false}
 * otherwise
 */
public boolean registerService(Service instance) {
  /*
   * No stacking of instances is allowed for a single service name
   */
  Descriptors.ServiceDescriptor serviceDesc = instance.getDescriptorForType();
  if (coprocessorServiceHandlers.containsKey(serviceDesc.getFullName())) {
    LOG.error("Coprocessor service "+serviceDesc.getFullName()+
        " already registered, rejecting request from "+instance
    );
    return false;
  }

  coprocessorServiceHandlers.put(serviceDesc.getFullName(), instance);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Registered coprocessor service: region="+
        Bytes.toStringBinary(getRegionName())+" service="+serviceDesc.getFullName());
  }
  return true;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:36,代码来源:HRegion.java

示例12: preEndpointInvocation

import com.google.protobuf.Service; //导入依赖的package包/类
public Message preEndpointInvocation(final Service service, final String methodName,
    Message request) throws IOException {
  ObserverContext<RegionCoprocessorEnvironment> ctx = null;
  for (RegionEnvironment env : coprocessors) {
    if (env.getInstance() instanceof EndpointObserver) {
      ctx = ObserverContext.createAndPrepare(env, ctx);
      Thread currentThread = Thread.currentThread();
      ClassLoader cl = currentThread.getContextClassLoader();
      try {
        currentThread.setContextClassLoader(env.getClassLoader());
        request = ((EndpointObserver) env.getInstance()).preEndpointInvocation(ctx, service,
          methodName, request);
      } catch (Throwable e) {
        handleCoprocessorThrowable(env, e);
      } finally {
        currentThread.setContextClassLoader(cl);
      }
      if (ctx.shouldComplete()) {
        break;
      }
    }
  }
  return request;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:25,代码来源:RegionCoprocessorHost.java

示例13: postEndpointInvocation

import com.google.protobuf.Service; //导入依赖的package包/类
public void postEndpointInvocation(final Service service, final String methodName,
    final Message request, final Message.Builder responseBuilder) throws IOException {
  ObserverContext<RegionCoprocessorEnvironment> ctx = null;
  for (RegionEnvironment env : coprocessors) {
    if (env.getInstance() instanceof EndpointObserver) {
      ctx = ObserverContext.createAndPrepare(env, ctx);
      Thread currentThread = Thread.currentThread();
      ClassLoader cl = currentThread.getContextClassLoader();
      try {
        currentThread.setContextClassLoader(env.getClassLoader());
        ((EndpointObserver) env.getInstance()).postEndpointInvocation(ctx, service,
          methodName, request, responseBuilder);
      } catch (Throwable e) {
        handleCoprocessorThrowable(env, e);
      } finally {
        currentThread.setContextClassLoader(cl);
      }
      if (ctx.shouldComplete()) {
        break;
      }
    }
  }
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:24,代码来源:RegionCoprocessorHost.java

示例14: coprocessorService

import com.google.protobuf.Service; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public <T extends Service, R> Map<byte[],R> coprocessorService(final Class<T> service,
    byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable)
    throws ServiceException, Throwable {
  final Map<byte[],R> results =  Collections.synchronizedMap(
      new TreeMap<byte[], R>(Bytes.BYTES_COMPARATOR));
  coprocessorService(service, startKey, endKey, callable, new Batch.Callback<R>() {
    public void update(byte[] region, byte[] row, R value) {
      if (region != null) {
        results.put(region, value);
      }
    }
  });
  return results;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:19,代码来源:HTable.java

示例15: register

import com.google.protobuf.Service; //导入依赖的package包/类
public void register(Service service) {
    // TODO: Support registering multiple local services? Needs "local 2PC" effectively. Yuck.
    Descriptors.ServiceDescriptor descriptor = service.getDescriptorForType();
    for (MethodDescriptor i : descriptor.getMethods()) {
        if (methods.containsKey(i.getFullName())) {
            throw new IllegalStateException(
                    "method " + i.getFullName() + " is already registered");
        }
        methods.put(i.getFullName(), new ProtoMethodInvoker(service, i));
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:12,代码来源:ServiceRegistry.java


注:本文中的com.google.protobuf.Service类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。