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


Java TSocket.setTimeout方法代碼示例

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


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

示例1: createNativeTransport

import org.apache.thrift.transport.TSocket; //導入方法依賴的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

示例2: CassandraConnection

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
/**
 * Construct an CassandaraConnection with optional authentication.
 * 
 * @param host the host to connect to
 * @param port the port to use
 * @param username the username to authenticate with (may be null
 * for no authentication)
 * @param password the password to authenticate with (may be null
 * for no authentication)
 * @throws Exception if the connection fails
 */
public CassandraConnection(String host, int port,
    String username, String password, int timeout) throws Exception {
  TSocket socket = new TSocket(host, port);
  if (timeout > 0) {
    socket.setTimeout(timeout);
  }
  
  m_transport = new TFramedTransport(socket);
  TProtocol protocol = new TBinaryProtocol(m_transport);
  m_client = new Cassandra.Client(protocol);      
  m_transport.open();
  
  if (!Const.isEmpty(username) && !Const.isEmpty(password)) {
    Map<String, String> creds = new HashMap<String, String>();
    creds.put("username", username);
    creds.put("password", password);
    m_client.login(new AuthenticationRequest(creds));
  }
}
 
開發者ID:javachen,項目名稱:learning-hadoop,代碼行數:31,代碼來源:CassandraConnection.java

示例3: makeObject

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
@Override
public PooledObject<TTransport> makeObject(ThriftServer thriftServer) throws Exception {
	TSocket tsocket = new TSocket(thriftServer.getHost(), thriftServer.getPort());
	tsocket.setTimeout(timeout);
	TFramedTransport transport = new TFramedTransport(tsocket);
	
	transport.open();
	DefaultPooledObject<TTransport> result = new DefaultPooledObject<TTransport>(transport);
	logger.trace("Make new thrift connection: {}:{}", thriftServer.getHost(), thriftServer.getPort());
	
	return result;
}
 
開發者ID:cyfonly,項目名稱:ThriftJ,代碼行數:13,代碼來源:ThriftConnectionFactory.java

示例4: NaviScribeDriver

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
public NaviScribeDriver(ServerUrlUtil.ServerUrl server, String auth, NaviPoolConfig poolConfig) throws TTransportException,
    UnknownHostException, IOException {
    super(server, auth, poolConfig);

    TSocket sock = new TSocket(new Socket(server.getHost(),
        server.getPort()));
    sock.setTimeout(poolConfig.getConnectTimeout());
    TFramedTransport transport = new TFramedTransport(sock);
    TBinaryProtocol protocol = new TBinaryProtocol(transport, false, false);
    client = new Client(protocol, protocol);
}
 
開發者ID:sunguangran,項目名稱:navi,代碼行數:12,代碼來源:NaviScribeDriver.java

