Java 类com.facebook.swift.codec.ThriftCodecManager 实例源码
项目:high
文件:Client.java
/**
* @param args
*/
public static void main(String[] args) throws Exception {
/**
TTransport transport = new TSocket("localhost", 8080);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
ThriftTestService.Client client = new ThriftTestService.Client(protocol);
System.out.println(client.test("name"));
transport.close(); **/
InMemoryScribe client;
ThriftCodecManager thriftCodecManager = new ThriftCodecManager();
HttpClientConnector connector = new HttpClientConnector(URI.create("http://localhost:" + 8080 +"/scribe"));
ThriftClientManager clientManager = new ThriftClientManager(thriftCodecManager);
client = clientManager.createClient(connector, InMemoryScribe.class).get();
List<LogEntry> msgs = new ArrayList<LogEntry>();
String name = client.log(msgs);
System.out.println("name: "+ name);
}
项目:high
文件:Application.java
@Bean
Servlet thrift(ThriftCodecManager thriftCodecManager, TProtocolFactory protocolFactory, TCalculatorService calculatorService) {
ThriftServiceProcessor processor = new ThriftServiceProcessor(thriftCodecManager, Arrays.<ThriftEventHandler>asList(), calculatorService);
return new TServlet(
NiftyProcessorAdapters.processorToTProcessor(processor),
protocolFactory,
protocolFactory
);
}
项目:hadoop-EAR
文件:TestClientProxyRequests.java
/** Helper verifier */
private <T extends Writable> void verifyStruct(T object) throws Exception {
@SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) object.getClass();
ThriftCodec<T> codec = new ThriftCodecManager().getCodec(clazz);
codec.write(object, protocol);
T thriftCopy = codec.read(protocol);
assertEqualsVerbose(object, thriftCopy);
T writableCopy = WritableUtils.clone(object, new Configuration());
assertEqualsVerbose(object, writableCopy);
}
项目:hadoop-EAR
文件:TestClientProxyResponses.java
/** Helper verifier */
private <T extends Writable> void verifyStruct(T object) throws Exception {
@SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) object.getClass();
ThriftCodec<T> codec = new ThriftCodecManager().getCodec(clazz);
codec.write(object, protocol);
T thriftCopy = codec.read(protocol);
assertEqualsVerbose(object, thriftCopy);
T writableCopy = WritableUtils.clone(object, new Configuration());
assertEqualsVerbose(object, writableCopy);
}
项目:hadoop-EAR
文件:TClientProxyProtocolServer.java
public TClientProxyProtocolServer(ClientProxyCommons commons, ClientProxyService proxyService) {
this.proxyService = proxyService;
ThriftCodecManager codecManager = new ThriftCodecManager();
ThriftEventHandler eventHandler = new ThriftEventHandler();
ThriftServiceProcessor processor = new ThriftServiceProcessor(codecManager, Arrays.asList(
eventHandler), this);
server = new ThriftServer(processor, getServerConfig(commons.conf)).start();
}
项目:mandrel
文件:ThriftTransportService.java
@PostConstruct
public void init() {
ThriftCatalog catalog = new ThriftCatalog();
catalog.addDefaultCoercions(MandrelCoercions.class);
ThriftCodecManager codecManager = new ThriftCodecManager(new CompilerThriftCodecFactory(ThriftCodecManager.class.getClassLoader()), catalog,
ImmutableSet.of());
NiftyProcessor processor = new ThriftServiceProcessor(codecManager,
// Arrays.asList(new ThriftServiceStatsHandler())
ImmutableList.of(), resources);
properties.setPort(transportProperties.getPort());
properties.setBindAddress(transportProperties.getBindAddress());
properties.setWorkerThreads(10);
properties.setTaskExpirationTimeout(Duration.valueOf("10s"));
server = new ThriftServer(processor, properties, new NiftyTimer("thrift"), ThriftServer.DEFAULT_FRAME_CODEC_FACTORIES,
ThriftServer.DEFAULT_PROTOCOL_FACTORIES, ThriftServer.DEFAULT_WORKER_EXECUTORS, ThriftServer.DEFAULT_SECURITY_FACTORY,
transportProperties.isLocal());
server.start();
services.add(new Service() {
@Override
public String getServiceName() {
return ServiceIds.node();
}
});
services.forEach(service -> {
log.debug("Registering service {}", service.getServiceName());
ServiceInstance instance = ServiceInstance.builder().host(transportProperties.getBindAddress()).port(transportProperties.getPort())
.name(service.getServiceName()).build();
discoveryClient.register(instance);
});
Event event = Event.forNode();
event.getNode().setNodeId(discoveryClient.getInstanceId()).setType(NodeEventType.NODE_STARTED);
send(event);
}
项目:mandrel
文件:ThriftClient.java
@PostConstruct
public void init() {
GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
poolConfig.setMaxTotalPerKey(4);
poolConfig.setMinIdlePerKey(1);
ThriftCatalog catalog = new ThriftCatalog();
catalog.addDefaultCoercions(MandrelCoercions.class);
ThriftCodecManager codecManager = new ThriftCodecManager(new CompilerThriftCodecFactory(ThriftCodecManager.class.getClassLoader()), catalog,
Collections.emptySet());
NettyClientConfig config = NettyClientConfig.newBuilder().build();
NiftyClient niftyClient = new NiftyClient(config, transportProperties.isLocal());
ThriftClientManager clientManager = new ThriftClientManager(codecManager, niftyClient, Collections.emptySet());
contracts = Arrays.asList(
// Frontier
FrontierContract.class, AdminFrontierContract.class,
// Coordinator
TimelineContract.class, JobsContract.class, MetricsContract.class, NodesContract.class, AdminCoordinatorContract.class,
// Worker
WorkerContract.class, AdminWorkerContract.class,
// Common
NodeContract.class).stream()
.map(clazz -> Pair.of(clazz, prepare(new KeyedClientPool<>(clazz, poolConfig, 9090, null, clientManager, transportProperties.isLocal()))))
.collect(Collectors.toMap(pair -> pair.getLeft(), pair -> pair.getRight()));
}
项目:mandrel
文件:ThriftClientManager.java
private ThriftClientMetadata(Class<?> clientType, String clientName, ThriftCodecManager codecManager) {
Preconditions.checkNotNull(clientType, "clientType is null");
Preconditions.checkNotNull(clientName, "clientName is null");
Preconditions.checkNotNull(codecManager, "codecManager is null");
this.clientName = clientName;
thriftServiceMetadata = new ThriftServiceMetadata(clientType, codecManager.getCatalog());
this.clientType = thriftServiceMetadata.getName();
ImmutableMap.Builder<Method, ThriftMethodHandler> methods = ImmutableMap.builder();
for (ThriftMethodMetadata methodMetadata : thriftServiceMetadata.getMethods().values()) {
ThriftMethodHandler methodHandler = new ThriftMethodHandler(methodMetadata, codecManager);
methods.put(methodMetadata.getMethod(), methodHandler);
}
methodHandlers = methods.build();
}
项目:high
文件:Server.java
public static void startServer() {
// Create the handler
//ThriftTestService.Iface serviceInterface =
// MyService.Iface serviceInterface = new MyServiceHandler();
// Create the processor
//TProcessor processor = new MyService.Processor<>(serviceInterface);
// Create the processor
//TProcessor processor = new ThriftTestService.Processor<>(new InMemoryScribe());
InMemoryScribe inMemoryScribe = new InMemoryScribeImpl();
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
ThriftCodecManager thriftCodecManager = new ThriftCodecManager();
List list = new ArrayList<>();
list.add(inMemoryScribe);
ThriftServiceProcessor processor = new ThriftServiceProcessor(thriftCodecManager, Arrays.<ThriftEventHandler>asList(), inMemoryScribe);
// Build the server definition
ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)
.build();
// Create the server transport
final NettyServerTransport server = new NettyServerTransport(serverDef );
// Create netty boss and executor thread pools
ExecutorService bossExecutor = Executors.newCachedThreadPool();
ExecutorService workerExecutor = Executors.newCachedThreadPool();
// Start the server
//server.start(bossExecutor, workerExecutor);
server.start();
// Arrange to stop the server at shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
server.stop();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
}
项目:high
文件:Application.java
@Bean
ThriftCodecManager thriftCodecManager() {
return new ThriftCodecManager();
}
项目:high
文件:ThApp.java
public static void main(String[] args) {
ThriftServiceProcessor processor = new ThriftServiceProcessor(
new ThriftCodecManager(),
ImmutableList.<ThriftEventHandler>of(),
new ThirdPartyCollectionServiceImpl()
);
// Build the server definition
ThriftServerDef serverDef = new ThriftServerDefBuilder()
.listen(8899)
.withProcessor(processor)
.build();
// Create the server transport
final NettyServerTransport server = new NettyServerTransport(serverDef );
// Create netty boss and executor thread pools
ExecutorService bossExecutor = Executors.newCachedThreadPool();
ExecutorService workerExecutor = Executors.newCachedThreadPool();
// Start the server
//server.start(bossExecutor, workerExecutor);
server.start();
// Arrange to stop the server at shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
server.stop();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
/**ThreadPool taskWorkerExecutor = newFixedThreadPool(1);
ThriftServerDef serverDef = ThriftServerDef.newBuilder()
.listen(8899)
.withProcessor(processor)
.using(taskWorkerExecutor)
.build();
bossExecutor = newCachedThreadPool();
ioWorkerExecutor = newCachedThreadPool();
NettyServerConfig serverConfig = NettyServerConfig.newBuilder()
.setBossThreadExecutor(bossExecutor)
.setWorkerThreadExecutor(ioWorkerExecutor)
.build();
server = new ThriftServer(serverConfig, serverDef);
server.start();**/
}
项目:zipkin
文件:ScribeCollector.java
ScribeCollector(Builder builder) {
ScribeSpanConsumer scribe = new ScribeSpanConsumer(builder);
ThriftServiceProcessor processor =
new ThriftServiceProcessor(new ThriftCodecManager(), emptyList(), scribe);
server = new ThriftServer(processor, new ThriftServerConfig().setPort(builder.port));
}
项目:mandrel
文件:ThriftClientManager.java
public ThriftClientManager() {
this(new ThriftCodecManager());
}
项目:mandrel
文件:ThriftClientManager.java
public ThriftClientManager(ClassLoader parent) {
this(new ThriftCodecManager(parent));
}
项目:mandrel
文件:ThriftClientManager.java
public ThriftClientManager(ThriftCodecManager codecManager) {
this(codecManager, new NiftyClient(), ImmutableSet.<ThriftClientEventHandler> of());
}
项目:mandrel
文件:ThriftClientManager.java
@Inject
public ThriftClientManager(ThriftCodecManager codecManager, NiftyClient niftyClient, Set<ThriftClientEventHandler> globalEventHandlers) {
this.codecManager = checkNotNull(codecManager, "codecManager is null");
this.niftyClient = checkNotNull(niftyClient, "niftyClient is null");
this.globalEventHandlers = checkNotNull(globalEventHandlers, "globalEventHandlers is null");
}