本文整理匯總了Java中org.apache.mina.core.future.ConnectFuture.getException方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnectFuture.getException方法的具體用法?Java ConnectFuture.getException怎麽用?Java ConnectFuture.getException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.mina.core.future.ConnectFuture
的用法示例。
在下文中一共展示了ConnectFuture.getException方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: retryAttemptListener
import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
/**
* Handles the retry attempts. Listens to see when the ConnectFuture is finished and checks if there was
* an exception thrown. If so, it then attempts a retry if there are more retries.
*
* @param connector
* @param detectFuture
* @param address
* @param retryAttempt
* @return IoFutureListener<ConnectFuture>
*/
private final IoFutureListener<ConnectFuture> retryAttemptListener(final DetectFutureMinaImpl detectFuture, final InetSocketAddress address, final IoSessionInitializer<ConnectFuture> init, final int retryAttempt) {
return new IoFutureListener<ConnectFuture>() {
@Override
public void operationComplete(ConnectFuture future) {
final Throwable cause = future.getException();
if (cause instanceof IOException) {
if(retryAttempt == 0) {
LogUtils.infof(this, "Service %s detected false: %s: %s",getServiceName(), cause.getClass().getName(), cause.getMessage());
detectFuture.setServiceDetected(false);
}else {
LogUtils.infof(this, "Connection exception occurred: %s for service %s, retrying attempt %d", cause, getServiceName(), retryAttempt);
future = m_connectionFactory.reConnect(address, init, createDetectorHandler(detectFuture));
future.addListener(retryAttemptListener(detectFuture, address, init, retryAttempt - 1));
}
}else if(cause instanceof Throwable) {
LogUtils.infof(this, cause, "Threw a Throwable and detection is false for service %s", getServiceName());
detectFuture.setServiceDetected(false);
}
}
};
}
示例2: handleConnectComplete
import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
protected synchronized void handleConnectComplete ( final ConnectFuture future )
{
logger.debug ( "Connection attempt complete: {}", future );
if ( this.connectFuture != future )
{
logger.warn ( "handleConnectComplete got called with wrong future - current: {}, called: {}", this.connectFuture, future );
return;
}
this.connectFuture = null;
final Throwable error = future.getException ();
if ( error != null )
{
setState ( ConnectionState.CLOSED, error );
return;
}
try
{
setSession ( future.getSession () );
}
catch ( final Throwable e )
{
setState ( ConnectionState.CLOSED, e );
}
logger.debug ( "Connection established" );
}
示例3: connect
import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public IoSession connect() throws Exception {
ConnectFuture future = connector.connect(new InetSocketAddress((String)rule.get("ip"), (Integer)rule.get("port")));
future.awaitUninterruptibly();
/*boolean b = future.awaitUninterruptibly(cfg.getConTimeout());
// 若返回值b==true,則表示設置了ConnectFuture的value,即調用了ConnectFuture的setException、setSession或cancel方法
if (!b)
throw new CommunicateException("連接遠程Tcp服務器超時");*/
if (!future.isConnected())
// 即getValue() instanceof IoSession == false,也就是說出現異常或Canceled
throw new Exception("與遠程Tcp服務器建立連接失敗:超時或異常",
future.getException());
return future.getSession();
}
示例4: connect
import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public MessageSession connect(SocketAddress address) throws IOException {
Objects.requireNonNull(address);
// client session
ConnectFuture connectFuture = connector.connect(address);
connectFuture.awaitUninterruptibly();
if (!connectFuture.isConnected() || connectFuture.getException() != null)
throw new IOException("Connection error", connectFuture.getException());
IoSession minaSession = connectFuture.getSession();
return minaAdapter.getMessageSession(minaSession);
}