mina nextfilter

mina中nextFilter是不一定代表的是在filterChain中的下一个filter,在 DefaultIoFilterChain中,EntryImpl是一个内部类,源码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
private final class EntryImpl implements Entry {
private EntryImpl prevEntry;

private EntryImpl nextEntry;

private final String name;

private IoFilter filter;

private final NextFilter nextFilter;

private EntryImpl(EntryImpl prevEntry, EntryImpl nextEntry, String name, IoFilter filter) {
if (filter == null) {
throw new IllegalArgumentException("filter");
}

if (name == null) {
throw new IllegalArgumentException("name");
}

this.prevEntry = prevEntry;
this.nextEntry = nextEntry;
this.name = name;
this.filter = filter;
this.nextFilter = new NextFilter() {
/
{@inheritDoc}
/

@Override
public void sessionCreated(IoSession session) {
Entry nextEntry = EntryImpl.this.nextEntry;
callNextSessionCreated(nextEntry, session);
}

/

{@inheritDoc}
/

@Override
public void sessionOpened(IoSession session) {
Entry nextEntry = EntryImpl.this.nextEntry;
callNextSessionOpened(nextEntry, session);
}

/
{@inheritDoc}
/

@Override
public void sessionClosed(IoSession session) {
Entry nextEntry = EntryImpl.this.nextEntry;
callNextSessionClosed(nextEntry, session);
}

/

{@inheritDoc}
/

@Override
public void sessionIdle(IoSession session, IdleStatus status) {
Entry nextEntry = EntryImpl.this.nextEntry;
callNextSessionIdle(nextEntry, session, status);
}

/
{@inheritDoc}
/

@Override
public void exceptionCaught(IoSession session, Throwable cause) {
Entry nextEntry = EntryImpl.this.nextEntry;
callNextExceptionCaught(nextEntry, session, cause);
}

/

{@inheritDoc}
/

@Override
public void inputClosed(IoSession session) {
Entry nextEntry = EntryImpl.this.nextEntry;
callNextInputClosed(nextEntry, session);
}

/
{@inheritDoc}
/

@Override
public void messageReceived(IoSession session, Object message) {
Entry nextEntry = EntryImpl.this.nextEntry;
callNextMessageReceived(nextEntry, session, message);
}

/

{@inheritDoc}
/
@Override
public void messageSent(IoSession session, WriteRequest writeRequest) {
Entry nextEntry = EntryImpl.this.nextEntry;
callNextMessageSent(nextEntry, session, writeRequest);
}

/
{@inheritDoc}
/

@Override
public void filterWrite(IoSession session, WriteRequest writeRequest) {
Entry nextEntry = EntryImpl.this.prevEntry;
callPreviousFilterWrite(nextEntry, session, writeRequest);
}

/

{@inheritDoc}
/
@Override
public void filterClose(IoSession session) {
Entry nextEntry = EntryImpl.this.prevEntry;
callPreviousFilterClose(nextEntry, session);
}

/*
{@inheritDoc}

*/
@Override
public String toString() {
return EntryImpl.this.nextEntry.name;
}
};
}

可以看到,nextFilter实现了?NextFilter接口,实现的方法中,filterWrite 和 filterClose调用的entry代码 Entry nextEntry = EntryImpl.this.prevEntry;,这两个调用的都是之前的entry.