当前位置: 首页>>代码示例>>Java>>正文


Java IoSession类代码示例

本文整理汇总了Java中org.apache.mina.common.IoSession的典型用法代码示例。如果您正苦于以下问题:Java IoSession类的具体用法?Java IoSession怎么用?Java IoSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IoSession类属于org.apache.mina.common包,在下文中一共展示了IoSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:MinaChannel.java

示例2: messageReceived

import org.apache.mina.common.IoSession; //导入依赖的package包/类
public void messageReceived(IoSession session, Object message) throws Exception {
  if (message instanceof List) {
    @SuppressWarnings("unchecked")
    List<ResponseWrapper> responses = (List<ResponseWrapper>) message;
    if (isDebugEnabled) {
      // for performance trace
      LOGGER.debug("receive response list from server: " + session.getRemoteAddress() + ",list size is:" + responses.size());
    }
    client.putResponses(responses);
  } else if (message instanceof ResponseWrapper) {
    ResponseWrapper response = (ResponseWrapper) message;
    if (isDebugEnabled) {
      // for performance trace
      LOGGER.debug("receive response list from server: " + session.getRemoteAddress() + ",request is:" + response.getRequestId());
    }
    client.putResponse(response);
  } else {
    LOGGER.error("receive message error,only support List || ResponseWrapper");
    throw new Exception("receive message error,only support List || ResponseWrapper");
  }
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:22,代码来源:MinaClientProcessor.java

示例3: handleRequest

import org.apache.mina.common.IoSession; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void handleRequest(final IoSession session, final Object message) {
  try {
    threadpool.execute(new HandlerRunnable(session, message, threadpool));
  } catch (RejectedExecutionException exception) {
    LOGGER.error("server threadpool full,threadpool maxsize is:" + ((ThreadPoolExecutor) threadpool).getMaximumPoolSize());
    if (message instanceof List) {
      List<RequestWrapper> requests = (List<RequestWrapper>) message;
      for (final RequestWrapper request : requests) {
        sendErrorResponse(session, request);
      }
    } else {
      sendErrorResponse(session, (RequestWrapper) message);
    }
  }
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:17,代码来源:MinaServerHandler.java

示例4: encode

import org.apache.mina.common.IoSession; //导入依赖的package包/类
@Override
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        final byte[] input = ((MaplePacket) message).getBytes();
        final byte[] unencrypted = new byte[input.length];
        System.arraycopy(input, 0, unencrypted, 0, input.length);

        final byte[] ret = new byte[unencrypted.length + 4];

        final byte[] header = client.getSendCrypto().getPacketHeader(unencrypted.length);
        synchronized(client.getSendCrypto()){
            MapleCustomEncryption.encryptData(unencrypted);
            client.getSendCrypto().crypt(unencrypted);

            System.arraycopy(header, 0, ret, 0, 4);
            System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);

            final ByteBuffer out_buffer = ByteBuffer.wrap(ret);
            out.write(out_buffer);
        }
    } else { // no client object created yet, send unencrypted (hello)
            out.write(ByteBuffer.wrap(((MaplePacket) message).getBytes()));
    }
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:27,代码来源:MaplePacketEncoder.java

示例5: encode

import org.apache.mina.common.IoSession; //导入依赖的package包/类
public void encode(IoSession session, Object message,
		ProtocolEncoderOutput out) throws Exception {
	if(!(message instanceof byte[])){
		throw new Exception("must send byte[]");
	}
	byte[] payload=(byte[]) message;
	ByteBuffer buf = ByteBuffer.allocate(payload.length, false);
       buf.put(payload);
       buf.flip();
       out.write(buf);
       if (isDebugEnabled)
       	LOGGER.debug(TairUtil.toHex(payload));
}
 
开发者ID:alibaba,项目名称:tair-java-client,代码行数:14,代码来源:TairProtocolEncoder.java

示例6: exceptionCaught

import org.apache.mina.common.IoSession; //导入依赖的package包/类
@Override
public void exceptionCaught(final IoSession session, final Throwable cause) throws Exception {
    //cause.printStackTrace();
    /*
    MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    log.error(MapleClient.getLogMessage(client, cause.getMessage()), cause);
    ChannelServer.getInstance(1).broadcastPacket(MaplePacketCreator.getChatText(30000, "Exception: " + cause.getClass().getName() + ": " + cause.getMessage()));
    for (int i = 0; i < cause.getStackTrace().length; ++i) {
        StackTraceElement ste = cause.getStackTrace()[i];
        ChannelServer.getInstance(1).broadcastPacket(MaplePacketCreator.getChatText(30000, ste.toString()));
        if (i > 2) {
            break;
        }
    }
    */
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:17,代码来源:MapleServerHandler.java

示例7: 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;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:11,代码来源:MinaServer.java

示例8: getChannel

import org.apache.mina.common.IoSession; //导入依赖的package包/类
public Channel getChannel(InetSocketAddress remoteAddress) {
    Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
    for (IoSession session : sessions) {
        if (session.getRemoteAddress().equals(remoteAddress)) {
            return MinaChannel.getOrAddChannel(session, getUrl(), this);
        }
    }
    return null;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:MinaServer.java

示例9: MinaChannel

import org.apache.mina.common.IoSession; //导入依赖的package包/类
private MinaChannel(IoSession session, URL url, ChannelHandler handler){
    super(url, handler);
    if (session == null) {
        throw new IllegalArgumentException("mina session == null");
    }
    this.session = session;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:8,代码来源:MinaChannel.java

示例10: encode

import org.apache.mina.common.IoSession; //导入依赖的package包/类
public void encode(IoSession session, Object msg, ProtocolEncoderOutput out) throws Exception {
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
    MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
    try {
    	codec.encode(channel, buffer, msg);
    } finally {
        MinaChannel.removeChannelIfDisconnectd(session);
    }
    out.write(ByteBuffer.wrap(buffer.toByteBuffer()));
    out.flush();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:12,代码来源:MinaCodecAdapter.java

示例11: sessionOpened

import org.apache.mina.common.IoSession; //导入依赖的package包/类
@Override
public void sessionOpened(IoSession session) throws Exception {
    MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
    try {
        handler.connected(channel);
    } finally {
        MinaChannel.removeChannelIfDisconnectd(session);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:MinaHandler.java

示例12: sessionClosed

import org.apache.mina.common.IoSession; //导入依赖的package包/类
@Override
public void sessionClosed(IoSession session) throws Exception {
    MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
    try {
        handler.disconnected(channel);
    } finally {
        MinaChannel.removeChannelIfDisconnectd(session);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:MinaHandler.java

示例13: messageReceived

import org.apache.mina.common.IoSession; //导入依赖的package包/类
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
    MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
    try {
        handler.received(channel, message);
    } finally {
        MinaChannel.removeChannelIfDisconnectd(session);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:MinaHandler.java

示例14: messageSent

import org.apache.mina.common.IoSession; //导入依赖的package包/类
@Override
public void messageSent(IoSession session, Object message) throws Exception {
    MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
    try {
        handler.sent(channel, message);
    } finally {
        MinaChannel.removeChannelIfDisconnectd(session);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:MinaHandler.java

示例15: exceptionCaught

import org.apache.mina.common.IoSession; //导入依赖的package包/类
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
    MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
    try {
        handler.caught(channel, cause);
    } finally {
        MinaChannel.removeChannelIfDisconnectd(session);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:MinaHandler.java


注:本文中的org.apache.mina.common.IoSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。