1 18 package org.apache.activemq.transport.nio; 19 20 import java.nio.channels.ClosedChannelException ; 21 import java.nio.channels.SelectionKey ; 22 import java.nio.channels.SocketChannel ; 23 24 import org.apache.activemq.transport.nio.SelectorManager.Listener; 25 26 30 final public class SelectorSelection { 31 32 private final SelectorWorker worker; 33 private final SelectionKey key; 34 private final Listener listener; 35 private int interest; 36 37 38 public SelectorSelection(SelectorWorker worker, SocketChannel socketChannel, Listener listener) throws ClosedChannelException { 39 this.worker = worker; 40 this.listener = listener; 41 this.key = socketChannel.register(worker.selector, 0, this); 42 worker.incrementUseCounter(); 43 } 44 45 public void setInterestOps(int ops) { 46 interest = ops; 47 } 48 49 public void enable() { 50 key.interestOps(interest); 51 worker.selector.wakeup(); 52 } 53 54 public void disable() { 55 key.interestOps(0); 56 } 57 58 public void close() { 59 worker.decrementUseCounter(); 60 key.cancel(); 61 worker.selector.wakeup(); 62 } 63 64 public void onSelect() { 65 listener.onSelect(this); 66 } 67 68 public void onError(Throwable e) { 69 listener.onError(this, e); 70 } 71 72 } 73 | Popular Tags |