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.core.session; 21 22 import java.net.SocketAddress; 23 24 import org.apache.mina.core.service.IoService; 25 26 /** 27 * A connectionless transport can recycle existing sessions by assigning an 28 * {@link IoSessionRecycler} to an {@link IoService}. 29 * 30 * @author The Apache MINA Project (dev@mina.apache.org) 31 * TODO More documentation 32 */ 33 public interface IoSessionRecycler { 34 /** 35 * A dummy recycler that doesn't recycle any sessions. Using this recycler will 36 * make all session lifecycle events to be fired for every I/O for all connectionless 37 * sessions. 38 */ 39 static IoSessionRecycler NOOP = new IoSessionRecycler() { 40 public void put(IoSession session) { 41 } 42 43 public IoSession recycle(SocketAddress localAddress, 44 SocketAddress remoteAddress) { 45 return null; 46 } 47 48 public void remove(IoSession session) { 49 } 50 }; 51 52 /** 53 * Called when the underlying transport creates or writes a new {@link IoSession}. 54 * 55 * @param session 56 * the new {@link IoSession}. 57 */ 58 void put(IoSession session); 59 60 /** 61 * Attempts to retrieve a recycled {@link IoSession}. 62 * 63 * @param localAddress 64 * the local socket address of the {@link IoSession} the 65 * transport wants to recycle. 66 * @param remoteAddress 67 * the remote socket address of the {@link IoSession} the 68 * transport wants to recycle. 69 * @return a recycled {@link IoSession}, or null if one cannot be found. 70 */ 71 IoSession recycle(SocketAddress localAddress, SocketAddress remoteAddress); 72 73 /** 74 * Called when an {@link IoSession} is explicitly closed. 75 * 76 * @param session 77 * the new {@link IoSession}. 78 */ 79 void remove(IoSession session); 80 }