示例5: reconnect

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
public synchronized void reconnect() {
    close();
    try {
        TSocket socket = new TSocket(host, port);
        if (timeout != null) {
            socket.setTimeout(timeout);
        } else {
            // @@@ Todo
            // set the socket default Timeout as xxxx
        }

        // locate login configuration
        Configuration login_conf = AuthUtils.GetConfiguration(conf);

        // construct a transport plugin
        ITransportPlugin transportPlugin = AuthUtils.GetTransportPlugin(type, conf, login_conf);

        final TTransport underlyingTransport = socket;

        // TODO get this from type instead of hardcoding to Nimbus.
        // establish client-server transport via plugin
        // do retries if the connect fails
        TBackoffConnect connectionRetry =
                new TBackoffConnect(Utils.getInt(conf.get(Config.STORM_NIMBUS_RETRY_TIMES)), Utils.getInt(conf.get(Config.STORM_NIMBUS_RETRY_INTERVAL)),
                        Utils.getInt(conf.get(Config.STORM_NIMBUS_RETRY_INTERVAL_CEILING)));
        _transport = connectionRetry.doConnectWithRetry(transportPlugin, underlyingTransport, host, asUser);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    _protocol = null;
    if (_transport != null) {
        _protocol = new TBinaryProtocol(_transport);
    }
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:35,代碼來源:ThriftClient.java

示例6: waitAndReconnect

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
/**
 * Sleeps for retrySleepMs_ and reconnects to the worker. Returns
 * true if the connection was established.
 * TODO: why does this behave so differently than the Planner implementation.
 */
private boolean waitAndReconnect() {
  sleepForRetry();
  try {
    protocol_.getTransport().open();
    TSocket socket = ThriftUtils.getSocketTransport(protocol_.getTransport());
    socket.setTimeout(connectionTimeoutMs_);
    workerClient_ = new RecordServiceWorker.Client(protocol_);
    socket.setTimeout(rpcTimeoutMs_);
    return true;
  } catch (TTransportException e) {
    return false;
  }
}
 
開發者ID:cloudera,項目名稱:RecordServiceClient,代碼行數:19,代碼來源:RecordServiceWorkerClient.java

示例7: ThriftClient

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
public ThriftClient(Map storm_conf, String host, int port, Integer timeout) throws TTransportException {
    try {
        //locate login configuration 
        Configuration login_conf = AuthUtils.GetConfiguration(storm_conf);

        //construct a transport plugin
        ITransportPlugin  transportPlugin = AuthUtils.GetTransportPlugin(storm_conf, login_conf);

        //create a socket with server
        if(host==null) {
            throw new IllegalArgumentException("host is not set");
        }
        if(port<=0) {
            throw new IllegalArgumentException("invalid port: "+port);
        }            
        TSocket socket = new TSocket(host, port);
        if(timeout!=null) {
            socket.setTimeout(timeout);
        }
        final TTransport underlyingTransport = socket;

        //establish client-server transport via plugin
        _transport =  transportPlugin.connect(underlyingTransport, host); 
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    _protocol = null;
    if (_transport != null)
        _protocol = new  TBinaryProtocol(_transport);
}
 
開發者ID:metamx,項目名稱:incubator-storm,代碼行數:31,代碼來源:ThriftClient.java

示例8: connect

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
private void connect() throws TException {
    TSocket socket = new TSocket(host, port);
    if(timeout!=null) {
        socket.setTimeout(timeout);
    }
    conn = new TFramedTransport(socket);
    client = new DistributedRPC.Client(new TBinaryProtocol(conn));
    conn.open();
}
 
開發者ID:metamx,項目名稱:incubator-storm,代碼行數:10,代碼來源:DRPCClient.java

示例9: initializeClientFields

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
protected void initializeClientFields() throws TTransportException {
  final TSocket sock = new TSocket("localhost", LISTEN_PORT);
  // arbitrary
  sock.setTimeout(100 * 1000);
  this.xport = new TFramedTransport(sock);
  this.xport.open();
  // no idea if below is best - stolen from accumulo
  // when my old method didn't work.
  final TProtocol protocol = new TCompactProtocol.Factory().getProtocol(this.xport);
  this.protocol = protocol;
}
 
開發者ID:hltcoe,項目名稱:concrete-java,代碼行數:12,代碼來源:AbstractServiceTest.java

示例10: connect

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
public synchronized boolean connect(String bgpHost, int bgpPort) {
    String msgPiece = "BGP config server at " + bgpHost + ":" + bgpPort;

    if (!BgpConfigurationManager.isValidConfigBgpHostPort(bgpHost, bgpPort)) {
        LOG.error("Invalid config server host: {}, port: {}", bgpHost, bgpPort);
        return false;
    }

    final int numberOfConnectRetries = 180;
    configServerUpdated = false;
    RetryOnException connectRetry = new RetryOnException(numberOfConnectRetries);

    disconnect();
    setConnectTS(System.currentTimeMillis());
    do {
        if (!isBGPEntityOwner.getAsBoolean()) {
            LOG.error("Non Entity BGP owner trying to connect to thrift. Returning");
            isConnected = false;
            return false;
        }
        if (configServerUpdated) {
            LOG.error("Config server updated while connecting to server {} {}", bgpHost, bgpPort);
            isConnected = false;
            return false;
        }
        try {
            LOG.error("Trying to connect BGP config server at {} : {}", bgpHost, bgpPort);
            TSocket ts = new TSocket(bgpHost, bgpPort, CONNECTION_TIMEOUT);
            transport = ts;
            transport.open();
            ts.setTimeout(THRIFT_TIMEOUT_MILLI);
            isConnected = true;
            setLastConnectedTS(System.currentTimeMillis());
            LOG.error("Connected to BGP config server at {} : {}", bgpHost, bgpPort);
            break;
        } catch (TTransportException tte) {
            LOG.debug("Failed connecting to BGP config server at {} : {}. msg: {}; Exception :",
                    bgpHost, bgpPort, msgPiece, tte);
            if (tte.getCause() instanceof ConnectException) {
                LOG.debug("Connect exception. Failed connecting to BGP config server at {} : {}. "
                        + "msg: {}; Exception :", bgpHost, bgpPort, msgPiece, tte);
                connectRetry.errorOccured();
            } else {
                //In Case of other exceptions we try only 3 times
                connectRetry.errorOccured(60);
            }
        }
    } while (connectRetry.shouldRetry());

    if (!connectRetry.shouldRetry()) {
        isConnected = false;
        return false;
    }

    bgpClient = new BgpConfigurator.Client(new TBinaryProtocol(transport));
    LOG.info("Connected to " + msgPiece);
    return true;
}
 
開發者ID:opendaylight,項目名稱:netvirt,代碼行數:59,代碼來源:BgpRouter.java

示例11: DefaultThriftConnectionPoolImpl

import org.apache.thrift.transport.TSocket; //導入方法依賴的package包/類
/**
 * <p>
 * Constructor for DefaultThriftConnectionPoolImpl.
 * </p>
 *
 * @param config a
 *        {@link org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig}
 *        object.
 */
public DefaultThriftConnectionPoolImpl(GenericKeyedObjectPoolConfig config) {
    this(config, info -> {
        TSocket tsocket = new TSocket(info.getHost(), info.getPort());
        tsocket.setTimeout(TIMEOUT);
        return new TFramedTransport(tsocket);
    });
}
 
開發者ID:ngayngo9x,項目名稱:q-thrift,代碼行數:17,代碼來源:DefaultThriftConnectionPoolImpl.java


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