Repository: mina Updated Branches: refs/heads/2.0 4b96641c4 -> c24642913
o Added some missing Javadoc o Fixed some warnings o Fixed a wrong HTML tag in Javadoc Project: http://git-wip-us.apache.org/repos/asf/mina/repo Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/e989f2cf Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/e989f2cf Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/e989f2cf Branch: refs/heads/2.0 Commit: e989f2cfffc7e52b9b2f3e38d8310ad9a8898dbc Parents: 4b96641 Author: Emmanuel Lécharny <elecha...@symas.com> Authored: Mon Dec 5 20:19:48 2016 +0100 Committer: Emmanuel Lécharny <elecha...@symas.com> Committed: Mon Dec 5 20:19:48 2016 +0100 ---------------------------------------------------------------------- .../core/filterchain/DefaultIoFilterChain.java | 233 ++++++++++++++++++- .../DefaultIoFilterChainBuilder.java | 95 +++++++- .../mina/core/filterchain/IoFilterAdapter.java | 20 ++ .../mina/core/filterchain/IoFilterChain.java | 15 +- .../core/filterchain/IoFilterChainBuilder.java | 7 + .../mina/core/filterchain/IoFilterEvent.java | 99 ++++---- .../filterchain/IoFilterLifeCycleException.java | 20 ++ .../CompositeByteArrayRelativeBase.java | 2 +- 8 files changed, 418 insertions(+), 73 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina/blob/e989f2cf/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java b/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java index a843a74..5c38f9d 100644 --- a/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java +++ b/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java @@ -59,7 +59,7 @@ public class DefaultIoFilterChain implements IoFilterChain { private final AbstractIoSession session; /** The mapping between the filters and their associated name */ - private final Map<String, Entry> name2entry = new ConcurrentHashMap<String, Entry>(); + private final Map<String, Entry> name2entry = new ConcurrentHashMap<>(); /** The chain head */ private final EntryImpl head; @@ -68,7 +68,7 @@ public class DefaultIoFilterChain implements IoFilterChain { private final EntryImpl tail; /** The logger for this class */ - private final static Logger LOGGER = LoggerFactory.getLogger(DefaultIoFilterChain.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultIoFilterChain.class); /** * Create a new default chain, associated with a session. It will only contain a @@ -87,10 +87,18 @@ public class DefaultIoFilterChain implements IoFilterChain { head.nextEntry = tail; } + /** + * {@inheritDoc} + */ + @Override public IoSession getSession() { return session; } + /** + * {@inheritDoc} + */ + @Override public Entry getEntry(String name) { Entry e = name2entry.get(name); @@ -101,6 +109,10 @@ public class DefaultIoFilterChain implements IoFilterChain { return e; } + /** + * {@inheritDoc} + */ + @Override public Entry getEntry(IoFilter filter) { EntryImpl e = head.nextEntry; @@ -115,6 +127,10 @@ public class DefaultIoFilterChain implements IoFilterChain { return null; } + /** + * {@inheritDoc} + */ + @Override public Entry getEntry(Class<? extends IoFilter> filterType) { EntryImpl e = head.nextEntry; @@ -129,6 +145,10 @@ public class DefaultIoFilterChain implements IoFilterChain { return null; } + /** + * {@inheritDoc} + */ + @Override public IoFilter get(String name) { Entry e = getEntry(name); @@ -139,6 +159,10 @@ public class DefaultIoFilterChain implements IoFilterChain { return e.getFilter(); } + /** + * {@inheritDoc} + */ + @Override public IoFilter get(Class<? extends IoFilter> filterType) { Entry e = getEntry(filterType); @@ -149,6 +173,10 @@ public class DefaultIoFilterChain implements IoFilterChain { return e.getFilter(); } + /** + * {@inheritDoc} + */ + @Override public NextFilter getNextFilter(String name) { Entry e = getEntry(name); @@ -159,6 +187,10 @@ public class DefaultIoFilterChain implements IoFilterChain { return e.getNextFilter(); } + /** + * {@inheritDoc} + */ + @Override public NextFilter getNextFilter(IoFilter filter) { Entry e = getEntry(filter); @@ -169,6 +201,10 @@ public class DefaultIoFilterChain implements IoFilterChain { return e.getNextFilter(); } + /** + * {@inheritDoc} + */ + @Override public NextFilter getNextFilter(Class<? extends IoFilter> filterType) { Entry e = getEntry(filterType); @@ -179,34 +215,59 @@ public class DefaultIoFilterChain implements IoFilterChain { return e.getNextFilter(); } + /** + * {@inheritDoc} + */ + @Override public synchronized void addFirst(String name, IoFilter filter) { checkAddable(name); register(head, name, filter); } + /** + * {@inheritDoc} + */ + @Override public synchronized void addLast(String name, IoFilter filter) { checkAddable(name); register(tail.prevEntry, name, filter); } + /** + * {@inheritDoc} + */ + @Override public synchronized void addBefore(String baseName, String name, IoFilter filter) { EntryImpl baseEntry = checkOldName(baseName); checkAddable(name); register(baseEntry.prevEntry, name, filter); } + /** + * {@inheritDoc} + */ + @Override public synchronized void addAfter(String baseName, String name, IoFilter filter) { EntryImpl baseEntry = checkOldName(baseName); checkAddable(name); register(baseEntry, name, filter); } + /** + * {@inheritDoc} + */ + @Override public synchronized IoFilter remove(String name) { EntryImpl entry = checkOldName(name); deregister(entry); + return entry.getFilter(); } + /** + * {@inheritDoc} + */ + @Override public synchronized void remove(IoFilter filter) { EntryImpl e = head.nextEntry; @@ -223,6 +284,10 @@ public class DefaultIoFilterChain implements IoFilterChain { throw new IllegalArgumentException("Filter not found: " + filter.getClass().getName()); } + /** + * {@inheritDoc} + */ + @Override public synchronized IoFilter remove(Class<? extends IoFilter> filterType) { EntryImpl e = head.nextEntry; @@ -240,6 +305,10 @@ public class DefaultIoFilterChain implements IoFilterChain { throw new IllegalArgumentException("Filter not found: " + filterType.getName()); } + /** + * {@inheritDoc} + */ + @Override public synchronized IoFilter replace(String name, IoFilter newFilter) { EntryImpl entry = checkOldName(name); IoFilter oldFilter = entry.getFilter(); @@ -265,6 +334,10 @@ public class DefaultIoFilterChain implements IoFilterChain { return oldFilter; } + /** + * {@inheritDoc} + */ + @Override public synchronized void replace(IoFilter oldFilter, IoFilter newFilter) { EntryImpl entry = head.nextEntry; @@ -311,6 +384,10 @@ public class DefaultIoFilterChain implements IoFilterChain { throw new IllegalArgumentException("Filter not found: " + oldFilter.getClass().getName()); } + /** + * {@inheritDoc} + */ + @Override public synchronized IoFilter replace(Class<? extends IoFilter> oldFilterType, IoFilter newFilter) { EntryImpl entry = head.nextEntry; @@ -357,8 +434,12 @@ public class DefaultIoFilterChain implements IoFilterChain { throw new IllegalArgumentException("Filter not found: " + oldFilterType.getName()); } + /** + * {@inheritDoc} + */ + @Override public synchronized void clear() throws Exception { - List<IoFilterChain.Entry> l = new ArrayList<IoFilterChain.Entry>(name2entry.values()); + List<IoFilterChain.Entry> l = new ArrayList<>(name2entry.values()); for (IoFilterChain.Entry entry : l) { try { @@ -448,6 +529,10 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public void fireSessionCreated() { callNextSessionCreated(head, session); } @@ -465,6 +550,10 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public void fireSessionOpened() { callNextSessionOpened(head, session); } @@ -482,6 +571,10 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public void fireSessionClosed() { // Update future. try { @@ -502,13 +595,15 @@ public class DefaultIoFilterChain implements IoFilterChain { IoFilter filter = entry.getFilter(); NextFilter nextFilter = entry.getNextFilter(); filter.sessionClosed(nextFilter, session); - } catch (Exception e) { - fireExceptionCaught(e); - } catch (Error e) { + } catch (Exception | Error e) { fireExceptionCaught(e); } } + /** + * {@inheritDoc} + */ + @Override public void fireSessionIdle(IdleStatus status) { session.increaseIdleCount(status, System.currentTimeMillis()); callNextSessionIdle(head, session, status); @@ -527,6 +622,10 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public void fireMessageReceived(Object message) { if (message instanceof IoBuffer) { session.increaseReadBytes(((IoBuffer) message).remaining(), System.currentTimeMillis()); @@ -548,6 +647,10 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public void fireMessageSent(WriteRequest request) { try { request.getFuture().setWritten(); @@ -576,6 +679,10 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public void fireExceptionCaught(Throwable cause) { callNextExceptionCaught(head, session, cause); } @@ -603,6 +710,10 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public void fireInputClosed() { Entry head = this.head; callNextInputClosed(head, session); @@ -618,7 +729,11 @@ public class DefaultIoFilterChain implements IoFilterChain { } } - public void fireFilterWrite(WriteRequest writeRequest) { + /** + * {@inheritDoc} + */ + @Override +public void fireFilterWrite(WriteRequest writeRequest) { callPreviousFilterWrite(tail, session, writeRequest); } @@ -637,6 +752,10 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public void fireFilterClose() { callPreviousFilterClose(tail, session); } @@ -654,8 +773,12 @@ public class DefaultIoFilterChain implements IoFilterChain { } } + /** + * {@inheritDoc} + */ + @Override public List<Entry> getAll() { - List<Entry> list = new ArrayList<Entry>(); + List<Entry> list = new ArrayList<>(); EntryImpl e = head.nextEntry; while (e != tail) { @@ -666,8 +789,12 @@ public class DefaultIoFilterChain implements IoFilterChain { return list; } + /** + * {@inheritDoc} + */ + @Override public List<Entry> getAllReversed() { - List<Entry> list = new ArrayList<Entry>(); + List<Entry> list = new ArrayList<>(); EntryImpl e = tail.prevEntry; while (e != head) { @@ -678,14 +805,26 @@ public class DefaultIoFilterChain implements IoFilterChain { return list; } + /** + * {@inheritDoc} + */ + @Override public boolean contains(String name) { return getEntry(name) != null; } + /** + * {@inheritDoc} + */ + @Override public boolean contains(IoFilter filter) { return getEntry(filter) != null; } + /** + * {@inheritDoc} + */ + @Override public boolean contains(Class<? extends IoFilter> filterType) { return getEntry(filterType) != null; } @@ -842,9 +981,7 @@ public class DefaultIoFilterChain implements IoFilterChain { public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { AbstractIoSession s = (AbstractIoSession) session; - if (!(message instanceof IoBuffer)) { - s.increaseReadMessages(System.currentTimeMillis()); - } else if (!((IoBuffer) message).hasRemaining()) { + if (!(message instanceof IoBuffer) || !((IoBuffer) message).hasRemaining()) { s.increaseReadMessages(System.currentTimeMillis()); } @@ -912,66 +1049,118 @@ public class DefaultIoFilterChain implements IoFilterChain { this.name = name; this.filter = filter; this.nextFilter = new NextFilter() { + /** + * {@inheritDoc} + */ + @Override public void sessionCreated(IoSession session) { Entry nextEntry = EntryImpl.this.nextEntry; callNextSessionCreated(nextEntry, session); } + /** + * {@inheritDoc} + */ + @Override public void sessionOpened(IoSession session) { Entry nextEntry = EntryImpl.this.nextEntry; callNextSessionOpened(nextEntry, session); } + /** + * {@inheritDoc} + */ + @Override public void sessionClosed(IoSession session) { Entry nextEntry = EntryImpl.this.nextEntry; callNextSessionClosed(nextEntry, session); } + /** + * {@inheritDoc} + */ + @Override public void sessionIdle(IoSession session, IdleStatus status) { Entry nextEntry = EntryImpl.this.nextEntry; callNextSessionIdle(nextEntry, session, status); } + /** + * {@inheritDoc} + */ + @Override public void exceptionCaught(IoSession session, Throwable cause) { Entry nextEntry = EntryImpl.this.nextEntry; callNextExceptionCaught(nextEntry, session, cause); } + /** + * {@inheritDoc} + */ + @Override public void inputClosed(IoSession session) { Entry nextEntry = EntryImpl.this.nextEntry; callNextInputClosed(nextEntry, session); } + /** + * {@inheritDoc} + */ + @Override public void messageReceived(IoSession session, Object message) { Entry nextEntry = EntryImpl.this.nextEntry; callNextMessageReceived(nextEntry, session, message); } + /** + * {@inheritDoc} + */ + @Override public void messageSent(IoSession session, WriteRequest writeRequest) { Entry nextEntry = EntryImpl.this.nextEntry; callNextMessageSent(nextEntry, session, writeRequest); } + /** + * {@inheritDoc} + */ + @Override public void filterWrite(IoSession session, WriteRequest writeRequest) { Entry nextEntry = EntryImpl.this.prevEntry; callPreviousFilterWrite(nextEntry, session, writeRequest); } + /** + * {@inheritDoc} + */ + @Override public void filterClose(IoSession session) { Entry nextEntry = EntryImpl.this.prevEntry; callPreviousFilterClose(nextEntry, session); } + /** + * {@inheritDoc} + */ + @Override public String toString() { return EntryImpl.this.nextEntry.name; } }; } + /** + * {@inheritDoc} + */ + @Override public String getName() { return name; } + /** + * {@inheritDoc} + */ + @Override public IoFilter getFilter() { return filter; } @@ -984,6 +1173,10 @@ public class DefaultIoFilterChain implements IoFilterChain { this.filter = filter; } + /** + * {@inheritDoc} + */ + @Override public NextFilter getNextFilter() { return nextFilter; } @@ -1022,18 +1215,34 @@ public class DefaultIoFilterChain implements IoFilterChain { return sb.toString(); } + /** + * {@inheritDoc} + */ + @Override public void addAfter(String name, IoFilter filter) { DefaultIoFilterChain.this.addAfter(getName(), name, filter); } + /** + * {@inheritDoc} + */ + @Override public void addBefore(String name, IoFilter filter) { DefaultIoFilterChain.this.addBefore(getName(), name, filter); } + /** + * {@inheritDoc} + */ + @Override public void remove() { DefaultIoFilterChain.this.remove(getName()); } + /** + * {@inheritDoc} + */ + @Override public void replace(IoFilter newFilter) { DefaultIoFilterChain.this.replace(getName(), newFilter); } http://git-wip-us.apache.org/repos/asf/mina/blob/e989f2cf/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java b/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java index a8b0c05..bbf3f9e 100644 --- a/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java +++ b/mina-core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java @@ -60,16 +60,17 @@ import org.slf4j.LoggerFactory; * @org.apache.xbean.XBean */ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { + /** The logger */ + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultIoFilterChainBuilder.class); - private final static Logger LOGGER = LoggerFactory.getLogger(DefaultIoFilterChainBuilder.class); - + /** The list of filters */ private final List<Entry> entries; /** * Creates a new instance with an empty filter list. */ public DefaultIoFilterChainBuilder() { - entries = new CopyOnWriteArrayList<Entry>(); + entries = new CopyOnWriteArrayList<>(); } /** @@ -81,7 +82,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { if (filterChain == null) { throw new IllegalArgumentException("filterChain"); } - entries = new CopyOnWriteArrayList<Entry>(filterChain.entries); + entries = new CopyOnWriteArrayList<>(filterChain.entries); } /** @@ -140,6 +141,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { */ public IoFilter get(String name) { Entry e = getEntry(name); + if (e == null) { return null; } @@ -155,6 +157,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { */ public IoFilter get(Class<? extends IoFilter> filterType) { Entry e = getEntry(filterType); + if (e == null) { return null; } @@ -168,7 +171,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { * @return The list of Filters */ public List<Entry> getAll() { - return new ArrayList<Entry>(entries); + return new ArrayList<>(entries); } /** @@ -179,6 +182,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { public List<Entry> getAllReversed() { List<Entry> result = getAll(); Collections.reverse(result); + return result; } @@ -244,6 +248,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { for (ListIterator<Entry> i = entries.listIterator(); i.hasNext();) { Entry base = i.next(); + if (base.getName().equals(baseName)) { register(i.previousIndex(), new EntryImpl(name, filter)); break; @@ -263,6 +268,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { for (ListIterator<Entry> i = entries.listIterator(); i.hasNext();) { Entry base = i.next(); + if (base.getName().equals(baseName)) { register(i.nextIndex(), new EntryImpl(name, filter)); break; @@ -283,8 +289,10 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { for (ListIterator<Entry> i = entries.listIterator(); i.hasNext();) { Entry e = i.next(); + if (e.getName().equals(name)) { entries.remove(i.previousIndex()); + return e.getFilter(); } } @@ -305,8 +313,10 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { for (ListIterator<Entry> i = entries.listIterator(); i.hasNext();) { Entry e = i.next(); + if (e.getFilter() == filter) { entries.remove(i.previousIndex()); + return e.getFilter(); } } @@ -327,8 +337,10 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { for (ListIterator<Entry> i = entries.listIterator(); i.hasNext();) { Entry e = i.next(); + if (filterType.isAssignableFrom(e.getFilter().getClass())) { entries.remove(i.previousIndex()); + return e.getFilter(); } } @@ -336,31 +348,57 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { throw new IllegalArgumentException("Filter not found: " + filterType.getName()); } + /** + * Replace a filter by a new one. + * + * @param name The name of the filter to replace + * @param newFilter The new filter to use + * @return The replaced filter + */ public synchronized IoFilter replace(String name, IoFilter newFilter) { checkBaseName(name); EntryImpl e = (EntryImpl) getEntry(name); IoFilter oldFilter = e.getFilter(); e.setFilter(newFilter); + return oldFilter; } + /** + * Replace a filter by a new one. + * + * @param oldFilter The filter to replace + * @param newFilter The new filter to use + */ public synchronized void replace(IoFilter oldFilter, IoFilter newFilter) { for (Entry e : entries) { if (e.getFilter() == oldFilter) { ((EntryImpl) e).setFilter(newFilter); + return; } } + throw new IllegalArgumentException("Filter not found: " + oldFilter.getClass().getName()); } + /** + * Replace a filter by a new one. We are looking for a filter type, + * but if we have more than one with the same type, only the first + * found one will be replaced + * + * @param oldFilterType The filter type to replace + * @param newFilter The new filter to use + */ public synchronized void replace(Class<? extends IoFilter> oldFilterType, IoFilter newFilter) { for (Entry e : entries) { if (oldFilterType.isAssignableFrom(e.getFilter().getClass())) { ((EntryImpl) e).setFilter(newFilter); + return; } } + throw new IllegalArgumentException("Filter not found: " + oldFilterType.getName()); } @@ -390,11 +428,13 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { + LinkedHashMap.class.getName() + "."); } - filters = new LinkedHashMap<String, IoFilter>(filters); + filters = new LinkedHashMap<>(filters); + for (Map.Entry<String, ? extends IoFilter> e : filters.entrySet()) { if (e.getKey() == null) { throw new IllegalArgumentException("filters contains a null key."); } + if (e.getValue() == null) { throw new IllegalArgumentException("filters contains a null value."); } @@ -402,6 +442,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { synchronized (this) { clear(); + for (Map.Entry<String, ? extends IoFilter> e : filters.entrySet()) { addLast(e.getKey(), e.getValue()); } @@ -434,9 +475,11 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { LOGGER.debug("{} is an ordered map (guessed from that it implements OrderedMap interface.)", mapType.getSimpleName()); } + return true; } } + type = type.getSuperclass(); } @@ -457,11 +500,12 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Failed to create a new map instance of '{}'.", mapType.getName(), e); } + return false; } Random rand = new Random(); - List<String> expectedNames = new ArrayList<String>(); + List<String> expectedNames = new ArrayList<>(); IoFilter dummyFilter = new IoFilterAdapter(); for (int i = 0; i < 65536; i++) { @@ -481,6 +525,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { if (LOGGER.isDebugEnabled()) { LOGGER.debug("The specified map didn't pass the insertion order test after {} tries.", (i + 1)); } + return false; } } @@ -491,12 +536,19 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { return true; } + /** + * {@inheritDoc} + */ + @Override public void buildFilterChain(IoFilterChain chain) throws Exception { for (Entry e : entries) { chain.addLast(e.getName(), e.getFilter()); } } + /** + * {@inheritDoc} + */ @Override public String toString() { StringBuilder buf = new StringBuilder(); @@ -554,6 +606,7 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { if (name == null) { throw new IllegalArgumentException("name"); } + if (filter == null) { throw new IllegalArgumentException("filter"); } @@ -562,10 +615,18 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { this.filter = filter; } + /** + * {@inheritDoc} + */ + @Override public String getName() { return name; } + /** + * {@inheritDoc} + */ + @Override public IoFilter getFilter() { return filter; } @@ -574,6 +635,10 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { this.filter = filter; } + /** + * {@inheritDoc} + */ + @Override public NextFilter getNextFilter() { throw new IllegalStateException(); } @@ -583,18 +648,34 @@ public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder { return "(" + getName() + ':' + filter + ')'; } + /** + * {@inheritDoc} + */ + @Override public void addAfter(String name, IoFilter filter) { DefaultIoFilterChainBuilder.this.addAfter(getName(), name, filter); } + /** + * {@inheritDoc} + */ + @Override public void addBefore(String name, IoFilter filter) { DefaultIoFilterChainBuilder.this.addBefore(getName(), name, filter); } + /** + * {@inheritDoc} + */ + @Override public void remove() { DefaultIoFilterChainBuilder.this.remove(getName()); } + /** + * {@inheritDoc} + */ + @Override public void replace(IoFilter newFilter) { DefaultIoFilterChainBuilder.this.replace(getName(), newFilter); } http://git-wip-us.apache.org/repos/asf/mina/blob/e989f2cf/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterAdapter.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterAdapter.java b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterAdapter.java index 2324b55..424df5c 100644 --- a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterAdapter.java +++ b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterAdapter.java @@ -34,42 +34,49 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void init() throws Exception { } /** * {@inheritDoc} */ + @Override public void destroy() throws Exception { } /** * {@inheritDoc} */ + @Override public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception { } /** * {@inheritDoc} */ + @Override public void onPostAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception { } /** * {@inheritDoc} */ + @Override public void onPreRemove(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception { } /** * {@inheritDoc} */ + @Override public void onPostRemove(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception { } /** * {@inheritDoc} */ + @Override public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception { nextFilter.sessionCreated(session); } @@ -77,6 +84,7 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void sessionOpened(NextFilter nextFilter, IoSession session) throws Exception { nextFilter.sessionOpened(session); } @@ -84,6 +92,7 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception { nextFilter.sessionClosed(session); } @@ -91,6 +100,7 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception { nextFilter.sessionIdle(session, status); } @@ -98,6 +108,7 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) throws Exception { nextFilter.exceptionCaught(session, cause); } @@ -105,6 +116,7 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { nextFilter.messageReceived(session, message); } @@ -112,6 +124,7 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void messageSent(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception { nextFilter.messageSent(session, writeRequest); } @@ -119,6 +132,7 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception { nextFilter.filterWrite(session, writeRequest); } @@ -126,6 +140,7 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void filterClose(NextFilter nextFilter, IoSession session) throws Exception { nextFilter.filterClose(session); } @@ -133,10 +148,15 @@ public class IoFilterAdapter implements IoFilter { /** * {@inheritDoc} */ + @Override public void inputClosed(NextFilter nextFilter, IoSession session) throws Exception { nextFilter.inputClosed(session); } + /** + * {@inheritDoc} + */ + @Override public String toString() { return this.getClass().getSimpleName(); } http://git-wip-us.apache.org/repos/asf/mina/blob/e989f2cf/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChain.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChain.java b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChain.java index 96e26b9..10079fc 100644 --- a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChain.java +++ b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChain.java @@ -222,8 +222,7 @@ public interface IoFilterChain { /** * Replace the filter with the specified name with the specified new filter. * - * @param filter - * The filter to remove + * @param filter The filter to remove */ void remove(IoFilter filter); @@ -232,8 +231,7 @@ public interface IoFilterChain { * If there's more than one filter with the specified type, the first match * will be replaced. * - * @param filterType - * The filter class to remove + * @param filterType The filter class to remove * @return The removed filter */ IoFilter remove(Class<? extends IoFilter> filterType); @@ -280,8 +278,7 @@ public interface IoFilterChain { * users don't need to call this method at all. Please use this method only * when you implement a new transport or fire a virtual event. * - * @param message - * The received message + * @param message The received message */ void fireMessageReceived(Object message); @@ -290,8 +287,7 @@ public interface IoFilterChain { * users don't need to call this method at all. Please use this method only * when you implement a new transport or fire a virtual event. * - * @param request - * The sent request + * @param request The sent request */ void fireMessageSent(WriteRequest request); @@ -316,8 +312,7 @@ public interface IoFilterChain { * call this method at all. Please use this method only when you implement a * new transport or fire a virtual event. * - * @param writeRequest - * The message to write + * @param writeRequest The message to write */ void fireFilterWrite(WriteRequest writeRequest); http://git-wip-us.apache.org/repos/asf/mina/blob/e989f2cf/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChainBuilder.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChainBuilder.java b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChainBuilder.java index 3cec9fc..50b3b2c 100644 --- a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChainBuilder.java +++ b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterChainBuilder.java @@ -41,9 +41,16 @@ public interface IoFilterChainBuilder { * An implementation which does nothing. */ IoFilterChainBuilder NOOP = new IoFilterChainBuilder() { + /** + * {@inheritDoc} + */ + @Override public void buildFilterChain(IoFilterChain chain) throws Exception { } + /** + * {@inheritDoc} + */ @Override public String toString() { return "NOOP"; http://git-wip-us.apache.org/repos/asf/mina/blob/e989f2cf/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterEvent.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterEvent.java b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterEvent.java index 035fe9a..7725619 100644 --- a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterEvent.java +++ b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterEvent.java @@ -44,6 +44,14 @@ public class IoFilterEvent extends IoEvent { private final NextFilter nextFilter; + /** + * Creates a new IoFilterEvent instance + * + * @param nextFilter The next Filter + * @param type The type of event + * @param session The current session + * @param parameter Any parameter + */ public IoFilterEvent(NextFilter nextFilter, IoEventType type, IoSession session, Object parameter) { super(type, session, parameter); @@ -54,14 +62,19 @@ public class IoFilterEvent extends IoEvent { this.nextFilter = nextFilter; } + /** + * @return The next filter + */ public NextFilter getNextFilter() { return nextFilter; } + /** + * {@inheritDoc} + */ @Override public void fire() { IoSession session = getSession(); - NextFilter nextFilter = getNextFilter(); IoEventType type = getType(); if (DEBUG) { @@ -69,48 +82,48 @@ public class IoFilterEvent extends IoEvent { } switch (type) { - case MESSAGE_RECEIVED: - Object parameter = getParameter(); - nextFilter.messageReceived(session, parameter); - break; - - case MESSAGE_SENT: - WriteRequest writeRequest = (WriteRequest) getParameter(); - nextFilter.messageSent(session, writeRequest); - break; - - case WRITE: - writeRequest = (WriteRequest) getParameter(); - nextFilter.filterWrite(session, writeRequest); - break; - - case CLOSE: - nextFilter.filterClose(session); - break; - - case EXCEPTION_CAUGHT: - Throwable throwable = (Throwable) getParameter(); - nextFilter.exceptionCaught(session, throwable); - break; - - case SESSION_IDLE: - nextFilter.sessionIdle(session, (IdleStatus) getParameter()); - break; - - case SESSION_OPENED: - nextFilter.sessionOpened(session); - break; - - case SESSION_CREATED: - nextFilter.sessionCreated(session); - break; - - case SESSION_CLOSED: - nextFilter.sessionClosed(session); - break; - - default: - throw new IllegalArgumentException("Unknown event type: " + type); + case MESSAGE_RECEIVED: + Object parameter = getParameter(); + nextFilter.messageReceived(session, parameter); + break; + + case MESSAGE_SENT: + WriteRequest writeRequest = (WriteRequest) getParameter(); + nextFilter.messageSent(session, writeRequest); + break; + + case WRITE: + writeRequest = (WriteRequest) getParameter(); + nextFilter.filterWrite(session, writeRequest); + break; + + case CLOSE: + nextFilter.filterClose(session); + break; + + case EXCEPTION_CAUGHT: + Throwable throwable = (Throwable) getParameter(); + nextFilter.exceptionCaught(session, throwable); + break; + + case SESSION_IDLE: + nextFilter.sessionIdle(session, (IdleStatus) getParameter()); + break; + + case SESSION_OPENED: + nextFilter.sessionOpened(session); + break; + + case SESSION_CREATED: + nextFilter.sessionCreated(session); + break; + + case SESSION_CLOSED: + nextFilter.sessionClosed(session); + break; + + default: + throw new IllegalArgumentException("Unknown event type: " + type); } if (DEBUG) { http://git-wip-us.apache.org/repos/asf/mina/blob/e989f2cf/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterLifeCycleException.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterLifeCycleException.java b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterLifeCycleException.java index c0c5fd9..f389705 100644 --- a/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterLifeCycleException.java +++ b/mina-core/src/main/java/org/apache/mina/core/filterchain/IoFilterLifeCycleException.java @@ -29,17 +29,37 @@ package org.apache.mina.core.filterchain; public class IoFilterLifeCycleException extends RuntimeException { private static final long serialVersionUID = -5542098881633506449L; + /** + * Creates a new IoFilterLifeCycleException instance + */ public IoFilterLifeCycleException() { + // Default exception } + /** + * Creates a new IoFilterLifeCycleException instance + * + * @param message The error message + */ public IoFilterLifeCycleException(String message) { super(message); } + /** + * Creates a new IoFilterLifeCycleException instance + * + * @param message The error message + * @param cause The original error cause + */ public IoFilterLifeCycleException(String message, Throwable cause) { super(message, cause); } + /** + * Creates a new IoFilterLifeCycleException instance + * + * @param cause The original error cause + */ public IoFilterLifeCycleException(Throwable cause) { super(cause); } http://git-wip-us.apache.org/repos/asf/mina/blob/e989f2cf/mina-core/src/main/java/org/apache/mina/util/byteaccess/CompositeByteArrayRelativeBase.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/util/byteaccess/CompositeByteArrayRelativeBase.java b/mina-core/src/main/java/org/apache/mina/util/byteaccess/CompositeByteArrayRelativeBase.java index 370ab48..634984f 100644 --- a/mina-core/src/main/java/org/apache/mina/util/byteaccess/CompositeByteArrayRelativeBase.java +++ b/mina-core/src/main/java/org/apache/mina/util/byteaccess/CompositeByteArrayRelativeBase.java @@ -99,7 +99,7 @@ abstract class CompositeByteArrayRelativeBase { } /** - * @return <T>TRUE</T> if there are some more bytes + * @return <TT>TRUE</TT> if there are some more bytes */ public final boolean hasRemaining() { return cursor.hasRemaining();