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


Java TProtocolFactory类代码示例

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


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

示例1: getClientConstructor

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
	String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
	Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};

	Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
	if (clientClass == null) {
		throw new ThriftRuntimeException("the client class is null");
	}

	Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
	if (constructor == null) {
		throw new ThriftRuntimeException("the clientClass constructor is null");
	}

	return constructor;
}
 
开发者ID:funtl,项目名称:framework,代码行数:17,代码来源:ThriftUtil.java

示例2: ApacheThriftMethodInvoker

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public ApacheThriftMethodInvoker(
        ListeningExecutorService executorService,
        ListeningScheduledExecutorService delayService,
        TTransportFactory transportFactory,
        TProtocolFactory protocolFactory,
        Duration connectTimeout,
        Duration requestTimeout,
        Optional<HostAndPort> socksProxy,
        Optional<SSLContext> sslContext)
{
    this.executorService = requireNonNull(executorService, "executorService is null");
    this.delayService = requireNonNull(delayService, "delayService is null");
    this.transportFactory = requireNonNull(transportFactory, "transportFactory is null");
    this.protocolFactory = requireNonNull(protocolFactory, "protocolFactory is null");
    this.connectTimeoutMillis = Ints.saturatedCast(requireNonNull(connectTimeout, "connectTimeout is null").toMillis());
    this.requestTimeoutMillis = Ints.saturatedCast(requireNonNull(requestTimeout, "requestTimeout is null").toMillis());
    this.socksProxy = requireNonNull(socksProxy, "socksProxy is null");
    this.sslContext = requireNonNull(sslContext, "sslContext is null");
}
 
开发者ID:airlift,项目名称:drift,代码行数:20,代码来源:ApacheThriftMethodInvoker.java

