本文整理汇总了Java中org.apache.mina.common.IoSession.isConnected方法的典型用法代码示例。如果您正苦于以下问题:Java IoSession.isConnected方法的具体用法?Java IoSession.isConnected怎么用?Java IoSession.isConnected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.common.IoSession
的用法示例。
在下文中一共展示了IoSession.isConnected方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOrAddChannel
import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
static MinaChannel getOrAddChannel(IoSession session, URL url, ChannelHandler handler) {
if (session == null) {
return null;
}
MinaChannel ret = (MinaChannel) session.getAttribute(CHANNEL_KEY);
if (ret == null) {
ret = new MinaChannel(session, url, handler);
if (session.isConnected()) {
MinaChannel old = (MinaChannel) session.setAttribute(CHANNEL_KEY, ret);
if (old != null) {
session.setAttribute(CHANNEL_KEY, old);
ret = old;
}
}
}
return ret;
}
示例2: getChannels
import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public Collection<Channel> getChannels() {
Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
Collection<Channel> channels = new HashSet<Channel>();
for (IoSession session : sessions) {
if (session.isConnected()) {
channels.add(MinaChannel.getOrAddChannel(session, getUrl(), this));
}
}
return channels;
}
示例3: getChannel
import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
protected Channel getChannel() {
IoSession s = session;
if (s == null || ! s.isConnected())
return null;
return MinaChannel.getOrAddChannel(s, getUrl(), this);
}
示例4: exceptionCaught
import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public void exceptionCaught(IoSession session, TairClientException exception) {
log.error("do async request failed", exception);
if (session.isConnected()) {
log.error("session closing");
session.close();
}
masterFailCount++;
}
示例5: createClient
import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key) throws Exception {
if (isDebugEnabled) {
LOGGER.debug("create connection to :" + targetIP + ":" + targetPort + ",timeout is:" + connectTimeout + ",key is:" + key);
}
SocketConnectorConfig cfg = new SocketConnectorConfig();
cfg.setThreadModel(ThreadModel.MANUAL);
if (connectTimeout > 1000) {
cfg.setConnectTimeout((int) connectTimeout / 1000);
} else {
cfg.setConnectTimeout(1);
}
cfg.getSessionConfig().setTcpNoDelay(Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")));
cfg.getFilterChain().addLast("objectserialize", new MinaProtocolCodecFilter());
SocketAddress targetAddress = new InetSocketAddress(targetIP, targetPort);
MinaClientProcessor processor = new MinaClientProcessor(this, key);
ConnectFuture connectFuture = ioConnector.connect(targetAddress, null, processor, cfg);
// wait for connection established
connectFuture.join();
IoSession ioSession = connectFuture.getSession();
if ((ioSession == null) || (!ioSession.isConnected())) {
String targetUrl = targetIP + ":" + targetPort;
LOGGER.error("create connection error,targetaddress is " + targetUrl);
throw new Exception("create connection error,targetaddress is " + targetUrl);
}
if (isDebugEnabled) {
LOGGER.debug(
"create connection to :" + targetIP + ":" + targetPort + ",timeout is:" + connectTimeout + ",key is:" + key + " successed");
}
MinaClient client = new MinaClient(ioSession, key, connectTimeout);
processor.setClient(client);
return client;
}
示例6: createClient
import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
private synchronized TairClient createClient(String targetUrl, int connectionTimeout, PacketStreamer pstreamer)
throws Exception {
SocketConnectorConfig cfg = new SocketConnectorConfig();
cfg.setThreadModel(ThreadModel.MANUAL);
if (connectionTimeout < MIN_CONN_TIMEOUT)
connectionTimeout = MIN_CONN_TIMEOUT;
cfg.setConnectTimeout((int) connectionTimeout / 1000);
cfg.getSessionConfig().setTcpNoDelay(true);
cfg.getFilterChain().addLast("objectserialize",
new TairProtocolCodecFilter(pstreamer));
String address = TairUtil.getHost(targetUrl);
int port = TairUtil.getPort(targetUrl);
SocketAddress targetAddress = new InetSocketAddress(address, port);
TairClientProcessor processor = new TairClientProcessor();
ConnectFuture connectFuture = ioConnector.connect(targetAddress, null,
processor, cfg);
connectFuture.join();
IoSession ioSession = connectFuture.getSession();
if ((ioSession == null) || (!ioSession.isConnected())) {
throw new Exception(
"create tair connection error,targetaddress is "
+ targetUrl);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("create tair connection success,targetaddress is "
+ targetUrl);
}
TairClient client = new TairClient(this, ioSession,targetUrl);
processor.setClient(client);
processor.setFactory(this, targetUrl);
return client;
}
示例7: removeChannelIfDisconnectd
import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
static void removeChannelIfDisconnectd(IoSession session) {
if (session != null && ! session.isConnected()) {
session.removeAttribute(CHANNEL_KEY);
}
}