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


Java IoSession.setAttribute方法代码示例

本文整理汇总了Java中org.apache.mina.core.session.IoSession.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java IoSession.setAttribute方法的具体用法?Java IoSession.setAttribute怎么用?Java IoSession.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.core.session.IoSession的用法示例。


在下文中一共展示了IoSession.setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exceptionCaught

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * Handle the exception we got.
 *
 * @param session The session we got the exception on
 * @param cause The exception cause
 * @throws Exception The t
 */
@Override
public void exceptionCaught( IoSession session, Throwable cause ) throws Exception
{
    LOG.warn( cause.getMessage(), cause );
    session.setAttribute( EXCEPTION_KEY, cause );

    if ( cause instanceof ProtocolEncoderException )
    {
        Throwable realCause = ( ( ProtocolEncoderException ) cause ).getCause();

        if ( realCause instanceof MessageEncoderException )
        {
            int messageId = ( ( MessageEncoderException ) realCause ).getMessageId();

            ResponseFuture<?> response = futureMap.get( messageId );
            response.cancel( true );
            response.setCause( realCause );
        }
    }

    session.closeNow();
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:30,代码来源:LdapNetworkConnection.java

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

示例3: encode

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    CharsetEncoder encoder = (CharsetEncoder) session.getAttribute(ENCODER);

    if (encoder == null) {
        encoder = charset.newEncoder();
        session.setAttribute(ENCODER, encoder);
    }

    String value = (message == null ? "" : message.toString());
    IoBuffer buf = IoBuffer.allocate(value.length()).setAutoExpand(true);
    buf.putString(value, encoder);

    if (buf.position() > maxLineLength) {
        throw new IllegalArgumentException("Line length: " + buf.position());
    }

    buf.putString(delimiter.getValue(), encoder);
    buf.flip();
    out.write(buf);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:21,代码来源:TextLineEncoder.java

示例4: onPreAdd

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * Executed just before the filter is added into the chain, we do :
 * <ul>
 * <li>check that we don't have a SSL filter already present
 * <li>we update the next filter
 * <li>we create the SSL handler helper class
 * <li>and we store it into the session's Attributes
 * </ul>
 */
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws SSLException {
    // Check that we don't have a SSL filter already present in the chain
    if (parent.contains(SslFilter.class)) {
        String msg = "Only one SSL filter is permitted in a chain.";
        LOGGER.error(msg);
        throw new IllegalStateException(msg);
    }

    LOGGER.debug("Adding the SSL Filter {} to the chain", name);

    IoSession session = parent.getSession();
    session.setAttribute(NEXT_FILTER, nextFilter);

    // Create a SSL handler and start handshake.
    SslHandler handler = new SslHandler(this, session);
    handler.init();
    session.setAttribute(SSL_HANDLER, handler);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:29,代码来源:SslFilter.java

示例5: messageReceived

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
    // no cube in session implies there must be a header line
    Cube cube = (Cube) session.getAttribute(CUBE);
    String line = (String) message;
    logger.info("### PARSING [{}]", message);
    if (cube == null) {
        cube = parser.parseHeader(line);
        session.setAttribute(CUBE, cube);
    } else {
        if (message != null && ((String) message).length() > 0) {
            parser.parse(cube, line);
            if (line.startsWith("L:")) {
                latch.countDown();
            } else if (line.startsWith("S:")) {
                boolean successfulBoost = parser.parseResponseS(line);
                session.setAttribute(BOOST_RESPONSE, successfulBoost);
                latch.countDown();
            }
        }
    }
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:23,代码来源:MinaCubeClient.java

示例6: sessionIdle

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception {
    if (status == interestedIdleStatus) {
        if (!session.containsAttribute(WAITING_FOR_RESPONSE)) {
            Object pingMessage = messageFactory.getRequest(session);
            if (pingMessage != null) {
                nextFilter.filterWrite(session, new DefaultWriteRequest(pingMessage));

                // If policy is OFF, there's no need to wait for
                // the response.
                if (getRequestTimeoutHandler() != KeepAliveRequestTimeoutHandler.DEAF_SPEAKER) {
                    markStatus(session);
                    if (interestedIdleStatus == IdleStatus.BOTH_IDLE) {
                        session.setAttribute(IGNORE_READER_IDLE_ONCE);
                    }
                } else {
                    resetStatus(session);
                }
            }
        } else {
            handlePingTimeout(session);
        }
    } else if (status == IdleStatus.READER_IDLE) {
        if (session.removeAttribute(IGNORE_READER_IDLE_ONCE) == null) {
            if (session.containsAttribute(WAITING_FOR_RESPONSE)) {
                handlePingTimeout(session);
            }
        }
    }

    if (forwardEvent) {
        nextFilter.sessionIdle(session, status);
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:35,代码来源:KeepAliveFilter.java

示例7: sessionOpened

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(IoSession session) {
    if (!Server.getInstance().isOnline()) {
        session.close(true);
        return;
    }
    if (channel > -1 && world > -1) {
        if (Server.getInstance().getChannel(world, channel) == null) {
            session.close(true);
            return;
        }
    } else {
        FilePrinter.print(FilePrinter.SESSION, "IoSession with " + session.getRemoteAddress() + " opened on " + sdf.format(Calendar.getInstance().getTime()), false);
    }

    byte key[] = {0x13, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, (byte) 0xB4, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00};
    byte ivRecv[] = {70, 114, 122, 82};
    byte ivSend[] = {82, 48, 120, 115};
    ivRecv[3] = (byte) (Math.random() * 255);
    ivSend[3] = (byte) (Math.random() * 255);
    MapleAESOFB sendCypher = new MapleAESOFB(key, ivSend, (short) (0xFFFF - ServerConstants.VERSION));
    MapleAESOFB recvCypher = new MapleAESOFB(key, ivRecv, (short) ServerConstants.VERSION);
    MapleClient client = new MapleClient(sendCypher, recvCypher, session);
    client.setWorld(world);
    client.setChannel(channel);
    session.write(MaplePacketCreator.getHello(ServerConstants.VERSION, ivSend, ivRecv));
    session.setAttribute(MapleClient.CLIENT_KEY, client);
}
 
开发者ID:NovaStory,项目名称:AeroStory,代码行数:29,代码来源:MapleServerHandler.java

示例8: getDecoderOut

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * Return a reference to the decoder callback. If it's not already created
 * and stored into the session, we create a new instance.
 */
private ProtocolDecoderOutput getDecoderOut(IoSession session, NextFilter nextFilter) {
    ProtocolDecoderOutput out = (ProtocolDecoderOutput) session.getAttribute(DECODER_OUT);

    if (out == null) {
        // Create a new instance, and stores it into the session
        out = new ProtocolDecoderOutputImpl();
        session.setAttribute(DECODER_OUT, out);
    }

    return out;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:16,代码来源:ProtocolCodecFilter.java

示例9: getPack

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
private Pack getPack(IoSession session) {
    Pack ctx;
    ctx = (Pack) session.getAttribute(PACK);

    if (ctx == null) {
        ctx = new Pack();
        session.setAttribute(PACK, ctx);
    }

    return ctx;
}
 
开发者ID:altiplanogao,项目名称:io-comparison,代码行数:12,代码来源:MsgDecoder.java

示例10: sessionCreated

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * This method is called when a new session is created. We will store some
 * informations that the session will need to process incoming requests.
 * 
 * @param session the newly created session
 */
@Override
public void sessionCreated( IoSession session ) throws Exception
{
    // Last, store the message container
    LdapMessageContainer<? extends MessageDecorator<Message>> ldapMessageContainer =
        new LdapMessageContainer<>(
            codec, config.getBinaryAttributeDetector() );

    session.setAttribute( LdapDecoder.MESSAGE_CONTAINER_ATTR, ldapMessageContainer );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:17,代码来源:LdapNetworkConnection.java

示例11: getSessionBuffer

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * Get the session buffer and create one of necessary
 * 
 * @param session
 *            the session
 * @return the session buffer
 */
private IoBuffer getSessionBuffer ( final IoSession session )
{
    IoBuffer buffer = (IoBuffer)session.getAttribute ( SESSION_BUFFER_ATTR );
    if ( buffer == null )
    {
        buffer = IoBuffer.allocate ( 0 );
        buffer.setAutoExpand ( true );
        session.setAttribute ( SESSION_BUFFER_ATTR, buffer );
    }
    return buffer;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:TPKTFilter.java

示例12: getContext

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * Return the context for this session
 */
private Context getContext(IoSession session) {
    Context ctx;
    ctx = (Context) session.getAttribute(CONTEXT);

    if (ctx == null) {
        ctx = new Context(bufferLength);
        session.setAttribute(CONTEXT, ctx);
    }

    return ctx;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:TextLineDecoder.java

示例13: onPreAdd

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (parent.contains(this)) {
        throw new IllegalArgumentException(
                "You can't add the same filter instance more than once.  Create another instance and add it.");
    }

    IoSession session = parent.getSession();
    session.setAttribute(RESPONSE_INSPECTOR, responseInspectorFactory.getResponseInspector());
    session.setAttribute(REQUEST_STORE, createRequestStore(session));
    session.setAttribute(UNRESPONDED_REQUEST_STORE, createUnrespondedRequestStore(session));
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:13,代码来源:RequestResponseFilter.java

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

示例15: onPreAdd

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
    if (parent.contains(CompressionFilter.class)) {
        throw new IllegalStateException("Only one " + CompressionFilter.class + " is permitted.");
    }

    Zlib deflater = new Zlib(compressionLevel, Zlib.MODE_DEFLATER);
    Zlib inflater = new Zlib(compressionLevel, Zlib.MODE_INFLATER);

    IoSession session = parent.getSession();

    session.setAttribute(DEFLATER, deflater);
    session.setAttribute(INFLATER, inflater);
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:CompressionFilter.java


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