示例3: ThriftTestingSource

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public ThriftTestingSource(String handlerName, int port, String protocol) throws Exception {
  TNonblockingServerTransport serverTransport =
      new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", port));
  ThriftSourceProtocol.Iface handler = getHandler(handlerName);

  TProtocolFactory transportProtocolFactory = null;
  if (protocol != null && protocol == ThriftRpcClient.BINARY_PROTOCOL) {
    transportProtocolFactory = new TBinaryProtocol.Factory();
  } else {
    transportProtocolFactory = new TCompactProtocol.Factory();
  }
  server = new THsHaServer(new THsHaServer.Args(serverTransport).processor(
      new ThriftSourceProtocol.Processor(handler)).protocolFactory(
          transportProtocolFactory));
  Executors.newSingleThreadExecutor().submit(new Runnable() {
    @Override
    public void run() {
      server.serve();
    }
  });
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:22,代码来源:ThriftTestingSource.java

示例4: getProtocolFactory

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private TProtocolFactory getProtocolFactory() {
  if (protocol.equals(BINARY_PROTOCOL)) {
    logger.info("Using TBinaryProtocol");
    return new TBinaryProtocol.Factory();
  } else {
    logger.info("Using TCompactProtocol");
    return new TCompactProtocol.Factory();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:10,代码来源:ThriftSource.java

示例5: getTThreadPoolServer

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,
                                            TProcessor processor,
                                            TTransportFactory transportFactory,
                                            int workerThreads,
                                            InetSocketAddress inetSocketAddress,
                                            int backlog,
                                            int clientTimeout)
    throws TTransportException {
  TServerTransport serverTransport = new TServerSocket(
                                         new TServerSocket.ServerSocketTransportArgs().
                                             bindAddr(inetSocketAddress).backlog(backlog).
                                             clientTimeout(clientTimeout));
  log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
  TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  if (workerThreads > 0) {
    serverArgs.maxWorkerThreads(workerThreads);
  }
  return new TThreadPoolServer(serverArgs);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:ThriftServer.java

示例6: getClient

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <X extends TAsyncClient> X getClient(final Class<X> clazz) {
    return (X) super.clients.computeIfAbsent(ClassNameUtils.getOuterClassName(clazz), (className) -> {
        TProtocolFactory protocolFactory = (TProtocolFactory) tTransport -> {
            TProtocol protocol = new TBinaryProtocol(tTransport);
            return new TMultiplexedProtocol(protocol, className);
        };
        try {
            return clazz.getConstructor(TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class)
                    .newInstance(protocolFactory, this.clientManager, this.transport);
        } catch (Throwable e) {
            if (e instanceof UnresolvedAddressException) {
                this.isOpen = false;
            }
            return null;
        }
    });
}
 
开发者ID:sofn,项目名称:trpc,代码行数:20,代码来源:AsyncTrpcClient.java

示例7: start

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public void start(CountDownLatch latch, int port) {
    try {
        TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port);
        //异步IO,需要使用TFramedTransport,它将分块缓存读取。
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        //使用高密度二进制协议
        TProtocolFactory proFactory = new TBinaryProtocol.Factory();
        //发布多个服务
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor(ClassNameUtils.getClassName(Hello.class), new Hello.Processor<>(new HelloServer()));

        TServer server = new TThreadedSelectorServer(new
                TThreadedSelectorServer.Args(serverTransport)
                .transportFactory(transportFactory)
                .protocolFactory(proFactory)
                .processor(processor)
        );
        System.out.println("Starting the hello server...");
        latch.countDown();
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:sofn,项目名称:trpc,代码行数:25,代码来源:DemoServer.java

示例8: messageReceived

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
@Override
protected void messageReceived(ChannelHandlerContext ctx, ThriftMessage message) throws Exception {
	ByteBuf buffer = message.getContent();
	logger.debug("msg.content:: {}", buffer);
	try {
		TNettyTransport transport = new TNettyTransport(ctx.channel(), buffer);
		TProtocolFactory protocolFactory = message.getProtocolFactory();
		TProtocol protocol = protocolFactory.getProtocol(transport);
		serverDef.nettyProcessor.process(ctx, protocol, protocol,
				new DefaultWriterListener(message, transport, ctx, serverDef));
	} catch (Throwable ex) {
		int refCount = buffer.refCnt();
		if (refCount > 0) {
			buffer.release(refCount);
		}
		throw ex;
	}
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:19,代码来源:ThriftMessageEncoder.java

示例9: run

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public void run() {
    ThriftTestHandler handler = new ThriftTestHandler(System.out);
    ThriftTest.Processor<ThriftTestHandler> processor = new ThriftTest.Processor<>(handler);

    TProtocolFactory factory = getProtocolFactory();

    serverTransport = getServerTransport();
    server = startServer(processor, factory);

    final CountDownLatch latch = new CountDownLatch(1);
    serverThread = new Thread(() -> {
        latch.countDown();
        server.serve();
    });

    serverThread.start();

    try {
        latch.await(100, TimeUnit.MILLISECONDS);
    } catch (InterruptedException ignored) {
        // continue
    }
}
 
开发者ID:Microsoft,项目名称:thrifty,代码行数:24,代码来源:TestServer.java

示例10: getClientConstructor

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
    String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
    Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};

    Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
    if (clientClass == null) {
        throw new ThriftRuntimeException("the client class is null");
    }

    Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
    if (constructor == null) {
        throw new ThriftRuntimeException("the clientClass constructor is null");
    }

    return constructor;
}
 
开发者ID:superhj1987,项目名称:spring-remoting-thrift,代码行数:17,代码来源:ThriftUtil.java

示例11: get

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
/**
 * Returns the {@link TProtocolFactory} for the specified {@link SerializationFormat}.
 *
 * @throws IllegalArgumentException if the specified {@link SerializationFormat} is not for Thrift
 */
public static TProtocolFactory get(SerializationFormat serializationFormat) {
    requireNonNull(serializationFormat, "serializationFormat");

    if (serializationFormat == ThriftSerializationFormats.BINARY) {
        return BINARY;
    }

    if (serializationFormat == ThriftSerializationFormats.COMPACT) {
        return COMPACT;
    }

    if (serializationFormat == ThriftSerializationFormats.JSON) {
        return JSON;
    }

    if (serializationFormat == ThriftSerializationFormats.TEXT) {
        return TEXT;
    }

    throw new IllegalArgumentException("non-Thrift serializationFormat: " + serializationFormat);
}
 
开发者ID:line,项目名称:armeria,代码行数:27,代码来源:ThriftProtocolFactories.java

示例12: toSerializationFormat

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
/**
 * Returns the {@link SerializationFormat} for the specified {@link TProtocolFactory}.
 *
 * @throws IllegalArgumentException if the specified {@link TProtocolFactory} is not known by this class
 */
public static SerializationFormat toSerializationFormat(TProtocolFactory protoFactory) {
    requireNonNull(protoFactory, "protoFactory");

    if (protoFactory instanceof TBinaryProtocol.Factory) {
        return ThriftSerializationFormats.BINARY;
    } else if (protoFactory instanceof TCompactProtocol.Factory) {
        return ThriftSerializationFormats.COMPACT;
    } else if (protoFactory instanceof TJSONProtocol.Factory) {
        return ThriftSerializationFormats.JSON;
    } else if (protoFactory instanceof TTextProtocol.Factory) {
        return ThriftSerializationFormats.TEXT;
    } else {
        throw new IllegalArgumentException(
                "unsupported TProtocolFactory: " + protoFactory.getClass().getName());
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:ThriftProtocolFactories.java

示例13: getTHsHaServer

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private static TServer getTHsHaServer(TProtocolFactory protocolFactory,
    TProcessor processor, TTransportFactory transportFactory,
    int workerThreads, int maxCallQueueSize,
    InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
    throws TTransportException {
  TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
  log.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());
  THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
  if (workerThreads > 0) {
    // Could support the min & max threads, avoiding to preserve existing functionality.
    serverArgs.minWorkerThreads(workerThreads).maxWorkerThreads(workerThreads);
  }
  ExecutorService executorService = createExecutor(
      workerThreads, maxCallQueueSize, metrics);
  serverArgs.executorService(executorService);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  return new THsHaServer(serverArgs);
}
 
开发者ID:apache,项目名称:hbase,代码行数:21,代码来源:ThriftServer.java

示例14: getTThreadedSelectorServer

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private static TServer getTThreadedSelectorServer(TProtocolFactory protocolFactory,
    TProcessor processor, TTransportFactory transportFactory,
    int workerThreads, int selectorThreads, int maxCallQueueSize,
    InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
    throws TTransportException {
  TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
  log.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString());
  TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport);
  if (workerThreads > 0) {
    serverArgs.workerThreads(workerThreads);
  }
  if (selectorThreads > 0) {
    serverArgs.selectorThreads(selectorThreads);
  }

  ExecutorService executorService = createExecutor(
      workerThreads, maxCallQueueSize, metrics);
  serverArgs.executorService(executorService);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  return new TThreadedSelectorServer(serverArgs);
}
 
开发者ID:apache,项目名称:hbase,代码行数:24,代码来源:ThriftServer.java

示例15: getServer

import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private TServer getServer(int workerThreads, int selectorThreads, int maxCallQueueSize,
      int readTimeout, int backlog, boolean nonblocking, boolean hsha, boolean selector,
      ThriftMetrics metrics, TProtocolFactory protocolFactory, TProcessor processor,
      TTransportFactory transportFactory, InetSocketAddress inetSocketAddress)
        throws TTransportException {
  TServer server;

  if (nonblocking) {
    server = getTNonBlockingServer(protocolFactory, processor, transportFactory,
            inetSocketAddress);
  } else if (hsha) {
    server = getTHsHaServer(protocolFactory, processor, transportFactory, workerThreads,
            maxCallQueueSize, inetSocketAddress, metrics);
  } else if (selector) {
    server = getTThreadedSelectorServer(protocolFactory, processor, transportFactory,
            workerThreads, selectorThreads, maxCallQueueSize, inetSocketAddress, metrics);
  } else {
    server = getTThreadPoolServer(protocolFactory, processor, transportFactory, workerThreads,
            inetSocketAddress, backlog, readTimeout, metrics);
  }
  return server;
}
 
开发者ID:apache,项目名称:hbase,代码行数:23,代码来源:ThriftServer.java


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