KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > mina > common > IoSessionRecycler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.mina.common;
21
22 import java.net.SocketAddress JavaDoc;
23
24 /**
25  * A connectionless transport can recycle existing sessions by assigning an
26  * IoSessionRecyler to its {@link IoServiceConfig}.
27  *
28  * @author The Apache Directory Project (mina-dev@directory.apache.org)
29  * TODO More documentation
30  */

31 public interface IoSessionRecycler {
32     /**
33      * A dummy recycler that doesn't recycle any sessions. Using this recycler will
34      * make all session lifecycle events to be fired for every I/O for all connectionless
35      * sessions.
36      */

37     static IoSessionRecycler NOOP = new IoSessionRecycler() {
38         public void put(IoSession session) {
39         }
40
41         public IoSession recycle(SocketAddress JavaDoc localAddress,
42                 SocketAddress JavaDoc remoteAddress) {
43             return null;
44         }
45
46         public void remove(IoSession session) {
47         }
48     };
49
50     /**
51      * Called when the underlying transport creates or writes a new {@link IoSession}.
52      *
53      * @param session
54      * the new {@link IoSession}.
55      */

56     void put(IoSession session);
57
58     /**
59      * Attempts to retrieve a recycled {@link IoSession}.
60      *
61      * @param localAddress
62      * the local socket address of the {@link IoSession} the
63      * transport wants to recycle.
64      * @param remoteAddress
65      * the remote socket address of the {@link IoSession} the
66      * transport wants to recycle.
67      * @return a recycled {@link IoSession}, or null if one cannot be found.
68      */

69     IoSession recycle(SocketAddress JavaDoc localAddress, SocketAddress JavaDoc remoteAddress);
70
71     /**
72      * Called when an {@link IoSession} is explicitly closed.
73      *
74      * @param session
75      * the new {@link IoSession}.
76      */

77     void remove(IoSession session);
78 }
79
Popular Tags