本文整理汇总了Java中com.alibaba.dubbo.remoting.Transporters类的典型用法代码示例。如果您正苦于以下问题:Java Transporters类的具体用法?Java Transporters怎么用?Java Transporters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transporters类属于com.alibaba.dubbo.remoting包,在下文中一共展示了Transporters类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: join
import com.alibaba.dubbo.remoting.Transporters; //导入依赖的package包/类
public Peer join(URL url, ChannelHandler handler) throws RemotingException {
Server server = servers.get(url);
if (server == null) { // TODO 有并发间隙
server = Transporters.bind(url, handler);
servers.put(url, server);
dispatcher.addChannelHandler(handler);
}
return new ServerPeer(server, clients, this);
}
示例2: connect
import com.alibaba.dubbo.remoting.Transporters; //导入依赖的package包/类
protected Client connect(URL url) throws RemotingException {
if (servers.containsKey(url)) {
return null;
}
Client client = clients.get(url);
if (client == null) { // TODO 有并发间隙
client = Transporters.connect(url, dispatcher);
clients.put(url, client);
}
return client;
}
示例3: connect
import com.alibaba.dubbo.remoting.Transporters; //导入依赖的package包/类
public ExchangeClient connect(URL url, ExchangeHandler handler) throws RemotingException {
return new HeaderExchangeClient(Transporters.connect(url, new DecodeHandler(new HeaderExchangeHandler(handler))));
}
示例4: bind
import com.alibaba.dubbo.remoting.Transporters; //导入依赖的package包/类
public ExchangeServer bind(URL url, ExchangeHandler handler) throws RemotingException {
return new HeaderExchangeServer(Transporters.bind(url, new DecodeHandler(new HeaderExchangeHandler(handler))));
}
示例5: main
import com.alibaba.dubbo.remoting.Transporters; //导入依赖的package包/类
public static void main( String[] args ) throws Exception {
final HeartBeatExchangeHandler serverHandler = new HeartBeatExchangeHandler( handler );
Thread serverThread = new Thread( new Runnable() {
public void run() {
try {
exchangeServer = new HeaderExchangeServer(
Transporters.bind(
clientUrl.addParameter( Constants.HEARTBEAT_KEY, 1000 ),
serverHandler ) );
serverStarted = true;
} catch ( Exception e ) {
e.printStackTrace();
}
}
} );
serverThread.setDaemon( true );
serverThread.start();
while ( !serverStarted ) {
Thread.sleep( 1000 );
}
HeartBeatExchangeHandler clientHandler = new HeartBeatExchangeHandler( handler );
ExchangeClient exchangeClient = new HeaderExchangeClient(
Transporters.connect( clientUrl, clientHandler ) );
for ( int i = 0; i < 10; i++ ) {
Thread.sleep( 1000 );
System.out.print( "." );
}
System.out.println();
if ( clientHandler.getHeartBeatCount() > 0 ) {
System.out.printf( "Client receives %d heartbeats",
clientHandler.getHeartBeatCount() );
} else {
throw new Exception( "Server heartbeat does not work." );
}
exchangeClient.close();
exchangeServer.close();
}
示例6: main
import com.alibaba.dubbo.remoting.Transporters; //导入依赖的package包/类
public static void main( String[] args ) throws Exception {
final HeartBeatExchangeHandler serverHandler = new HeartBeatExchangeHandler( handler );
Thread serverThread = new Thread( new Runnable() {
public void run() {
try {
exchangeServer = new HeaderExchangeServer(
Transporters.bind( serverUrl, serverHandler ) );
serverStarted = true;
} catch ( Exception e ) {
e.printStackTrace();
}
}
} );
serverThread.setDaemon( true );
serverThread.start();
while ( ! serverStarted ) {
Thread.sleep( 1000 );
}
URL url = serverUrl.addParameter( Constants.HEARTBEAT_KEY, 1000 );
HeartBeatExchangeHandler clientHandler = new HeartBeatExchangeHandler( handler );
ExchangeClient exchangeClient = new HeaderExchangeClient(
Transporters.connect( url, clientHandler ) );
for( int i = 0; i < 10; i++ ) {
Thread.sleep( 1000 );
System.out.print( "." );
}
System.out.println();
if ( serverHandler.getHeartBeatCount() > 0 ) {
System.out.printf( "Server receives %d heartbeats",
serverHandler.getHeartBeatCount() );
} else {
throw new Exception( "Client heartbeat does not work." );
}
exchangeClient.close();
exchangeServer.close();
}