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


Java IoSession.getAttribute方法代碼示例

本文整理匯總了Java中org.apache.mina.core.session.IoSession.getAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java IoSession.getAttribute方法的具體用法?Java IoSession.getAttribute怎麽用?Java IoSession.getAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.mina.core.session.IoSession的用法示例。


在下文中一共展示了IoSession.getAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: doFilterWrite

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
@Override
protected Object doFilterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
        throws IOException {
    if (!compressOutbound) {
        return null;
    }

    if (session.containsAttribute(DISABLE_COMPRESSION_ONCE)) {
        // Remove the marker attribute because it is temporary.
        session.removeAttribute(DISABLE_COMPRESSION_ONCE);
        return null;
    }

    Zlib deflater = (Zlib) session.getAttribute(DEFLATER);
    if (deflater == null) {
        throw new IllegalStateException();
    }

    IoBuffer inBuffer = (IoBuffer) writeRequest.getMessage();
    if (!inBuffer.hasRemaining()) {
        // Ignore empty buffers
        return null;
    } else {
        return deflater.deflate(inBuffer);
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:27,代碼來源:CompressionFilter.java

示例3: messageReceived

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
@Override
public void messageReceived ( final IoSession session, final Object message ) throws Exception
{
    logger.trace ( "Received message: {}", message );

    final Object o = session.getAttribute ( "connection" );
    if ( o instanceof ServerConnection )
    {
        ( (ServerConnection)o ).handleMessageReceived ( message );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:12,代碼來源:ServerBaseHandler.java

示例4: encode

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
@Override
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
	CodecContext context = (CodecContext) session.getAttribute(SessionProperties.CODEC_CONTEXT);
	if (context == null) {
		context = new CodecContext();
		session.setAttribute(SessionProperties.CODEC_CONTEXT, context);
	}
	IoBuffer buffer = writeMessage((Message) message);
	out.write(buffer);
}
 
開發者ID:kingston-csj,項目名稱:jforgame,代碼行數:11,代碼來源:MessageEncoder.java

示例5: filterWrite

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
@Override
public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception {
    // If we're already processing a stream we need to queue the WriteRequest.
    if (session.getAttribute(CURRENT_STREAM) != null) {
        Queue<WriteRequest> queue = getWriteRequestQueue(session);
        if (queue == null) {
            queue = new ConcurrentLinkedQueue<WriteRequest>();
            session.setAttribute(WRITE_REQUEST_QUEUE, queue);
        }
        queue.add(writeRequest);
        return;
    }

    Object message = writeRequest.getMessage();

    if (getMessageClass().isInstance(message)) {

        T stream = getMessageClass().cast(message);

        IoBuffer buffer = getNextBuffer(stream);
        if (buffer == null) {
            // End of stream reached.
            writeRequest.getFuture().setWritten();
            nextFilter.messageSent(session, writeRequest);
        } else {
            session.setAttribute(CURRENT_STREAM, message);
            session.setAttribute(CURRENT_WRITE_REQUEST, writeRequest);

            nextFilter.filterWrite(session, new DefaultWriteRequest(buffer));
        }

    } else {
        nextFilter.filterWrite(session, writeRequest);
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:36,代碼來源:AbstractStreamWriteFilter.java

示例6: encode

import org.apache.mina.core.session.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 MapleAESOFB send_crypto = client.getSendCrypto();
            final byte[] input = (byte[]) message;
            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 = send_crypto.getPacketHeader(unencrypted.length);
            MapleCustomEncryption.encryptData(unencrypted);

            final Lock mutex = client.getLock();
            mutex.lock();
            try {
                send_crypto.crypt(unencrypted);
                System.arraycopy(header, 0, ret, 0, 4);
                System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);
                out.write(IoBuffer.wrap(ret));
            } finally {
                mutex.unlock();
            }
//            System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);
//            out.write(ByteBuffer.wrap(ret));
        } else {
            out.write(IoBuffer.wrap(((byte[]) message)));
        }
    }
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:30,代碼來源:MaplePacketEncoder.java

示例7: getTimedContext

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
/**
 * Get the context for a session
 * 
 * @param session
 *            the session
 * @return the context
 */
private Context getTimedContext ( final IoSession session, final boolean create )
{
    Context ctx = (Context)session.getAttribute ( CONTEXT );
    if ( ctx == null && create )
    {
        logger.trace ( "Creating context for: {}", session );
        ctx = new Context ( this, this.timeout, session );
        registerContext ( ctx );
        session.setAttribute ( CONTEXT, ctx );
    }
    return ctx;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:20,代碼來源:TimedEndDecoder.java

示例8: dispose

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
@Override
public void dispose ( final IoSession session ) throws Exception
{
    // remove the context from the session and kill the cyclic check
    final Context ctx = (Context)session.getAttribute ( CONTEXT );
    if ( ctx != null )
    {
        unregisterContext ( ctx );
        ctx.dispose ();
        session.removeAttribute ( CONTEXT );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:TimedEndDecoder.java

示例9: getCharsetDecoder

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
private CharsetDecoder getCharsetDecoder ( final IoSession session )
{
    if ( session.containsAttribute ( "charsetDecoder" ) )
    {
        return (CharsetDecoder)session.getAttribute ( "charsetDecoder" );
    }

    final CharsetDecoder decoder = Charset.forName ( "UTF-8" ).newDecoder ();
    session.setAttribute ( "charsetDecoder", decoder );
    return decoder;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:12,代碼來源:MessageChannelCodecFilter.java

示例10: fromSession

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
public static ProtocolConfiguration fromSession ( final IoSession session )
{
    final Object result = session.getAttribute ( "protocol.configuration" );
    if ( result != null )
    {
        return (ProtocolConfiguration)result;
    }

    return DEFAULT_CONFIGURATION;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:11,代碼來源:ProtocolConfiguration.java

示例11: getState

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
private State getState(IoSession session) throws Exception {
    State state = (State) session.getAttribute(STATE);
    if (state == null) {
        state = new State();
        State oldState = (State) session.setAttributeIfAbsent(STATE, state);
        if (oldState != null) {
            state = oldState;
        }
    }
    return state;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:12,代碼來源:DemuxingProtocolEncoder.java

示例12: getEncoderOut

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
private ProtocolEncoderOutput getEncoderOut(IoSession session, NextFilter nextFilter, WriteRequest writeRequest) {
    ProtocolEncoderOutput out = (ProtocolEncoderOutput) session.getAttribute(ENCODER_OUT);

    if (out == null) {
        // Create a new instance, and stores it into the session
        out = new ProtocolEncoderOutputImpl(session, nextFilter, writeRequest);
        session.setAttribute(ENCODER_OUT, out);
    }

    return out;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:12,代碼來源:ProtocolCodecFilter.java

示例13: sessionOpened

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
/**
 * Hooked session opened event.
 * 
 * @param session the io session
 */
@Override
public final void sessionOpened(IoSession session) throws Exception {
    ProxyIoSession proxyIoSession = (ProxyIoSession) session.getAttribute(ProxyIoSession.PROXY_SESSION);

    if (proxyIoSession.getRequest() instanceof SocksProxyRequest || proxyIoSession.isAuthenticationFailed()
            || proxyIoSession.getHandler().isHandshakeComplete()) {
        proxySessionOpened(session);
    } else {
        logger.debug("Filtered session opened event !");
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:17,代碼來源:AbstractProxyIoHandler.java

示例14: dispose

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
public void dispose(IoSession session) throws Exception {
    Context ctx = (Context) session.getAttribute(CONTEXT);

    if (ctx != null) {
        session.removeAttribute(CONTEXT);
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:11,代碼來源:TextLineDecoder.java

示例15: decode

import org.apache.mina.core.session.IoSession; //導入方法依賴的package包/類
@Override
public MessageDecoderResult decode(IoSession session, IoBuffer in,ProtocolDecoderOutput outPut) throws Exception {
	//將客戶端發來的對象進行封裝
	//TODO  等待測試超長數據是否能正常解碼 
	Context context = (Context) session.getAttribute(CONTEXT);
	//跳過第一個字節
	if(!context.init){
		in.buf().position(0);//由於分包之後mina不能讓沒有改變的緩衝數據返回正常,於是先移動了下遊標,這裏給歸0
		context.init = true;
		in.skip(1);
		in.getInt();
		in.getInt();
	}
 
	int count = context.count;
	//System.out.println("這裏是第一次COnut:"+context.count);
	//System.out.println("一共有"+in.remaining()+"數據");
	while (in.hasRemaining()) {
		//System.out.println("循環裏麵的Count:"+count);
		byte b = in.get();
		if(b == 1){
			//收到下一條的起始數據了,證明此條數據已經殘缺 重置緩衝區 作廢此信息
			in.buf().position(1);//移動遊標,mina不允許不使用數據就返回
			context.reset();//重置
			context.limit_data = true;//用於判斷是否是前一次包破損後遺留下的新數據包  decodable中判斷
			session.setAttribute(CONTEXT, context);
			return MessageDecoderResult.OK;//給他返回個正常解碼,然後才能繼續解碼
		}
		new String(context.byteStr,BeanUtil.charset);
		//如果標題沒讀完 繼續讀
		if(!context.isReadName){
			context.byteStr[count] = b;
			if(count == context.strLength-1){
				//標題讀完  byte[]轉換為字符串
				context.fileName = new String(context.byteStr,BeanUtil.charset);
				//System.out.println(context.fileName);
				//count = -1;
				context.isReadName = true;
				//跳出程序
				break;
			}
		}
		/*
		if(context.isReadName && count != -1){
			//如果讀取完了標題那麽讀取其他內容
			//byteFile[count] = b;
		}
		//byteFile[count] = b;
		 */
		//這裏並未判斷是否後麵還有數據就加了1
		if(in.buf().position()<=in.buf().limit())
		count++;
          }
 
	context.count = count;
	session.setAttribute(CONTEXT, context);
	//如果內容全部讀完  那麽就存入並返回數據
	//System.out.println("Count:"+context.count+";----StrLen:"+context.strLength);
	if(context.count == context.strLength-1){
		//這裏就代表數據全部接收完了 返回出去
		
		BaseMessage message = new BaseMessage();
		message.setDataType(context.dataType);
		StringBean bean = new StringBean();
		bean.setFileName(context.fileName);
		bean.setStrLength(context.strLength);
		message.setData(bean);
		outPut.write(message);
		//重置
		context.reset();
 
	}else{
		return  MessageDecoderResult.NEED_DATA;
	}
	//this.finishDecode(session, outPut);
	
	return MessageDecoderResult.OK;
}
 
開發者ID:Xvms,項目名稱:xvms,代碼行數:79,代碼來源:StringProtocolDecoder.java


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