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 <a href="http://mina.apache.org">Apache MINA Project</a> 31 */ 32 public interface IoSessionRecycler { 33 /** 34 * A dummy recycler that doesn't recycle any sessions. Using this recycler will 35 * make all session lifecycle events to be fired for every I/O for all connectionless 36 * sessions. 37 */ 38 IoSessionRecyclersionRecycler.html#IoSessionRecycler">IoSessionRecycler NOOP = new IoSessionRecycler() { 39 /** 40 * {@inheritDoc} 41 */ 42 @Override 43 public void put(IoSession session) { 44 // Do nothing 45 } 46 47 /** 48 * {@inheritDoc} 49 */ 50 @Override 51 public IoSession recycle(SocketAddress remoteAddress) { 52 return null; 53 } 54 55 /** 56 * {@inheritDoc} 57 */ 58 @Override 59 public void remove(IoSession session) { 60 // Do nothing 61 } 62 }; 63 64 /** 65 * Called when the underlying transport creates or writes a new {@link IoSession}. 66 * 67 * @param session the new {@link IoSession}. 68 */ 69 void put(IoSession session); 70 71 /** 72 * Attempts to retrieve a recycled {@link IoSession}. 73 * 74 * @param remoteAddress the remote socket address of the {@link IoSession} the transport wants to recycle. 75 * @return a recycled {@link IoSession}, or null if one cannot be found. 76 */ 77 IoSession recycle(SocketAddress remoteAddress); 78 79 /** 80 * Called when an {@link IoSession} is explicitly closed. 81 * 82 * @param session the new {@link IoSession}. 83 */ 84 void remove(IoSession session); 85 }