Author: trustin
Date: Sun Nov 4 18:03:44 2007
New Revision: 591865
URL: http://svn.apache.org/viewvc?rev=591865&view=rev
Log:
Related issue: DIRMINA-144 (Traffic shaping filter)
* More precise traffic control by adjusting MaxReadBufferSize as soon as
possible.
Modified:
mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/TrafficShapingFilter.java
Modified:
mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/TrafficShapingFilter.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/TrafficShapingFilter.java?rev=591865&r1=591864&r2=591865&view=diff
==============================================================================
---
mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/TrafficShapingFilter.java
(original)
+++
mina/trunk/core/src/main/java/org/apache/mina/filter/traffic/TrafficShapingFilter.java
Sun Nov 4 18:03:44 2007
@@ -120,6 +120,7 @@
"You can't add the same filter instance more than once.
Create another instance and add it.");
}
parent.getSession().setAttribute(STATE, new State());
+ adjustReadBufferSize(parent.getSession());
}
@Override
@@ -163,19 +164,13 @@
state.readStartTime = 0;
state.suspendedRead = suspendTime != 0;
- if (session.getConfig().getReadBufferSize() >
maxReadThroughput) {
-
session.getConfig().setReadBufferSize(maxReadThroughput);
- }
- if (session.getConfig().getMaxReadBufferSize() >
maxReadThroughput) {
-
session.getConfig().setMaxReadBufferSize(maxReadThroughput);
- }
+ adjustReadBufferSize(session);
}
}
}
if (suspendTime != 0) {
session.suspendRead();
- System.out.println(messageSizeEstimator.estimateSize(message) + ",
" + suspendTime);
scheduledExecutor.schedule(new Runnable() {
public void run() {
synchronized (state) {
@@ -187,6 +182,20 @@
}
nextFilter.messageReceived(session, message);
+ }
+
+ private void adjustReadBufferSize(IoSession session) {
+ int maxReadThroughput = this.maxReadThroughput;
+ if (maxReadThroughput == 0) {
+ return;
+ }
+
+ if (session.getConfig().getReadBufferSize() > maxReadThroughput) {
+ session.getConfig().setReadBufferSize(maxReadThroughput);
+ }
+ if (session.getConfig().getMaxReadBufferSize() > maxReadThroughput) {
+ session.getConfig().setMaxReadBufferSize(maxReadThroughput);
+ }
}
@Override