Changeset 427
- Timestamp:
- 07/17/07 07:11:02 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
experiments/jruby-1/src/com/rubyeventmachine/EM.java
r425 r427 54 54 private ByteBuffer EmptyByteBuffer; 55 55 private AtomicBoolean loopBreaker; 56 56 private ByteBuffer myReadBuffer; 57 private int timerQuantum; 57 58 58 59 public EM() { … … 63 64 loopBreaker = new AtomicBoolean(); 64 65 loopBreaker.set(false); 66 myReadBuffer = ByteBuffer.allocateDirect(32*1024); 67 timerQuantum = 98; 65 68 } 66 69 … … 98 101 runTimers(); 99 102 if (!bRunReactor) break; 100 mySelector.select( 200); // TODO, timer quantum needs to be configurable.103 mySelector.select(timerQuantum); 101 104 102 105 Iterator<SelectionKey> it = mySelector.selectedKeys().iterator(); … … 120 123 if (k.isReadable()) { 121 124 SocketChannel sn = (SocketChannel) k.channel(); 122 ByteBuffer bb = ByteBuffer.allocate(16 * 1024); // TODO. Preallocate and reuse the buffer. 125 ByteBuffer bb = ByteBuffer.allocate(16 * 1024); 126 // Obviously not thread-safe, since we're using the same buffer for every connection. 127 // This should minimize the production of garbage, though. 128 // TODO, we need somehow to make a call to the EventableChannel, so we can pass the 129 // inbound data through an SSLEngine. Hope that won't break the strategy of using one 130 // global read-buffer. 131 //myReadBuffer.clear(); 123 132 int r = sn.read(bb); 124 133 if (r > 0) { 125 134 bb.flip(); 126 bb = ((EventableChannel)k.attachment()).dispatchInboundData (bb);135 //bb = ((EventableChannel)k.attachment()).dispatchInboundData (bb); 127 136 eventCallback (((EventableChannel)k.attachment()).getBinding(), EM_CONNECTION_READ, bb); 128 137 } … … 269 278 Connections.get(sig).startTls(); 270 279 } 280 281 public void setTimerQuantum (int mills) { 282 if (mills < 5 || mills > 2500) 283 throw new RuntimeException ("attempt to set invalid timer-quantum value: "+mills); 284 timerQuantum = mills; 285 } 271 286 }