本文整理匯總了Java中org.apache.thrift.transport.TSocket類的典型用法代碼示例。如果您正苦於以下問題:Java TSocket類的具體用法?Java TSocket怎麽用?Java TSocket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TSocket類屬於org.apache.thrift.transport包,在下文中一共展示了TSocket類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
示例2: logThrift
import org.apache.thrift.transport.TSocket; //導入依賴的package包/類
private static int logThrift(HostAndPort address, List<LogEntry> messages)
{
try {
TSocket socket = new TSocket(address.getHost(), address.getPort());
socket.open();
try {
TBinaryProtocol tp = new TBinaryProtocol(new TFramedTransport(socket));
assertEquals(new scribe.Client(tp).Log(messages), ResultCode.OK);
}
finally {
socket.close();
}
}
catch (TException e) {
throw new RuntimeException(e);
}
return 1;
}
示例3: createClientSocket
import org.apache.thrift.transport.TSocket; //導入依賴的package包/類
private static TSocket createClientSocket(boolean secure, HostAndPort address)
throws TTransportException
{
if (!secure) {
return new TSocket(address.getHost(), address.getPort());
}
try {
SSLContext serverSslContext = ClientTestUtils.getClientSslContext();
SSLSocket clientSocket = (SSLSocket) serverSslContext.getSocketFactory().createSocket(address.getHost(), address.getPort());
// clientSocket.setSoTimeout(timeout);
return new TSocket(clientSocket);
}
catch (Exception e) {
throw new TTransportException("Error initializing secure socket", e);
}
}
示例4: createSSLSocket
import org.apache.thrift.transport.TSocket; //導入依賴的package包/類
private static TSocket createSSLSocket(SSLSocketFactory factory, String host,
int port, int timeout, List<String> excludeProtocols)
throws FlumeException {
try {
SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
socket.setSoTimeout(timeout);
List<String> enabledProtocols = new ArrayList<String>();
for (String protocol : socket.getEnabledProtocols()) {
if (!excludeProtocols.contains(protocol)) {
enabledProtocols.add(protocol);
}
}
socket.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
return new TSocket(socket);
} catch (Exception e) {
throw new FlumeException("Could not connect to " + host + " on port " + port, e);
}
}
示例5: testScribeMessage
import org.apache.thrift.transport.TSocket; //導入依賴的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();
}
示例6: load
import org.apache.thrift.transport.TSocket; //導入依賴的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);
}
示例7: startClient
import org.apache.thrift.transport.TSocket; //導入依賴的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();
}
示例8: startClient2
import org.apache.thrift.transport.TSocket; //導入依賴的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();
}
示例9: makeObject
import org.apache.thrift.transport.TSocket; //導入依賴的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;
}
示例10: makeObject
import org.apache.thrift.transport.TSocket; //導入依賴的package包/類
@Override
public TServiceClient makeObject() throws Exception {
TSocket tsocket = new TSocket(server.getHost(), server.getPort());
tsocket.open();
// TTransport transport = new TFramedTransport(tsocket);
TJSONProtocol protocol = new TJSONProtocol(tsocket);
TMultiplexedProtocol uProtocol=new TMultiplexedProtocol(protocol, proccessName);
TServiceClient client = this.clientFactory.getClient(uProtocol);
if (callback != null) {
try {
callback.make(client);
} catch (Exception e) {
logger.warn("makeObject:{}", e);
}
}
return client;
}
示例11: createContext
import org.apache.thrift.transport.TSocket; //導入依賴的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;
}
示例12: thriftTest
import org.apache.thrift.transport.TSocket; //導入依賴的package包/類
@Test
public void thriftTest() throws TException {
TSocket transport = new TSocket("127.0.0.1", 8080);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
TMultiplexedProtocol mp1 = new TMultiplexedProtocol(protocol,"helloWorld");
HelloWorld.Client client = new HelloWorld.Client(mp1);
User user = new User();
user.setName("{\"proid\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}");
user.setId(234242453);
user.setIsman(true);
Result result = client.createNewBaseResInfo(user);
Assert.notNull(result);
System.out.println(result.getMsg());
System.out.println("end>>>>>>>>>>>>>>>>");
}
示例13: Worker
import org.apache.thrift.transport.TSocket; //導入依賴的package包/類
public Worker(int id, long durationMillis, String path, int globals) throws IOException {
this.id = id;
this.workerDuration = durationMillis;
this.localPath = path + "/f" + Integer.toString(id);
this.globalPath = "/f" + Integer.toString(id);
this.instanceMap = new HashMap<>();
this.globals = globals;
String replicaHost = replicaAddr.split(":")[0];
int replicaPort = Integer.parseInt(replicaAddr.split(":")[1]);
TTransport transport = new TSocket(replicaHost, replicaPort);
try {
transport.open();
} catch (TTransportException e) {
throw new RuntimeException(e);
}
TProtocol protocol = new TBinaryProtocol(transport);
c = new FuseOps.Client(protocol);
out = new BufferedWriter(new FileWriter(new File(logPrefix + this.id)));
}
示例14: Worker
import org.apache.thrift.transport.TSocket; //導入依賴的package包/類
public Worker(int id, long durationMillis, String path, int globals) throws IOException {
this.id = id;
this.workerDuration = durationMillis;
this.path = path;
this.globals = globals;
String replicaHost = replicaAddr.split(":")[0];
int replicaPort = Integer.parseInt(replicaAddr.split(":")[1]);
TTransport transport = new TSocket(replicaHost, replicaPort);
try {
transport.open();
} catch (TTransportException e) {
throw new RuntimeException(e);
}
TProtocol protocol = new TBinaryProtocol(transport);
c = new FuseOps.Client(protocol);
out = new BufferedWriter(new FileWriter(new File(logPrefix + this.id)));
}
示例15: Worker
import org.apache.thrift.transport.TSocket; //導入依賴的package包/類
public Worker(int id, String path) throws IOException {
this.id = id;
this.path = path;
this.localPath = path + "/f" + Integer.toString(id);
this.globalPath = "/f" + Integer.toString(id);
this.instanceMap = new HashMap<>();
String replicaHost = replicaAddr.split(":")[0];
int replicaPort = Integer.parseInt(replicaAddr.split(":")[1]);
TTransport transport = new TSocket(replicaHost, replicaPort);
try {
transport.open();
} catch (TTransportException e) {
throw new RuntimeException(e);
}
TProtocol protocol = new TBinaryProtocol(transport);
c = new FuseOps.Client(protocol);
}