当前位置: 首页>>代码示例>>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;未经允许,请勿转载。