本文整理汇总了Java中org.apache.mina.core.filterchain.IoFilterAdapter类的典型用法代码示例。如果您正苦于以下问题:Java IoFilterAdapter类的具体用法?Java IoFilterAdapter怎么用?Java IoFilterAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IoFilterAdapter类属于org.apache.mina.core.filterchain包,在下文中一共展示了IoFilterAdapter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPreAdd
import org.apache.mina.core.filterchain.IoFilterAdapter; //导入依赖的package包/类
@Override
public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception {
Class<? extends IoFilterAdapter> clazz = getClass();
if (parent.contains(clazz)) {
throw new IllegalStateException("Only one " + clazz.getName() + " is permitted.");
}
}
示例2: buildFilterChain
import org.apache.mina.core.filterchain.IoFilterAdapter; //导入依赖的package包/类
@Override
public void buildFilterChain ( final IoFilterChain chain )
{
if ( this.loggerName != null && Boolean.getBoolean ( "org.eclipse.scada.protocol.sfp.common.logger.raw" ) )
{
chain.addFirst ( "logger.raw", new LoggingFilter ( this.loggerName ) );
}
if ( !Boolean.getBoolean ( "org.eclipse.scada.protocol.sfp.common.disableStats" ) )
{
chain.addFirst ( StatisticsFilter.DEFAULT_NAME, new StatisticsFilter () );
}
if ( this.loggerName != null && Boolean.getBoolean ( "org.eclipse.scada.protocol.sfp.common.logger" ) )
{
chain.addFirst ( "logger", new LoggingFilter ( this.loggerName ) );
}
chain.addLast ( "closeidle", new IoFilterAdapter () {
@Override
public void sessionIdle ( final NextFilter nextFilter, final IoSession session, final IdleStatus status ) throws Exception
{
session.close ( true );
}
} );
chain.addLast ( "codec", new ProtocolCodecFilter ( new ProtocolEncoderImpl (), new ProtocolDecoderImpl () ) );
}
示例3: setUp
import org.apache.mina.core.filterchain.IoFilterAdapter; //导入依赖的package包/类
@Before
public void setUp() throws InterruptedException {
connMsg = new ConnectMessage();
connMsg.setProcotolVersion((byte) 0x03);
m_minaSession = new DummySession();
m_session = new MinaChannel(m_minaSession);
m_minaSession.getFilterChain().addFirst("MessageCatcher", new IoFilterAdapter() {
@Override
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session,
WriteRequest writeRequest) throws Exception {
try {
m_receivedMessage = (AbstractMessage) writeRequest.getMessage();
if (m_receivedMessage instanceof ConnAckMessage) {
ConnAckMessage buf = (ConnAckMessage) m_receivedMessage;
m_returnCode = buf.getReturnCode();
}
} catch (Exception ex) {
throw new AssertionError("Wrong return code");
}
}
});
//sleep to let the messaging batch processor to process the initEvent
Thread.sleep(300);
m_storageService = new MemoryStorageService();
//m_storageService.initStore();
subscriptions = new SubscriptionsStore();
subscriptions.init(m_storageService);
m_processor = new ProtocolProcessor();
m_processor.init(subscriptions, m_storageService);
}
示例4: testPublishOfRetainedMessage_afterNewSubscription
import org.apache.mina.core.filterchain.IoFilterAdapter; //导入依赖的package包/类
@Test
public void testPublishOfRetainedMessage_afterNewSubscription() throws Exception {
m_minaSession.getFilterChain().remove("MessageCatcher");
m_minaSession.getFilterChain().addFirst("MessageCatcher", new IoFilterAdapter() {
@Override
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session,
WriteRequest writeRequest) throws Exception {
try {
System.out.println("filterReceived class " + writeRequest.getMessage().getClass().getName());
if (writeRequest.getMessage() instanceof PublishMessage) {
m_receivedMessage = (AbstractMessage) writeRequest.getMessage();
}
if (m_receivedMessage instanceof ConnAckMessage) {
ConnAckMessage buf = (ConnAckMessage) m_receivedMessage;
m_returnCode = buf.getReturnCode();
}
} catch (Exception ex) {
throw new AssertionError("Wrong return code");
}
}
});
// //simulate a connect that register a clientID to an IoSession
final Subscription subscription = new Subscription(FAKE_CLIENT_ID,
FAKE_TOPIC, AbstractMessage.QOSType.MOST_ONE, true);
//subscriptions.matches(topic) redefine the method to return true
SubscriptionsStore subs = new SubscriptionsStore() {
@Override
public List<Subscription> matches(String topic) {
if (topic.equals(FAKE_TOPIC)) {
return Arrays.asList(subscription);
} else {
throw new IllegalArgumentException("Expected " + FAKE_TOPIC + " buf found " + topic);
}
}
};
subs.init(new MemoryStorageService());
//simulate a connect that register a clientID to an IoSession
m_processor.init(subs, m_storageService);
ConnectMessage connectMessage = new ConnectMessage();
connectMessage.setClientID(FAKE_CLIENT_ID);
connectMessage.setProcotolVersion((byte)3);
connectMessage.setCleanSession(subscription.isCleanSession());
m_processor.processConnect(m_session, connectMessage);
PublishEvent pubEvt = new PublishEvent(FAKE_TOPIC, AbstractMessage.QOSType.MOST_ONE, "Hello".getBytes(), true, "FakeCLI", null);
m_processor.processPublish(pubEvt);
//Exercise
SubscribeMessage msg = new SubscribeMessage();
msg.addSubscription(new SubscribeMessage.Couple((byte)QOSType.MOST_ONE.ordinal(), "#"));
m_processor.processSubscribe(m_session, msg, FAKE_CLIENT_ID, false);
//Verify
assertNotNull(m_receivedMessage);
assertTrue(m_receivedMessage instanceof PublishMessage);
PublishMessage pubMessage = (PublishMessage) m_receivedMessage;
assertEquals(FAKE_TOPIC, pubMessage.getTopicName());
}
示例5: setLoggingFilter
import org.apache.mina.core.filterchain.IoFilterAdapter; //导入依赖的package包/类
/**
* <p>setLoggingFilter</p>
*
* @param filterLogging a {@link org.apache.mina.core.filterchain.IoFilterAdapter} object.
*/
protected final void setLoggingFilter(final IoFilterAdapter filterLogging) {
m_filterLogging = filterLogging;
}
示例6: getLoggingFilter
import org.apache.mina.core.filterchain.IoFilterAdapter; //导入依赖的package包/类
/**
* <p>getLoggingFilter</p>
*
* @return a {@link org.apache.mina.core.filterchain.IoFilterAdapter} object.
*/
protected final IoFilterAdapter getLoggingFilter() {
return m_filterLogging;
}