public boolean dispatchForEvent(NioChannel socket, SocketStatus status, boolean dispatch) { if (dispatch && status == SocketStatus.OPEN_READ) { socket.getPoller().add(socket, OP_CALLBACK); } else { processSocket(socket,status,dispatch); } return true; }
public Object getAttachment(boolean remove) { Poller pol = getPoller(); Selector sel = pol!=null?pol.getSelector():null; SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null; Object att = key!=null?key.attachment():null; if (key != null && att != null && remove ) key.attach(null); return att; }
public Object getAttachment(boolean remove) { Poller pol = getPoller(); Selector sel = pol!=null?pol.getSelector():null; SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null; Object att = key!=null?key.attachment():null; if (key != null && att != null && remove ) key.attach(null); return att; } /**
public Object getAttachment(boolean remove) { Poller pol = getPoller(); Selector sel = pol!=null?pol.getSelector():null; SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null; Object att = key!=null?key.attachment():null; if (key != null && att != null && remove ) key.attach(null); return att; } /**
public Object getAttachment(boolean remove) { Poller pol = getPoller(); Selector sel = pol!=null?pol.getSelector():null; SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null; Object att = key!=null?key.attachment():null; if (key != null && att != null && remove ) key.attach(null); return att; } /**
public Object getAttachment(boolean remove) { Poller pol = getPoller(); Selector sel = pol!=null?pol.getSelector():null; SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null; Object att = key!=null?key.attachment():null; if (key != null && att != null && remove ) key.attach(null); return att; } /**
public Object getAttachment() { Poller pol = getPoller(); Selector sel = pol!=null?pol.getSelector():null; SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null; Object att = key!=null?key.attachment():null; return att; }
@Override public SendfileState processSendfile(SendfileDataBase sendfileData) { setSendfileData((SendfileData) sendfileData); SelectionKey key = getSocket().getIOChannel().keyFor( getSocket().getPoller().getSelector()); // Might as well do the first write on this thread return getSocket().getPoller().processSendfile(key, this, true); }
@Override protected boolean breakKeepAliveLoop( SocketWrapper<NioChannel> socketWrapper) { // Do sendfile as needed: add socket to sendfile and end if (sendfileData != null && !error) { ((KeyAttachment) socketWrapper).setSendfileData(sendfileData); sendfileData.keepAlive = keepAlive; SelectionKey key = socketWrapper.getSocket().getIOChannel().keyFor( socketWrapper.getSocket().getPoller().getSelector()); //do the first write on this thread, might as well openSocket = socketWrapper.getSocket().getPoller().processSendfile(key, (KeyAttachment) socketWrapper, true); return true; } return false; }
@Override protected boolean breakKeepAliveLoop( SocketWrapper<NioChannel> socketWrapper) { // Do sendfile as needed: add socket to sendfile and end if (sendfileData != null && !error) { ((KeyAttachment) socketWrapper).setSendfileData(sendfileData); sendfileData.keepAlive = keepAlive; SelectionKey key = socketWrapper.getSocket().getIOChannel().keyFor( socketWrapper.getSocket().getPoller().getSelector()); //do the first write on this thread, might as well openSocket = socketWrapper.getSocket().getPoller().processSendfile(key, (KeyAttachment) socketWrapper, true, true); return true; } return false; }
@Override protected boolean breakKeepAliveLoop( SocketWrapper<NioChannel> socketWrapper) { // Do sendfile as needed: add socket to sendfile and end if (sendfileData != null && !error) { ((KeyAttachment) socketWrapper).setSendfileData(sendfileData); sendfileData.keepAlive = keepAlive; SelectionKey key = socketWrapper.getSocket().getIOChannel().keyFor( socketWrapper.getSocket().getPoller().getSelector()); //do the first write on this thread, might as well openSocket = socketWrapper.getSocket().getPoller().processSendfile(key, (KeyAttachment) socketWrapper, true); return true; } return false; }
@Override protected void longPoll(SocketWrapper<NioChannel> socket, Processor<NioChannel> processor) { connections.put(socket.getSocket(), processor); if (processor.isAsync()) { socket.setAsync(true); } else { // Either: // - this is comet request // - this is an upgraded connection // - the request line/headers have not been completely // read socket.getSocket().getPoller().add(socket.getSocket()); } }
/** * Expected to be used by the handler once the processor is no longer * required. */ @Override public void release(SocketWrapper<NioChannel> socket, Processor<NioChannel> processor, boolean isSocketClosing, boolean addToPoller) { processor.recycle(isSocketClosing); recycledProcessors.push(processor); if (addToPoller) { socket.getSocket().getPoller().add(socket.getSocket()); } }
/** * Expected to be used by the handler once the processor is no longer * required. */ @Override public void release(SocketWrapper<NioChannel> socket, Processor<NioChannel> processor, boolean isSocketClosing, boolean addToPoller) { processor.recycle(isSocketClosing); recycledProcessors.offer(processor); if (addToPoller) { socket.getSocket().getPoller().add(socket.getSocket()); } }
@Override protected void longPoll(SocketWrapper<NioChannel> socket, Processor<NioChannel> processor) { if (processor.isAsync()) { socket.setAsync(true); } else { // Either: // - this is comet request // - this is an upgraded connection // - the request line/headers have not been completely // read socket.getSocket().getPoller().add(socket.getSocket()); } }
/** * Expected to be used by the handler once the processor is no longer * required. */ @Override public void release(SocketWrapper<NioChannel> socket, AjpNioProcessor processor, boolean isSocketClosing, boolean addToPoller) { processor.recycle(isSocketClosing); recycledProcessors.offer(processor); if (addToPoller) { socket.getSocket().getPoller().add(socket.getSocket()); } }
/** * Callback to write data from the buffer. */ protected void flushBuffer() throws IOException { //prevent timeout for async, SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); if (key != null) { NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment(); attach.access(); } //write to the socket, if there is anything to write if (socket.getBufHandler().getWriteBuffer().position() > 0) { socket.getBufHandler().getWriteBuffer().flip(); writeToSocket(socket.getBufHandler().getWriteBuffer(),true, false); } }
/** * Callback to write data from the buffer. */ protected void flushBuffer() throws IOException { //prevent timeout for async, SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); if (key != null) { NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment(); attach.access(); } //write to the socket, if there is anything to write if (socket.getBufHandler().getWriteBuffer().position() > 0) { socket.getBufHandler().getWriteBuffer().flip(); writeToSocket(socket.getBufHandler().getWriteBuffer(),true, false); } }
/** * Callback to write data from the buffer. */ private void flushBuffer() throws IOException { //prevent timeout for async, SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); if (key != null) { NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment(); attach.access(); } //write to the socket, if there is anything to write if (socket.getBufHandler().getWriteBuffer().position() > 0) { socket.getBufHandler().getWriteBuffer().flip(); writeToSocket(socket.getBufHandler().getWriteBuffer(),true, false); } }
/** * Callback to write data from the buffer. */ private void flushBuffer() throws IOException { //prevent timeout for async, SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); if (key != null) { NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment(); attach.access(); } //write to the socket, if there is anything to write if (socket.getBufHandler().getWriteBuffer().position() > 0) { socket.getBufHandler().getWriteBuffer().flip(); writeToSocket(socket.getBufHandler().getWriteBuffer(),true, false); } }