Fix class references of its subclass issue

Motivation:

Realization of `AbstractTrafficShapingHandler.userDefinedWritabilityIndex()` has references to subclasses.
In addition, one of the subclasses overriding it, but the other does not.

Modifications:

Add overriding to the second subclass. Remove references to subclasses from parent class.

Result:

More consistent and clean code (OOP-stylish).
This commit is contained in:
Nikolay Fedorovskikh 2017-02-25 23:19:31 +05:00 committed by Norman Maurer
parent 22ccf6c7b1
commit c0cd3db5b1
2 changed files with 6 additions and 7 deletions

View File

@ -146,13 +146,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler
* {@value #GLOBALCHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX}. * {@value #GLOBALCHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX}.
*/ */
protected int userDefinedWritabilityIndex() { protected int userDefinedWritabilityIndex() {
if (this instanceof GlobalChannelTrafficShapingHandler) { return CHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX;
return GLOBALCHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX;
} else if (this instanceof GlobalTrafficShapingHandler) {
return GLOBAL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX;
} else {
return CHANNEL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX;
}
} }
/** /**

View File

@ -111,6 +111,11 @@ public class GlobalTrafficShapingHandler extends AbstractTrafficShapingHandler {
tc.start(); tc.start();
} }
@Override
protected int userDefinedWritabilityIndex() {
return AbstractTrafficShapingHandler.GLOBAL_DEFAULT_USER_DEFINED_WRITABILITY_INDEX;
}
/** /**
* Create a new instance. * Create a new instance.
* *