protected void destroy(NioSession session) throws IOException { ByteChannel ch = session.getChannel(); SelectionKey key = session.getSelectionKey(); if (key != null) { key.cancel(); } ch.close(); }
/** * {@inheritDoc} */ @Override public InetSocketAddress getServiceAddress() { return (InetSocketAddress) super.getServiceAddress(); } }
@Override protected void init(NioSession session) throws Exception { SelectableChannel ch = (SelectableChannel) session.getChannel(); ch.configureBlocking(false); session.setSelectionKey(ch.register(selector, SelectionKey.OP_READ, session)); }
private boolean flush(NioSession session, long currentTime) throws Exception { final WriteRequestQueue writeRequestQueue = session.getWriteRequestQueue(); final int maxWrittenBytes = session.getConfig().getMaxReadBufferSize() + (session.getConfig().getMaxReadBufferSize() >>> 1); WriteRequest req = session.getCurrentWriteRequest(); session.setCurrentWriteRequest(req); session.setCurrentWriteRequest(null); buf.reset(); session.getFilterChain().fireMessageSent(req); continue; destination = session.getRemoteAddress(); session.setCurrentWriteRequest(null); writtenBytes += localWrittenBytes; buf.reset(); session.getFilterChain().fireMessageSent(req); session.increaseWrittenBytes(writtenBytes, currentTime);
@Override protected boolean isInterestedInRead(NioSession session) { SelectionKey key = session.getSelectionKey(); return (key != null) && key.isValid() && ((key.interestOps() & SelectionKey.OP_READ) != 0); }
@Override protected int transferFile(NioSession session, FileRegion region, int length) throws Exception { try { return (int) region.getFileChannel().transferTo(region.getPosition(), length, session.getChannel()); } catch (IOException e) { // Check to see if the IOException is being thrown due to // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5103988 String message = e.getMessage(); if ((message != null) && message.contains("temporarily unavailable")) { return 0; } throw e; } }
private void flushSessions(long currentTime) { for (;;) { NioSession session = flushingSessions.poll(); if (session == null) { break; } // Reset the Schedule for flush flag for this session, // as we are flushing it now session.unscheduledForFlush(); try { boolean flushedAll = flush(session, currentTime); if (flushedAll && !session.getWriteRequestQueue().isEmpty(session) && !session.isScheduledForFlush()) { scheduleFlush(session); } } catch (Exception e) { session.getFilterChain().fireExceptionCaught(e); } } }
/** * {@inheritDoc} */ @Override protected NioSession newSession(IoProcessor<NioSession> processor, DatagramChannel handle) { NioSession session = new NioDatagramSession(this, handle, processor); session.getConfig().setAll(getSessionConfig()); return session; }
session.setSelectionKey(newKey);
private boolean flush(NioSession session, long currentTime) throws Exception { final WriteRequestQueue writeRequestQueue = session.getWriteRequestQueue(); final int maxWrittenBytes = session.getConfig().getMaxReadBufferSize() + (session.getConfig().getMaxReadBufferSize() >>> 1); WriteRequest req = session.getCurrentWriteRequest(); session.setCurrentWriteRequest(req); session.setCurrentWriteRequest(null); buf.reset(); session.getFilterChain().fireMessageSent(req); continue; destination = session.getRemoteAddress(); session.setCurrentWriteRequest(null); writtenBytes += localWrittenBytes; buf.reset(); session.getFilterChain().fireMessageSent(req); session.increaseWrittenBytes(writtenBytes, currentTime);
@Override protected boolean isReadable(NioSession session) { SelectionKey key = session.getSelectionKey(); return (key != null) && key.isValid() && key.isReadable(); }
@Override protected int transferFile(NioSession session, FileRegion region, int length) throws Exception { try { return (int) region.getFileChannel().transferTo(region.getPosition(), length, session.getChannel()); } catch (IOException e) { // Check to see if the IOException is being thrown due to // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5103988 String message = e.getMessage(); if ((message != null) && message.contains("temporarily unavailable")) { return 0; } throw e; } }
private void flushSessions(long currentTime) { for (;;) { NioSession session = flushingSessions.poll(); if (session == null) { break; } // Reset the Schedule for flush flag for this session, // as we are flushing it now session.unscheduledForFlush(); try { boolean flushedAll = flush(session, currentTime); if (flushedAll && !session.getWriteRequestQueue().isEmpty(session) && !session.isScheduledForFlush()) { scheduleFlush(session); } } catch (Exception e) { session.getFilterChain().fireExceptionCaught(e); } } }
/** * {@inheritDoc} */ @Override protected NioSession newSession(IoProcessor<NioSession> processor, DatagramChannel handle) { NioSession session = new NioDatagramSession(this, handle, processor); session.getConfig().setAll(getSessionConfig()); return session; }
session.setSelectionKey(newKey);
final WriteRequestQueue writeRequestQueue = session.getWriteRequestQueue(); final int maxWrittenBytes = session.getConfig().getMaxReadBufferSize() + (session.getConfig().getMaxReadBufferSize() >>> 1); session.setCurrentWriteRequest(null); buf.reset(); session.getFilterChain().fireMessageSent(writeRequest); return; session.setCurrentWriteRequest(writeRequest); session.setCurrentWriteRequest(null); buf.reset(); session.getFilterChain().fireMessageSent(writeRequest); continue; destination = session.getRemoteAddress(); session.getWriteRequestQueue().offer(session, writeRequest); scheduleFlush(session); } else { session.setCurrentWriteRequest(null); writtenBytes += localWrittenBytes; buf.reset(); session.getFilterChain().fireMessageSent(writeRequest); session.getFilterChain().fireExceptionCaught(e); } finally {
@Override protected boolean isWritable(NioSession session) { SelectionKey key = session.getSelectionKey(); return (key != null) && key.isValid() && key.isWritable(); }
protected void destroy(NioSession session) throws IOException { ByteChannel ch = session.getChannel(); SelectionKey key = session.getSelectionKey(); if (key != null) { key.cancel(); } ch.close(); }
@Override protected int transferFile(NioSession session, FileRegion region, int length) throws Exception { try { return (int) region.getFileChannel().transferTo(region.getPosition(), length, session.getChannel()); } catch (IOException e) { // Check to see if the IOException is being thrown due to // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5103988 String message = e.getMessage(); if (message != null && message.contains("temporarily unavailable")) { return 0; } throw e; } }
@Override protected void init(NioSession session) throws Exception { SelectableChannel ch = (SelectableChannel) session.getChannel(); ch.configureBlocking(false); selectorLock.readLock().lock(); try { session.setSelectionKey(ch.register(selector, SelectionKey.OP_READ, session)); } finally { selectorLock.readLock().unlock(); } }