本文整理匯總了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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
}
示例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;
}
示例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));
}
}