List of usage examples for org.apache.thrift.transport TTransportFactory TTransportFactory
TTransportFactory
From source file:com.baifendian.swordfish.execserver.ExecThriftServer.java
License:Apache License
/** * @throws UnknownHostException/*from www.j a va 2s . co m*/ * @throws TTransportException */ public void run() throws UnknownHostException, TTransportException, InterruptedException { HdfsClient.init(ConfigurationUtil.getConfiguration()); logger.info("register to master {}:{}", masterServer.getHost(), masterServer.getPort()); // master boolean ret = masterClient.registerExecutor(host, port, System.currentTimeMillis()); if (!ret) { // ?, ? Thread.sleep(3000); ret = masterClient.registerExecutor(host, port, System.currentTimeMillis()); if (!ret) { logger.error("register to master {}:{} failed", masterServer.getHost(), masterServer.getPort()); throw new RuntimeException("register executor error"); } } // heartBeatInterval = conf.getInt(Constants.EXECUTOR_HEARTBEAT_INTERVAL, Constants.defaultExecutorHeartbeatInterval); heartbeatExecutorService = Executors.newScheduledThreadPool(Constants.defaultExecutorHeartbeatThreadNum); Runnable heartBeatThread = getHeartBeatThread(); heartbeatExecutorService.scheduleAtFixedRate(heartBeatThread, 10, heartBeatInterval, TimeUnit.SECONDS); // ? worker service TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); TTransportFactory tTransportFactory = new TTransportFactory(); workerService = new ExecServiceImpl(host, port, conf); TProcessor tProcessor = new WorkerService.Processor(workerService); inetSocketAddress = new InetSocketAddress(host, port); server = getTThreadPoolServer(protocolFactory, tProcessor, tTransportFactory, inetSocketAddress, Constants.defaultServerMinNum, Constants.defaultServerMaxNum); logger.info("start thrift server on port:{}", port); // daemon, ?? Thread serverThread = new TServerThread(server); serverThread.setDaemon(true); serverThread.start(); // ?, ?? Runtime.getRuntime().addShutdownHook(new Thread(() -> { postProcess(); logger.info("exec server stop"); })); synchronized (this) { // while (running.get()) { try { logger.info("wait...................."); wait(); } catch (InterruptedException e) { logger.error("error", e); } } postProcess(); logger.info("exec server stop"); } }
From source file:com.baifendian.swordfish.masterserver.MasterThriftServer.java
License:Apache License
/** * ?//from w w w .j ava 2 s . co m * * @throws MasterException * @throws TTransportException */ private void init() throws MasterException, TTransportException { masterService = new MasterServiceImpl(); TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); TTransportFactory tTransportFactory = new TTransportFactory(); TProcessor tProcessor = new MasterService.Processor(masterService); InetSocketAddress inetSocketAddress = new InetSocketAddress(host, port); server = ThriftUtil.getTThreadPoolServer(protocolFactory, tProcessor, tTransportFactory, inetSocketAddress, MasterConfig.masterMinThreads, MasterConfig.masterMaxThreads); logger.info("start thrift server on port: {}", port); }
From source file:com.bigdata.dastor.thrift.server.DastorMain.java
License:Apache License
private void setup() throws IOException, TTransportException { // BIGDATA add a configurable switch. if (DatabaseDescriptor.isTryLockMemoryEnabled()) { CLibrary.tryMlockall();/* ww w. j a v a 2 s . c o m*/ } // log4j String file = System.getProperty("bigdata.conf.dir") + File.separator + "log4j.properties"; PropertyConfigurator.configure(file); int listenPort = DatabaseDescriptor.getThriftPort(); InetAddress listenAddr = DatabaseDescriptor.getThriftAddress(); /* * If ThriftAddress was left completely unconfigured, then assume * the same default as ListenAddress */ if (listenAddr == null) listenAddr = FBUtilities.getLocalAddress(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { logger.error("Uncaught exception in thread " + t, e); if (e instanceof OutOfMemoryError) { System.exit(100); } } }); // check the system table for mismatched partitioner. try { SystemTable.checkHealth(); } catch (IOException e) { logger.error("Fatal exception during initialization", e); System.exit(100); } // initialize keyspaces for (String table : DatabaseDescriptor.getTables()) { if (logger.isDebugEnabled()) logger.debug("opening keyspace " + table); Table.open(table); } // replay the log if necessary and check for compaction candidates CommitLog.recover(); CompactionManager.instance.checkAllColumnFamilies(); // start server internals try { StorageService.instance.initServer(); } catch (ConfigurationException e) { logger.error("Fatal error: " + e.getMessage()); System.err.println("Bad configuration; unable to start server"); System.exit(1); } // BIGDATA: init storage proxy StorageProxy.init(); // now we start listening for clients final DastorThriftServer dastorServer = new DastorThriftServer(); Dastor.Processor processor = new Dastor.Processor(dastorServer); // Transport TServerSocket tServerSocket = new TServerSocket(new InetSocketAddress(listenAddr, listenPort)); // BIGDATA: logger.info(String.format("Starting up thrift server @ %s:%s", listenAddr, listenPort)); // Protocol factory TProtocolFactory tProtocolFactory = new TBinaryProtocol.Factory(); // Transport factory TTransportFactory inTransportFactory, outTransportFactory; if (DatabaseDescriptor.isThriftFramed()) { inTransportFactory = new TFramedTransport.Factory(); outTransportFactory = new TFramedTransport.Factory(); } else { inTransportFactory = new TTransportFactory(); outTransportFactory = new TTransportFactory(); } // ThreadPool Server CustomTThreadPoolServer.Options options = new CustomTThreadPoolServer.Options(); options.minWorkerThreads = 64; SynchronousQueue<Runnable> executorQueue = new SynchronousQueue<Runnable>(); ExecutorService executorService = new ThreadPoolExecutor(options.minWorkerThreads, options.maxWorkerThreads, 60, TimeUnit.SECONDS, executorQueue) { @Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); dastorServer.logout(); } }; serverEngine = new CustomTThreadPoolServer(new TProcessorFactory(processor), tServerSocket, inTransportFactory, outTransportFactory, tProtocolFactory, tProtocolFactory, options, executorService); }
From source file:com.cloudera.beeswax.Server.java
License:Apache License
/** * Start the Beeswax server.//from w w w . ja va 2 s . c o m */ private static void serveBeeswax(int port) throws TTransportException { TServerTransport serverTransport = new TServerSocket(port); BeeswaxService.Iface impl = new BeeswaxServiceImpl(dtHost, dtPort, dtHttps, qlifetime); Processor processor = new BeeswaxService.Processor(impl); TTransportFactory transFactory; if (useKerberos) { final String names[] = SaslRpcServer.splitKerberosName(kerberosName); if (names.length < 2) { throw new IllegalArgumentException( "Kerberos principal should have at least 2 parts: " + kerberosName); } TSaslServerTransport.Factory saslFactory = new TSaslServerTransport.Factory( AuthMethod.KERBEROS.getMechanismName(), names[0], names[1], // two parts of kerberos principal SaslRpcServer.SASL_PROPS, new SaslRpcServer.SaslGssCallbackHandler()); transFactory = new KbrSaslTransportFactory(saslFactory, bwUgi); } else { transFactory = new TTransportFactory(); } TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport).processor(processor) .protocolFactory(new TBinaryProtocol.Factory()).transportFactory(transFactory); TServer server = new TThreadPoolServer(args); if (dtPort != -1) { LOG.info("Starting beeswax server on port " + port + ", talking back to Desktop at " + dtHost + ":" + dtPort); } else { LOG.info("Starting beeswax server on port " + port); } server.serve(); }
From source file:com.cloudera.beeswax.Server.java
License:Apache License
/** * Start the thrift metastore server./*from w w w.j ava2 s . c o m*/ * * Mostly borrowed from org.apache.hadoop.hive.metastore.HiveMetaStore. */ public static void serveMeta(int port) throws MetaException, TTransportException { // Verify that we're supposed to run an internal metastore. HiveConf conf = new HiveConf(Driver.class); if (!conf.getBoolean("hive.metastore.local", true)) { String msg = "hive.metastore.local is set to false. The Beeswax internal metastore " + "is not supposed to run."; LOG.fatal(msg); System.exit(1); } TServerTransport serverTransport = new TServerSocket(port); Iface handler = new HMSHandler("new db based metaserver"); FacebookService.Processor processor = new ThriftHiveMetastore.Processor(handler); TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport).processor(processor) .protocolFactory(new TBinaryProtocol.Factory()).transportFactory(new TTransportFactory()); TServer server = new TThreadPoolServer(args); HMSHandler.LOG.info("Started the new metaserver on port [" + port + "]..."); HMSHandler.LOG.info("minWorkerThreads = " + args.minWorkerThreads); HMSHandler.LOG.info("maxWorkerThreads = " + args.maxWorkerThreads); server.serve(); }
From source file:com.cloudera.llama.server.ThriftEndPoint.java
License:Apache License
public static TTransportFactory createTTransportFactory(ServerConfiguration conf) { TTransportFactory factory;//from w w w . ja v a 2 s .co m if (Security.isSecure(conf)) { Map<String, String> saslProperties = new HashMap<String, String>(); saslProperties.put(Sasl.QOP, conf.getThriftQOP()); String principal = conf.getServerPrincipalName(); String name = extractPrincipalName(principal); String host = extractPrincipalHost(principal); if (host == null) { throw new IllegalArgumentException( FastFormat.format("Kerberos principal '{}' must have a hostname part", principal)); } TSaslServerTransport.Factory saslFactory = new TSaslServerTransport.Factory(); saslFactory.addServerDefinition("GSSAPI", name, host, saslProperties, new GssCallback()); factory = saslFactory; } else { factory = new TTransportFactory(); } return factory; }
From source file:com.facebook.infrastructure.service.CassandraServer.java
License:Apache License
private static TThreadPoolServer thriftEngine(CassandraServer server) throws TTransportException { Cassandra.Processor processor = new Cassandra.Processor(server); // Transport//from www . j a va 2s . c o m TServerSocket tServerSocket = new TServerSocket(9160); // Protocol factory TProtocolFactory tProtocolFactory = new TBinaryProtocol.Factory(); // ThreadPool Server TThreadPoolServer.Options options = new TThreadPoolServer.Options(); options.minWorkerThreads = 64; return new TThreadPoolServer(new TProcessorFactory(processor), tServerSocket, new TTransportFactory(), new TTransportFactory(), tProtocolFactory, tProtocolFactory, options); }
From source file:com.tna.cep.service.thrift.flume.TSaneThreadPoolServer.java
License:Apache License
/** * Commonly used constructor.//from w w w . j av a 2 s . c om **/ public TSaneThreadPoolServer(TProcessor processor, TServerTransport serverTransport, TProtocolFactory protocolFactory) { this(new TProcessorFactory(processor), serverTransport, new TTransportFactory(), new TTransportFactory(), protocolFactory, protocolFactory); }
From source file:com.uber.hoodie.hive.util.HiveTestService.java
License:Apache License
public TServer startMetaStore(String forceBindIP, int port, HiveConf conf) throws IOException { try {//from ww w. j a v a 2s . c om // Server will create new threads up to max as necessary. After an idle // period, it will destory threads to keep the number of threads in the // pool to min. int minWorkerThreads = conf.getIntVar(HiveConf.ConfVars.METASTORESERVERMINTHREADS); int maxWorkerThreads = conf.getIntVar(HiveConf.ConfVars.METASTORESERVERMAXTHREADS); boolean tcpKeepAlive = conf.getBoolVar(HiveConf.ConfVars.METASTORE_TCP_KEEP_ALIVE); boolean useFramedTransport = conf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_FRAMED_TRANSPORT); // don't support SASL yet //boolean useSasl = conf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL); TServerTransport serverTransport; if (forceBindIP != null) { InetSocketAddress address = new InetSocketAddress(forceBindIP, port); serverTransport = tcpKeepAlive ? new TServerSocketKeepAlive(address) : new TServerSocket(address); } else { serverTransport = tcpKeepAlive ? new TServerSocketKeepAlive(port) : new TServerSocket(port); } TProcessor processor; TTransportFactory transFactory; IHMSHandler handler = (IHMSHandler) HiveMetaStore.newRetryingHMSHandler("new db based metaserver", conf, true); if (conf.getBoolVar(HiveConf.ConfVars.METASTORE_EXECUTE_SET_UGI)) { transFactory = useFramedTransport ? new ChainedTTransportFactory(new TFramedTransport.Factory(), new TUGIContainingTransport.Factory()) : new TUGIContainingTransport.Factory(); processor = new TUGIBasedProcessor<IHMSHandler>(handler); LOG.info("Starting DB backed MetaStore Server with SetUGI enabled"); } else { transFactory = useFramedTransport ? new TFramedTransport.Factory() : new TTransportFactory(); processor = new TSetIpAddressProcessor<IHMSHandler>(handler); LOG.info("Starting DB backed MetaStore Server"); } TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport).processor(processor) .transportFactory(transFactory).protocolFactory(new TBinaryProtocol.Factory()) .minWorkerThreads(minWorkerThreads).maxWorkerThreads(maxWorkerThreads); final TServer tServer = new TThreadPoolServer(args); executorService.submit(new Runnable() { @Override public void run() { tServer.serve(); } }); return tServer; } catch (Throwable x) { throw new IOException(x); } }
From source file:io.airlift.drift.integration.LegacyApacheThriftTesterUtil.java
License:Apache License
private static int logThrift(HostAndPort address, List<LogEntry> messages, List<MethodInvocationFilter> filters, Transport transportType, Protocol protocolType, boolean secure) { if (!filters.isEmpty()) { return 0; }// w w w . ja va 2s . co m TTransportFactory transportFactory; switch (transportType) { case UNFRAMED: transportFactory = new TTransportFactory(); break; case FRAMED: transportFactory = new TFramedTransport.Factory(); break; case HEADER: return 0; default: throw new IllegalArgumentException("Unsupported transport " + transportType); } try (TSocket socket = createClientSocket(secure, address)) { if (!socket.isOpen()) { socket.open(); } TTransport transport = transportFactory.getTransport(socket); TProtocol protocol; switch (protocolType) { case BINARY: protocol = new TBinaryProtocol(transport); break; case COMPACT: protocol = new TCompactProtocol(transport); break; case FB_COMPACT: return 0; default: throw new IllegalArgumentException("Unsupported protocol " + protocolType); } assertEquals(new scribe.Client(protocol).Log(messages), ResultCode.OK); } catch (TException e) { throw new RuntimeException(e); } return 1; }