1 7 8 package com.sun.corba.se.impl.transport; 9 10 import java.nio.channels.SelectionKey ; 11 12 import org.omg.CORBA.INTERNAL ; 13 14 import com.sun.corba.se.pept.transport.Acceptor; 15 import com.sun.corba.se.pept.transport.Connection; 16 import com.sun.corba.se.pept.transport.EventHandler; 17 18 import com.sun.corba.se.spi.orb.ORB; 19 import com.sun.corba.se.spi.orbutil.threadpool.NoSuchThreadPoolException; 20 import com.sun.corba.se.spi.orbutil.threadpool.NoSuchWorkQueueException; 21 import com.sun.corba.se.spi.orbutil.threadpool.Work; 22 23 import com.sun.corba.se.impl.orbutil.ORBUtility; 24 25 public abstract class EventHandlerBase 26 implements 27 EventHandler 28 { 29 protected ORB orb; 30 protected Work work; 31 protected boolean useWorkerThreadForEvent; 32 protected boolean useSelectThreadToWait; 33 protected SelectionKey selectionKey; 34 35 40 public void setUseSelectThreadToWait(boolean x) 41 { 42 useSelectThreadToWait = x; 43 } 44 45 public boolean shouldUseSelectThreadToWait() 46 { 47 return useSelectThreadToWait; 48 } 49 50 public void setSelectionKey(SelectionKey selectionKey) 51 { 52 this.selectionKey = selectionKey; 53 } 54 55 public SelectionKey getSelectionKey() 56 { 57 return selectionKey; 58 } 59 60 66 public void handleEvent() 67 { 68 if (orb.transportDebugFlag) { 69 dprint(".handleEvent->: " + this); 70 } 71 getSelectionKey().interestOps(getSelectionKey().interestOps() & 72 (~ getInterestOps())); 73 if (shouldUseWorkerThreadForEvent()) { 74 Throwable throwable = null; 75 try { 76 if (orb.transportDebugFlag) { 77 dprint(".handleEvent: addWork to pool: " + 0); 78 } 79 orb.getThreadPoolManager().getThreadPool(0) 80 .getWorkQueue(0).addWork(getWork()); 81 } catch (NoSuchThreadPoolException e) { 82 throwable = e; 83 } catch (NoSuchWorkQueueException e) { 84 throwable = e; 85 } 86 if (throwable != null) { 88 if (orb.transportDebugFlag) { 89 dprint(".handleEvent: " + throwable); 90 } 91 INTERNAL i = new INTERNAL ("NoSuchThreadPoolException"); 92 i.initCause(throwable); 93 throw i; 94 } 95 } else { 96 if (orb.transportDebugFlag) { 97 dprint(".handleEvent: doWork"); 98 } 99 getWork().doWork(); 100 } 101 if (orb.transportDebugFlag) { 102 dprint(".handleEvent<-: " + this); 103 } 104 } 105 106 public boolean shouldUseWorkerThreadForEvent() 107 { 108 return useWorkerThreadForEvent; 109 } 110 111 public void setUseWorkerThreadForEvent(boolean x) 112 { 113 useWorkerThreadForEvent = x; 114 } 115 116 public void setWork(Work work) 117 { 118 this.work = work; 119 } 120 121 public Work getWork() 122 { 123 return work; 124 } 125 126 private void dprint(String msg) 127 { 128 ORBUtility.dprint("EventHandlerBase", msg); 129 } 130 } 131 132 | Popular Tags |