1 | package org.apache.mina.io.datagram; |
2 | |
3 | import org.apache.mina.common.ByteBuffer; |
4 | import org.apache.mina.io.IoFilterChain; |
5 | import org.apache.mina.io.IoSession; |
6 | import org.apache.mina.io.IoSessionManagerFilterChain; |
7 | import org.apache.mina.util.Queue; |
8 | |
9 | /** |
10 | * An {@link IoFilterChain} for datagram transport (UDP/IP). |
11 | * |
12 | * @author The Apache Directory Project |
13 | */ |
14 | class DatagramSessionManagerFilterChain extends IoSessionManagerFilterChain { |
15 | |
16 | DatagramSessionManagerFilterChain( DatagramSessionManager processor ) |
17 | { |
18 | super( processor ); |
19 | } |
20 | |
21 | protected void doWrite( IoSession session, ByteBuffer buf, Object marker ) |
22 | { |
23 | DatagramSession s = ( DatagramSession ) session; |
24 | Queue writeBufferQueue = s.getWriteBufferQueue(); |
25 | Queue writeMarkerQueue = s.getWriteMarkerQueue(); |
26 | |
27 | synchronized( writeBufferQueue ) |
28 | { |
29 | writeBufferQueue.push( buf ); |
30 | writeMarkerQueue.push( marker ); |
31 | if( writeBufferQueue.size() == 1 ) |
32 | { |
33 | // Notify DatagramSessionManager only when writeBufferQueue was empty. |
34 | ( ( DatagramSessionManager ) getManager() ).flushSession( s ); |
35 | } |
36 | } |
37 | } |
38 | } |