當前位置: 首頁>>代碼示例>>Java>>正文


Java TTransport類代碼示例

本文整理匯總了Java中org.apache.thrift.transport.TTransport的典型用法代碼示例。如果您正苦於以下問題:Java TTransport類的具體用法?Java TTransport怎麽用?Java TTransport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TTransport類屬於org.apache.thrift.transport包,在下文中一共展示了TTransport類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
@Override
public TTransport create(ServiceInstance<RpcPayload> instance)
        throws Exception {
    TTransport transport = this.createNativeTransport(instance);
    try {
        transport.open();
    } catch (TException ex) {
        LOG.warn(
                "Error when creating new transport on server: "
                        + instance.getAddress() + ":" + instance.getPort(),
                ex);
        markError(instance);
        throw ex;
    }
    return new ManagedTransport(transport, instance);
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:17,代碼來源:AbstractTransportPool.java

示例2: createNativeTransport

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
/**
 * 根據rc的設置來確定創建什麽類型的transport;
 *
 * @param instance
 * @return
 */
protected TTransport createNativeTransport(
        ServiceInstance<RpcPayload> instance) {
    TSocket socket = new TSocket(instance.getAddress(), instance.getPort());
    socket.setTimeout(socketTimeout);

    RpcPayload server = instance.getPayload();
    if ((server == null) || (server.getTransport() == null)
            || (server.getTransport().equals("socket"))) {
        return socket;
    } else if ("framed-transport".equals(server.getTransport())) {
        return new TFramedTransport(socket);
    }

    // for default, use TSocket;
    return socket;
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:23,代碼來源:AbstractTransportPool.java

示例3: createModelBridge

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
/**
 * Creates a Model and a Thrift Bridge to this model.
 */
protected static EBMI createModelBridge(String host, String pythonExecutable, File opendaPythonPath, File modelPythonPath,
		String modelPythonModuleName, String modelPythonClassName, File modelRunDir) throws IOException {
	// start local server.
	int port = getFreePort();
	
	if (host == null) {
		//localhost
		host = "127.0.0.1";
	}
	
	Process process = startModelProcess(host, port, pythonExecutable, opendaPythonPath, modelPythonPath,
			modelPythonModuleName, modelPythonClassName, modelRunDir);

	// connect to server.
	TTransport transport = connectToCode(host, port, process);

	// create client.
	TProtocol protocol = new TBinaryProtocol(transport);
	BMIService.Client client = new BMIService.Client(protocol);

	return new ThriftBmiBridge(client, process, transport);
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:26,代碼來源:BmiModelFactory.java

示例4: testScribeMessage

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
@Test
public void testScribeMessage() throws Exception {
  TTransport transport = new TFramedTransport(new TSocket("localhost", port));

  TProtocol protocol = new TBinaryProtocol(transport);
  Scribe.Client client = new Scribe.Client(protocol);
  transport.open();
  LogEntry logEntry = new LogEntry("INFO", "Sending info msg to scribe source");
  List<LogEntry> logEntries = new ArrayList<LogEntry>(1);
  logEntries.add(logEntry);
  client.Log(logEntries);

  // try to get it from Channels
  Transaction tx = memoryChannel.getTransaction();
  tx.begin();
  Event e = memoryChannel.take();
  Assert.assertNotNull(e);
  Assert.assertEquals("Sending info msg to scribe source", new String(e.getBody()));
  tx.commit();
  tx.close();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:TestScribeSource.java

示例5: load

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
@Override
public Pair<TTransport, Bmv2DeviceThriftClient> load(DeviceId deviceId)
        throws TTransportException {
    log.debug("Instantiating new client... > deviceId={}", deviceId);
    // Make the expensive call
    Bmv2Device device = Bmv2Device.of(deviceId);
    TTransport transport = new TSocket(device.thriftServerHost(), device.thriftServerPort());
    TProtocol protocol = new TBinaryProtocol(transport);
    // Our BMv2 device implements multiple Thrift services, create a client for each one on the same transport.
    Standard.Client standardClient = new Standard.Client(
            new TMultiplexedProtocol(protocol, "standard"));
    SimpleSwitch.Client simpleSwitch = new SimpleSwitch.Client(
            new TMultiplexedProtocol(protocol, "simple_switch"));
    // Wrap clients so to automatically have synchronization and resiliency to connectivity errors
    Standard.Iface safeStandardClient = SafeThriftClient.wrap(standardClient,
                                                              Standard.Iface.class,
                                                              options);
    SimpleSwitch.Iface safeSimpleSwitchClient = SafeThriftClient.wrap(simpleSwitch,
                                                                      SimpleSwitch.Iface.class,
                                                                      options);
    Bmv2DeviceThriftClient client = new Bmv2DeviceThriftClient(deviceId,
                                                               transport,
                                                               safeStandardClient,
                                                               safeSimpleSwitchClient);
    return Pair.of(transport, client);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:Bmv2ControllerImpl.java

示例6: validateObject

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
@Override
public boolean validateObject(ThriftServer thriftServer, PooledObject<TTransport> pooledObject) {
	boolean isValidate;
	try {
		if (failoverChecker == null) {
			isValidate = pooledObject.getObject().isOpen();
		} else {
			ConnectionValidator validator = failoverChecker.getConnectionValidator();
			isValidate = pooledObject.getObject().isOpen() && (validator == null || validator.isValid(pooledObject.getObject()));
		}
	} catch (Throwable e) {
		logger.warn("Fail to validate tsocket: {}:{}", new Object[]{thriftServer.getHost(), thriftServer.getPort(), e});
		isValidate = false;
	}
	if (failoverChecker != null && !isValidate) {
		failoverChecker.getFailoverStrategy().fail(thriftServer);
	}
	logger.info("ValidateObject isValidate:{}", isValidate);
	
	return isValidate;
}
 
開發者ID:cyfonly,項目名稱:ThriftJ,代碼行數:22,代碼來源:ThriftConnectionFactory.java

示例7: run

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
@Override
public void run() {
	for (ThriftServer thriftServer : getAvailableServers(true)) {
		TTransport tt = null;
		boolean valid = false;
		try {
			tt = poolProvider.getConnection(thriftServer);
			valid = connectionValidator.isValid(tt);
		} catch (Exception e) {
			valid = false;
			logger.warn(e.getMessage(), e);
		} finally {
			if (tt != null) {
				if (valid) {
					poolProvider.returnConnection(thriftServer, tt);
				} else {
					failoverStrategy.fail(thriftServer);
					poolProvider.returnBrokenConnection(thriftServer, tt);
				}
			} else {
				failoverStrategy.fail(thriftServer);
			}
		}
	}
}
 
開發者ID:cyfonly,項目名稱:ThriftJ,代碼行數:26,代碼來源:FailoverChecker.java

示例8: startClient

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
public static void startClient(String ip ,int port ,int timeout) throws Exception
{
	TTransport transport = new TSocket(ip,port,timeout);
	TProtocol protocol = new TBinaryProtocol(transport);
	leafrpc.Client client = new leafrpc.Client(protocol);
	transport.open();

	int i = 0;
	while(i < 2000000)
	{
		 client.getID("");
		 ++i;
	}

	transport.close();
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:17,代碼來源:rpcClient.java

示例9: startClient2

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
public static void startClient2(String ip ,int port ,int timeout) throws Exception
{
	TTransport transport = new TFramedTransport(new TSocket(ip,port,timeout));
	TProtocol protocol = new TBinaryProtocol(transport);
	leafrpc.Client client = new leafrpc.Client(protocol);
	transport.open();

	for(int i = 0; i< 1000000; i++)
	{
		client.getID("");
		if (i % 100000 == 0)
		{
			System.out.println(Thread.currentThread().getName() + " " + client.getID(""));
		}
		//ai.incrementAndGet();
	}
	transport.close();
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:19,代碼來源:rpcClient.java

示例10: makeObject

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
@Override
public TServiceClient makeObject() throws Exception {
    InetSocketAddress address = serverAddressProvider.selector();
    if(address==null){
        new ThriftException("No provider available for remote service");
    }
    TSocket tsocket = new TSocket(address.getHostName(), address.getPort());
    TTransport transport = new TFramedTransport(tsocket);
    TProtocol protocol = new TBinaryProtocol(transport);
    TServiceClient client = this.clientFactory.getClient(protocol);
    transport.open();
    if (callback != null) {
        try {
            callback.make(client);
        } catch (Exception e) {
            logger.warn("makeObject:{}", e);
        }
    }
    return client;
}
 
開發者ID:somewhereMrli,項目名稱:albedo-thrift,代碼行數:21,代碼來源:ThriftClientPoolFactory.java

示例11: deflateNonNull

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
/**
 * Encodes a thrift object into a DEFLATE-compressed binary array.
 *
 * @param tBase Object to encode.
 * @return Deflated, encoded object.
 * @throws CodingException If the object could not be encoded.
 */
public static byte[] deflateNonNull(TBase<?, ?> tBase) throws CodingException {
  requireNonNull(tBase);

  // NOTE: Buffering is needed here for performance.
  // There are actually 2 buffers in play here - the BufferedOutputStream prevents thrift from
  // causing a call to deflate() on every encoded primitive. The DeflaterOutputStream buffer
  // allows the underlying Deflater to operate on a larger chunk at a time without stopping to
  // copy the intermediate compressed output to outBytes.
  // See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4986239
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  TTransport transport = new TIOStreamTransport(
      new BufferedOutputStream(
          new DeflaterOutputStream(outBytes, new Deflater(DEFLATE_LEVEL), DEFLATER_BUFFER_SIZE),
          DEFLATER_BUFFER_SIZE));
  try {
    TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
    tBase.write(protocol);
    transport.close(); // calls finish() on the underlying stream, completing the compression
    return outBytes.toByteArray();
  } catch (TException e) {
    throw new CodingException("Failed to serialize: " + tBase, e);
  } finally {
    transport.close();
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:33,代碼來源:ThriftBinaryCodec.java

示例12: inflateNonNull

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
/**
 * Decodes a thrift object from a DEFLATE-compressed byte array into a target type.
 *
 * @param clazz Class to instantiate and deserialize to.
 * @param buffer Compressed buffer to decode.
 * @return A populated message.
 * @throws CodingException If the message could not be decoded.
 */
public static <T extends TBase<T, ?>> T inflateNonNull(Class<T> clazz, byte[] buffer)
    throws CodingException {

  requireNonNull(clazz);
  requireNonNull(buffer);

  T tBase = newInstance(clazz);
  TTransport transport = new TIOStreamTransport(
        new InflaterInputStream(new ByteArrayInputStream(buffer)));
  try {
    TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
    tBase.read(protocol);
    return tBase;
  } catch (TException e) {
    throw new CodingException("Failed to deserialize: " + e, e);
  } finally {
    transport.close();
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:28,代碼來源:ThriftBinaryCodec.java

示例13: createContext

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public ServerContext createContext(final TProtocol input, final TProtocol output) {
    final String userName = "metacat-thrift-interface";
    String clientHost = null; //requestContext.getHeaderString("X-Forwarded-For");
    final long requestThreadId = Thread.currentThread().getId();

    final TTransport transport = input.getTransport();
    if (transport instanceof TSocket) {
        final TSocket thriftSocket = (TSocket) transport;
        clientHost = thriftSocket.getSocket().getInetAddress().getHostAddress();
    }

    final CatalogServerRequestContext context = new CatalogServerRequestContext(
        userName,
        null,
        clientHost,
        null,
        "hive",
        requestThreadId
    );
    MetacatContextManager.setContext(context);
    return context;
}
 
開發者ID:Netflix,項目名稱:metacat,代碼行數:27,代碼來源:CatalogThriftEventHandler.java

示例14: ClientProcessData

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
protected ClientProcessData(GfxdTSocket socket, int connectionNumber,
    TProcessor proc, TTransport in, TTransport out, TProtocol inp,
    TProtocol outp, TServerEventHandler eventHandler) {
  this.clientSocket = socket;
  this.connectionNumber = connectionNumber;
  this.processor = proc;
  this.inputTransport = in;
  this.outputTransport = out;
  this.inputProtocol = inp;
  this.outputProtocol = outp;
  this.eventHandler = eventHandler;
  if (eventHandler != null) {
    this.connectionContext = eventHandler.createContext(inp, outp);
  }
  else {
    this.connectionContext = null;
  }
  this.idle = true;
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:20,代碼來源:GfxdThriftServerSelector.java

示例15: requestTransport

import org.apache.thrift.transport.TTransport; //導入依賴的package包/類
protected TProtocol requestTransport(String url) throws TTransportException {

        // probably not thread safe, but we need it? Not atm.

        TTransport act;

        if (!activeTransports.containsKey(url)) {
        	logger.log(Level.DEBUG ,"Creating new transport for: " + url);
            activeTransports.put(url, new THttpClient(url));
        }

        act = activeTransports.get(url);

        if (!act.isOpen()) {
            act.open();
        }
        // THINK: always create new protocol?
        return new TJSONProtocol(act);
    }
 
開發者ID:Ericsson,項目名稱:CodeCheckerEclipsePlugin,代碼行數:20,代碼來源:ThriftTransportFactory.java


注:本文中的org.apache.thrift.transport.TTransport類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。