/** * Constructor which sets buffer size to <code>bufferSize</code>. If * <code>buffersMap</code> is null then a default instance of {@link ConcurrentHashMap} * is created else the provided instance is used. * * @param bufferSize the new buffer size * @param buffersMap the map to use for storing each session buffer */ public BufferedWriteFilter(int bufferSize, LazyInitializedCacheMap<IoSession, IoBuffer> buffersMap) { super(); this.bufferSize = bufferSize; if (buffersMap == null) { this.buffersMap = new LazyInitializedCacheMap<IoSession, IoBuffer>(); } else { this.buffersMap = buffersMap; } }
/** * Internal method that actually frees the {@link IoBuffer} that contains * the buffered data that has not been flushed. * * @param session the session we operate on */ private void free(IoSession session) { IoBuffer buf = buffersMap.remove(session); if (buf != null) { buf.free(); } }
/** * Flushes the buffered data. * * @param session the session where buffer will be written */ public void flush(IoSession session) { try { internalFlush(session.getFilterChain().getNextFilter(this), session, buffersMap.get(session)); } catch (Exception e) { session.getFilterChain().fireExceptionCaught(e); } }
/** * Writes an {@link IoBuffer} to the session's buffer. * * @param session the session to which a write is requested * @param data the data to buffer */ private void write(IoSession session, IoBuffer data) { IoBuffer dest = buffersMap.putIfAbsent(session, new IoBufferLazyInitializer(bufferSize)); write(session, data, dest); }
/** * Flushes the buffered data. * * @param session the session where buffer will be written */ public void flush(IoSession session) { try { internalFlush(session.getFilterChain().getNextFilter(this), session, buffersMap.get(session)); } catch (Exception e) { session.getFilterChain().fireExceptionCaught(e); } }
/** * Writes an {@link IoBuffer} to the session's buffer. * * @param session the session to which a write is requested * @param data the data to buffer */ private void write(IoSession session, IoBuffer data) { IoBuffer dest = buffersMap.putIfAbsent(session, new IoBufferLazyInitializer(bufferSize)); write(session, data, dest); }
/** * Flushes the buffered data. * * @param session the session where buffer will be written */ public void flush(IoSession session) { try { internalFlush(session.getFilterChain().getNextFilter(this), session, buffersMap.get(session)); } catch (Throwable e) { session.getFilterChain().fireExceptionCaught(e); } }
/** * Internal method that actually frees the {@link IoBuffer} that contains * the buffered data that has not been flushed. * * @param session the session we operate on */ private void free(IoSession session) { IoBuffer buf = buffersMap.remove(session); if (buf != null) { buf.free(); } }
/** * Writes an {@link IoBuffer} to the session's buffer. * * @param session the session to which a write is requested * @param data the data to buffer */ private void write(IoSession session, IoBuffer data) { IoBuffer dest = buffersMap.putIfAbsent(session, new IoBufferLazyInitializer(bufferSize)); write(session, data, dest); }
/** * Constructor which sets buffer size to <code>bufferSize</code>. If * <code>buffersMap</code> is null then a default instance of {@link ConcurrentHashMap} * is created else the provided instance is used. * * @param bufferSize the new buffer size * @param buffersMap the map to use for storing each session buffer */ public BufferedWriteFilter(int bufferSize, LazyInitializedCacheMap<IoSession, IoBuffer> buffersMap) { super(); this.bufferSize = bufferSize; if (buffersMap == null) { this.buffersMap = new LazyInitializedCacheMap<IoSession, IoBuffer>(); } else { this.buffersMap = buffersMap; } }
/** * Internal method that actually frees the {@link IoBuffer} that contains * the buffered data that has not been flushed. * * @param session the session we operate on */ private void free(IoSession session) { IoBuffer buf = buffersMap.remove(session); if (buf != null) { buf.free(); } }
/** * Constructor which sets buffer size to <code>bufferSize</code>. If * <code>buffersMap</code> is null then a default instance of {@link ConcurrentHashMap} * is created else the provided instance is used. * * @param bufferSize the new buffer size * @param buffersMap the map to use for storing each session buffer */ public BufferedWriteFilter(int bufferSize, LazyInitializedCacheMap<IoSession, IoBuffer> buffersMap) { super(); this.bufferSize = bufferSize; if (buffersMap == null) { this.buffersMap = new LazyInitializedCacheMap<>(); } else { this.buffersMap = buffersMap; } }