本文整理汇总了Java中org.apache.mina.core.session.IoSession类的典型用法代码示例。如果您正苦于以下问题:Java IoSession类的具体用法?Java IoSession怎么用?Java IoSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IoSession类属于org.apache.mina.core.session包,在下文中一共展示了IoSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processWriteCommand
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
private boolean processWriteCommand ( final IoSession session, final IoBuffer data, final ProtocolDecoderOutput out ) throws ProtocolCodecException
{
final int len = messageLength ( data );
if ( len < 0 )
{
return false;
}
final int registerNumber = data.getUnsignedShort ();
final int operationId = data.getInt ();
final Variant value = decodeVariant ( session, data );
out.write ( new WriteCommand ( registerNumber, value, operationId ) );
return true;
}
示例2: handleDT
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
/**
* Handle data transmission
*
* @param nextFilter
* @param session
* @param writeRequest
*/
private void handleDT ( final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest )
{
final DataTPDU userData = (DataTPDU)writeRequest.getMessage ();
final IoBuffer data = IoBuffer.allocate ( userData.getData ().remaining () + 3 );
data.put ( (byte)0x02 ); // header length
data.put ( (byte) ( COMMAND_DATA << 4 ) );
final byte seq = (byte)0x80; // bit 8 to 1 (last packet)... bit 7..1 to zero (packet #0)
data.put ( seq );
data.put ( userData.getData () );
data.flip ();
nextFilter.filterWrite ( session, new WriteRequestWrapper ( writeRequest ) {
@Override
public Object getMessage ()
{
return data;
}
} );
}
示例3: createHelloMessage
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
private Object createHelloMessage ( final IoSession session, final NextFilter nextFilter )
{
final HandshakeContext context = new HandshakeContext ( ProtocolConfiguration.fromSession ( session ), this.clientMode, session, nextFilter );
final Map<String, String> helloProperties = new HashMap<String, String> ();
for ( final Handshake handshake : getHanshakeHandlers ( ProtocolConfiguration.fromSession ( session ) ) )
{
handshake.request ( context, helloProperties );
}
if ( logger.isDebugEnabled () )
{
logProperties ( "Request session - helloProperties", helloProperties ); //$NON-NLS-1$
}
return new HelloMessage ( helloProperties );
}
示例4: decode
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
@Override
public synchronized void decode ( final IoSession session, final IoBuffer in, final ProtocolDecoderOutput out ) throws Exception
{
IoBuffer currentFrame = (IoBuffer)session.getAttribute ( SESSION_KEY_CURRENT_FRAME );
if ( currentFrame == null )
{
currentFrame = IoBuffer.allocate ( Constants.MAX_PDU_SIZE + Constants.RTU_HEADER_SIZE );
session.setAttribute ( SESSION_KEY_CURRENT_FRAME, currentFrame );
}
logger.trace ( "decode () current frame = {} data = {}", currentFrame.toString (), currentFrame.getHexDump () );
logger.trace ( "decode () new frame = {} data = {}", in.toString (), in.getHexDump () );
final int expectedSize = currentFrame.position () + in.remaining ();
if ( expectedSize > MAX_SIZE + 1 )
{
throw new ModbusProtocolError ( String.format ( "received size (%s) exceeds max size (%s)", expectedSize, MAX_SIZE ) );
}
currentFrame.put ( in );
tick ( session, out );
}
示例5: sessionClosed
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
@Override
public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception {
// Call finishDecode() first when a connection is closed.
ProtocolDecoder decoder = factory.getDecoder(session);
ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter);
try {
decoder.finishDecode(session, decoderOut);
} catch (Throwable t) {
ProtocolDecoderException pde;
if (t instanceof ProtocolDecoderException) {
pde = (ProtocolDecoderException) t;
} else {
pde = new ProtocolDecoderException(t);
}
throw pde;
} finally {
// Dispose everything
disposeCodec(session);
decoderOut.flush(nextFilter, session);
}
// Call the next filter
nextFilter.sessionClosed(session);
}
示例6: doExec
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
@Override
public void doExec(TcpMessage message, IoSession session) {
CjyTcpMessage tcpMsg = (CjyTcpMessage)message;
logger.debug("收到设备" + tcpMsg.getAddress() + "的登录消息" );
//TODO 更新登录设备的状态,包括ip,在线状态等
//登录响应消息
CjyTcpMessage loginResp = new CjyTcpMessage();
loginResp.setAddress(tcpMsg.getAddress());
loginResp.setCmd(TcpNetCmd.LOGIN_ID);
loginResp.setLength(0);
session.write(loginResp);
//召测数据
CjyTcpMessage dataReq = new CjyTcpMessage();
dataReq.setAddress(tcpMsg.getAddress());
dataReq.setCmd(TcpNetCmd.READ_DATA_ID);
dataReq.setLength(0);
session.write(dataReq);
}
示例7: encodeBrowseUpdate
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
private void encodeBrowseUpdate ( final IoSession session, final Object message, final IoBuffer data ) throws ProtocolCodecException
{
// length
data.putUnsignedShort ( ( (BrowseAdded)message ).getEntries ().size () );
final CharsetEncoder encoder = Sessions.getCharsetEncoder ( session );
// data
for ( final BrowseAdded.Entry entry : ( (BrowseAdded)message ).getEntries () )
{
data.putUnsignedShort ( entry.getRegister () );
data.put ( entry.getDataType ().getDataType () );
data.putEnumSet ( entry.getFlags () );
try
{
data.putPrefixedString ( entry.getName (), encoder );
data.putPrefixedString ( entry.getDescription (), encoder );
data.putPrefixedString ( entry.getUnit (), encoder );
}
catch ( final CharacterCodingException e )
{
throw new ProtocolCodecException ( e );
}
}
}
示例8: decodeDataUpdateEntry
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
private DataUpdate.Entry decodeDataUpdateEntry ( final IoBuffer data, final IoSession session ) throws ProtocolCodecException
{
final int register = data.getUnsignedShort ();
final byte missedUpdates = data.get ();
final long timestamp = data.getLong ();
final Set<DataUpdate.State> states = data.getEnumSetShort ( DataUpdate.State.class );
final Variant value = decodeVariant ( session, data );
return new DataUpdate.Entry ( register, value, timestamp, states, missedUpdates );
}
示例9: messageSent
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
@Override
public void messageSent(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception {
if (writeRequest instanceof FilteredWriteRequest) {
FilteredWriteRequest req = (FilteredWriteRequest) writeRequest;
if (req.getParent() == this) {
nextFilter.messageSent(session, req.getParentRequest());
return;
}
}
nextFilter.messageSent(session, writeRequest);
}
示例10: exceptionCaught
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
System.out.println("exceptionCaught……"+cause.getMessage());
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("EXCEPTION, please implement "
+ getClass().getName()
+ ".exceptionCaught() for proper handling:", cause);
}
}
示例11: handlePacket
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, IoSession session) {
List<String> playerList = new ArrayList<String>();
for (Channel ch : Server.getInstance().getAllChannels()) {
Collection<MapleCharacter> list = ch.getPlayerStorage().getAllCharacters();
synchronized (list) {
for (MapleCharacter chr : list) {
if (!chr.isGM()) {
playerList.add(chr.getName());
}
}
}
}
session.write(GMPacketCreator.sendPlayerList(playerList));
}
示例12: sessionClosed
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public final void sessionClosed(NextFilter nextFilter, IoSession session) {
if (eventTypes.contains(IoEventType.SESSION_CLOSED)) {
IoFilterEvent event = new IoFilterEvent(nextFilter, IoEventType.SESSION_CLOSED, session, null);
fireEvent(event);
} else {
nextFilter.sessionClosed(session);
}
}
示例13: sessionOpened
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
@Override
public void sessionOpened ( final NextFilter nextFilter, final IoSession session ) throws Exception
{
final ProtocolConfiguration configuration = ProtocolConfiguration.fromSession ( session );
// init timeout for handshake
// FIXME: this is not a real timeout but a read idle timeout only
session.getConfig ().setReaderIdleTime ( (int)Math.ceil ( configuration.getHandshakeTimeout () / 1000.0 ) );
if ( this.clientMode )
{
nextFilter.filterWrite ( session, new DefaultWriteRequest ( createHelloMessage ( session, nextFilter ) ) );
}
}
示例14: onHandShakeCompleted
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
@Override
public void onHandShakeCompleted(IoSession session, int handShakeMsgID) {
switch (handShakeMsgID) {
default:
logger.error("收到未知握手请求" + Integer.toHexString(handShakeMsgID));
break;
}
}
示例15: requestCreateChannel
import org.apache.mina.core.session.IoSession; //导入依赖的package包/类
private void requestCreateChannel(TCRequestMessage message, TCRequestCreateChannel data, IoSession session, UnrealId source, PlayerMessage player) {
synchronized(mutex) {
if (!running.getFlag()) return;
TCTeam team = teams.get(player.getTeam());
synchronized(team) {
Map<Integer, TCChannel> channels = team.getChannels();
synchronized(channels) {
int newChannelId = team.getNextChannelId();
TCChannel newChannel = new TCChannel();
newChannel.setChannelId(newChannelId);
newChannel.setCreator(source);
newChannel.getConnectedBots().add(source);
channels.put(newChannelId, newChannel);
TCInfoTeamChannelCreated infoDataTeam = new TCInfoTeamChannelCreated(-1, owner.getSimTime());
infoDataTeam.setChannel(newChannel.clone());
TCInfoMessage infoMessageTeam = new TCInfoMessage(getMyId(), infoDataTeam);
sendTeamExcept(infoMessageTeam, player.getTeam(), source);
TCInfoTeamChannelCreated infoDataRequestee = new TCInfoTeamChannelCreated(data.getRequestId(), owner.getSimTime());
infoDataRequestee.setChannel(newChannel.clone());
TCInfoMessage infoMessageRequestee = new TCInfoMessage(getMyId(), infoDataRequestee);
sendPrivate(infoMessageRequestee, source);
}
}
}
}