本文整理汇总了Java中org.apache.thrift.ProcessFunction类的典型用法代码示例。如果您正苦于以下问题:Java ProcessFunction类的具体用法?Java ProcessFunction怎么用?Java ProcessFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProcessFunction类属于org.apache.thrift包,在下文中一共展示了ProcessFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
@Override
public final boolean process(final TProtocol in, final TProtocol out)
throws TException {
final TMessage msg = in.readMessageBegin();
final ProcessFunction<LocatorServiceImpl, ?> fn = this.fnMap
.get(msg.name);
if (fn != null) {
fn.process(msg.seqid, in, out, this.inst);
// terminate connection on receiving closeConnection
// direct class comparison should be the fastest way
return fn.getClass() != LocatorService.Processor.closeConnection.class;
}
else {
TProtocolUtil.skip(in, TType.STRUCT);
in.readMessageEnd();
TApplicationException x = new TApplicationException(
TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
+ msg.name + "'");
out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
msg.seqid));
x.write(out);
out.writeMessageEnd();
out.getTransport().flush();
return true;
}
}
示例2: invokeSynchronously
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
private static void invokeSynchronously(
ServiceRequestContext ctx, Object impl,
ThriftFunction func, TBase<?, ?> args, DefaultRpcResponse reply) {
final ProcessFunction<Object, TBase<?, ?>> f = func.syncFunc();
ctx.blockingTaskExecutor().execute(() -> {
if (reply.isDone()) {
// Closed already most likely due to timeout.
return;
}
try {
final TBase<?, ?> result = f.getResult(impl, args);
if (func.isOneWay()) {
reply.complete(null);
} else {
reply.complete(func.getResult(result));
}
} catch (Throwable t) {
reply.completeExceptionally(t);
}
});
}
示例3: registerFunction
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private void registerFunction(Set<String> methodNames, Class<?> iface, String name, Object func) {
checkDuplicateMethodName(methodNames, name);
methodNames.add(name);
try {
final ThriftFunction f;
if (func instanceof ProcessFunction) {
f = new ThriftFunction(iface, (ProcessFunction) func);
} else {
f = new ThriftFunction(iface, (AsyncProcessFunction) func);
}
functions.put(name, f);
} catch (Exception e) {
throw new IllegalArgumentException("failed to retrieve function metadata: " +
iface.getName() + '.' + name + "()", e);
}
}
示例4: process
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
@Override
public final boolean process(final TProtocol in, final TProtocol out)
throws TException {
final TMessage msg = in.readMessageBegin();
final ProcessFunction<GFXDServiceImpl, ?> fn = this.fnMap.get(msg.name);
if (fn != null) {
fn.process(msg.seqid, in, out, this.inst);
// terminate connection on receiving closeConnection
// direct class comparison should be the fastest way
// TODO: SW: also need to clean up connection artifacts in the case of
// client connection failure (ConnectionListener does get a notification
// but how to tie the socket/connectionNumber to the connectionID?)
return fn.getClass() != GFXDService.Processor.closeConnection.class;
}
else {
TProtocolUtil.skip(in, TType.STRUCT);
in.readMessageEnd();
TApplicationException x = new TApplicationException(
TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
+ msg.name + "'");
out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
msg.seqid));
x.write(out);
out.writeMessageEnd();
out.getTransport().flush();
return true;
}
}
示例5: getProcessMap
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
/**
* Constructs the map from function name -> handler.
* @param calls The call queue.
* @return The map.
*/
private static Map<String, ProcessFunction> getProcessMap(
LinkedBlockingQueue<TBase> calls) {
Map<String, ProcessFunction> processMap =
new HashMap<String, ProcessFunction>();
processMap.put("grantResource", new grantResourceHandler(calls));
processMap.put("revokeResource", new revokeResourceHandler(calls));
processMap.put("processDeadNode", new processDeadNodeHandler(calls));
return processMap;
}
示例6: init
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
private Set<Class<?>> init(Object implementation, Iterable<Class<?>> candidateInterfaces) {
// Build the map of method names and their corresponding process functions.
final Set<String> methodNames = new HashSet<>();
final Set<Class<?>> interfaces = new HashSet<>();
for (Class<?> iface : candidateInterfaces) {
final Map<String, AsyncProcessFunction<?, ?, ?>> asyncProcessMap;
asyncProcessMap = getThriftAsyncProcessMap(implementation, iface);
if (asyncProcessMap != null) {
asyncProcessMap.forEach(
(name, func) -> registerFunction(methodNames, iface, name, func));
interfaces.add(iface);
}
final Map<String, ProcessFunction<?, ?>> processMap;
processMap = getThriftProcessMap(implementation, iface);
if (processMap != null) {
processMap.forEach(
(name, func) -> registerFunction(methodNames, iface, name, func));
interfaces.add(iface);
}
}
if (functions.isEmpty()) {
if (implementation != null) {
throw new IllegalArgumentException('\'' + implementation.getClass().getName() +
"' is not a Thrift service implementation.");
} else {
throw new IllegalArgumentException("not a Thrift service interface: " + candidateInterfaces);
}
}
return Collections.unmodifiableSet(interfaces);
}
示例7: getThriftProcessMap
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
private static Map<String, ProcessFunction<?, ?>> getThriftProcessMap(Object service, Class<?> iface) {
final String name = iface.getName();
if (!name.endsWith("$Iface")) {
return null;
}
final String processorName = name.substring(0, name.length() - 5) + "Processor";
try {
final Class<?> processorClass = Class.forName(processorName, false, iface.getClassLoader());
if (!TBaseProcessor.class.isAssignableFrom(processorClass)) {
return null;
}
final Constructor<?> processorConstructor = processorClass.getConstructor(iface);
@SuppressWarnings("rawtypes")
final TBaseProcessor processor = (TBaseProcessor) processorConstructor.newInstance(service);
@SuppressWarnings("unchecked")
Map<String, ProcessFunction<?, ?>> processMap =
(Map<String, ProcessFunction<?, ?>>) processor.getProcessMapView();
return processMap;
} catch (Exception e) {
logger.debug("Failed to retrieve the process map from: {}", iface, e);
return null;
}
}
示例8: before
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
// process(int seqid, TProtocol iprot, TProtocol oprot, I iface)
if (args.length != 4) {
return;
}
String methodName = ThriftConstants.UNKNOWN_METHOD_NAME;
if (target instanceof ProcessFunction) {
ProcessFunction<?, ?> processFunction = (ProcessFunction<?, ?>)target;
methodName = processFunction.getMethodName();
}
ThriftClientCallContext clientCallContext = new ThriftClientCallContext(methodName);
InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
currentTransaction.setAttachment(clientCallContext);
// Set server marker - server handlers may create a client to call another Thrift server.
// When this happens, TProtocol interceptors for clients are triggered since technically they're still within THRIFT_SERVER_SCOPE.
// We set the marker inside server's input protocol to safeguard against such cases.
Object iprot = args[1];
// With the addition of TProtocolDecorator, iprot may actually be a wrapper around the actual input protocol
Object rootInputProtocol = getRootInputProtocol(iprot);
if (validateInputProtocol(rootInputProtocol)) {
((ServerMarkerFlagFieldAccessor)rootInputProtocol)._$PINPOINT$_setServerMarkerFlag(true);
}
}
示例9: Processor
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
public Processor(LocatorServiceImpl inst) {
super(inst);
this.inst = inst;
this.fnMap = new HashMap<String, ProcessFunction<LocatorServiceImpl, ?>>(
super.getProcessMapView());
}
示例10: Processor
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
public Processor(GFXDServiceImpl inst) {
super(inst);
this.inst = inst;
this.fnMap = new HashMap<String, ProcessFunction<GFXDServiceImpl, ?>>(
super.getProcessMapView());
}
示例11: ServiceProcessor
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public ServiceProcessor(Service service) {
super(service, getProcessMap(new HashMap<String, ProcessFunction<Service, ? extends TBase>>()));
}
示例12: getProcessMap
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private static Map<String, ProcessFunction<Service, ? extends TBase>> getProcessMap(
Map<String, ProcessFunction<Service, ? extends TBase>> processMap) {
processMap.put(FUNCTION_NAME, new GetProcessFunction());
return processMap;
}
示例13: ThriftFunction
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
ThriftFunction(Class<?> serviceType, ProcessFunction<?, ?> func) throws Exception {
this(serviceType, func.getMethodName(), func, Type.SYNC,
getArgFields(func), getResult(func), getDeclaredExceptions(func));
}
示例14: getResult
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
private static TBase<?, ?> getResult(ProcessFunction<?, ?> func) {
return getResult0(Type.SYNC, func.getClass(), func.getMethodName());
}
示例15: getArgs
import org.apache.thrift.ProcessFunction; //导入依赖的package包/类
private static TBase<?, ?> getArgs(ProcessFunction<?, ?> func) {
return getArgs0(Type.SYNC, func.getClass(), func.getMethodName());
}