1 /* 2 Copyright 2007 Ramon Servadei 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 package fulmine.util.io; 17 18 import java.nio.channels.Channel; 19 import java.nio.channels.SelectableChannel; 20 import java.nio.channels.SelectionKey; 21 22 import fulmine.IDestroyable; 23 24 /** 25 * A task that is associated with a {@link SelectionKey}. This task is 26 * registered with the {@link SelectorTasks}. Upon registration, this receives 27 * the selection key via the {@link #setSelectionKey(SelectionKey)} method. 28 * <p> 29 * When the registered NIO {@link Channel} has an operation ready for 30 * processing, the {@link #run()} method of this will be executed by the thread 31 * running the {@link SelectorTasks#process()} method. 32 * <p> 33 * Implementations must be efficient; any thread blocking will prevent other 34 * {@link Channel} ready operations from being processed by the 35 * {@link SelectorTasks#process()}. 36 * 37 * 38 * @author Ramon Servadei 39 * 40 */ 41 public interface ISelectionKeyTask extends IDestroyable 42 { 43 /** 44 * Run the task associated with the operation and selection key 45 */ 46 public void run(); 47 48 /** 49 * Receives the selection key returned from the 50 * {@link SelectableChannel#register(java.nio.channels.Selector, int)} 51 * method called during the 52 * {@link SelectorTasks#register(int, SelectableChannel, ISelectionKeyTask)} 53 * method. 54 * 55 * @param selectionKey 56 * the selection key for this 57 */ 58 public void setSelectionKey(SelectionKey selectionKey); 59 }