當前位置: 首頁>>代碼示例>>Java>>正文


Java IoSession類代碼示例

本文整理匯總了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;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:17,代碼來源:ProtocolDecoderImpl.java

示例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;
        }
    } );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:32,代碼來源:COTPFilter.java

示例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 );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:MessageChannelFilter.java

示例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 );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:22,代碼來源:ModbusRtuDecoder.java

示例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);
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:26,代碼來源:ProtocolCodecFilter.java

示例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);
}
 
開發者ID:langxianwei,項目名稱:iot-plat,代碼行數:20,代碼來源:LoginMessageClientHandler.java

示例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 );
        }
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:27,代碼來源:ProtocolEncoderImpl.java

示例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 );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:12,代碼來源:ProtocolDecoderImpl.java

示例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);
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:WriteRequestFilter.java

示例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);
    }
}
 
開發者ID:langxianwei,項目名稱:iot-plat,代碼行數:9,代碼來源:ServerHandler.java

示例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));
}
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:16,代碼來源:PlayerListHandler.java

示例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);
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:ExecutorFilter.java

示例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 ) ) );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:15,代碼來源:MessageChannelFilter.java

示例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;
	}
}
 
開發者ID:langxianwei,項目名稱:iot-plat,代碼行數:9,代碼來源:ProxyBiz.java

示例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);				
			}
		}
	}
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:28,代碼來源:TCMinaServer.java


注:本文中的org.apache.mina.core.session.IoSession類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。