org.apache.mina.filter.traffic
Class WriteThrottleFilter

java.lang.Object
  extended by org.apache.mina.common.IoFilterAdapter
      extended by org.apache.mina.filter.traffic.WriteThrottleFilter
All Implemented Interfaces:
IoFilter

public class WriteThrottleFilter
extends IoFilterAdapter

An IoFilter that throttles outgoing traffic to prevent a unwanted OutOfMemoryError under heavy load.

This filter will automatically enforce the specified WriteThrottlePolicy when the sessionScheduledWriteBytes, sessionScheduledWriteMessages, serviceScheduledWriteBytes or serviceScheduledWriteMessages exceeds the specified limit values.

Please add this filter at the end of the filter chain.

Version:
$Rev: 616100 $, $Date: 2008-01-28 23:58:32 +0100 (Mon, 28 Jan 2008) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.mina.common.IoFilter
IoFilter.NextFilter
 
Constructor Summary
WriteThrottleFilter()
          Creates a new instance with the default policy (WriteThrottlePolicy.LOG) and limit values.
WriteThrottleFilter(int maxSessionScheduledWriteMessages, long maxSessionScheduledWriteBytes, int maxServiceScheduledWriteMessages, long maxServiceScheduledWriteBytes, int maxGlobalScheduledWriteMessages, long maxGlobalScheduledWriteBytes)
          Creates a new instance with the default policy (WriteThrottlePolicy.LOG) and the specified limit values.
WriteThrottleFilter(WriteThrottlePolicy policy)
          Creates a new instance with the specified policy and the default limit values.
WriteThrottleFilter(WriteThrottlePolicy policy, int maxSessionScheduledWriteMessages, long maxSessionScheduledWriteBytes, int maxServiceScheduledWriteMessages, long maxServiceScheduledWriteBytes, int maxGlobalScheduledWriteMessages, long maxGlobalScheduledWriteBytes)
          Creates a new instance with the specified policy and limit values.
 
Method Summary
 void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause)
          Filters IoHandler.exceptionCaught(IoSession,Throwable) event.
 void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
          Filters IoSession.write(Object) method invocation.
static long getGlobalScheduledWriteBytes()
           
static int getGlobalScheduledWriteMessages()
           
 long getMaxGlobalScheduledWriteBytes()
           
 int getMaxGlobalScheduledWriteMessages()
           
 long getMaxServiceScheduledWriteBytes()
           
 int getMaxServiceScheduledWriteMessages()
           
 long getMaxSessionScheduledWriteBytes()
           
 int getMaxSessionScheduledWriteMessages()
           
 WriteThrottlePolicy getPolicy()
           
 void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
          Filters IoHandler.messageSent(IoSession,Object) event.
 void onPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)
          Invoked before this filter is added to the specified parent.
 void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
          Filters IoHandler.sessionClosed(IoSession) event.
 void setMaxGlobalScheduledWriteBytes(long maxGlobalScheduledWriteBytes)
           
 void setMaxGlobalScheduledWriteMessages(int maxGlobalScheduledWriteMessages)
           
 void setMaxServiceScheduledWriteBytes(long maxServiceScheduledWriteBytes)
           
 void setMaxServiceScheduledWriteMessages(int maxServiceScheduledWriteMessages)
           
 void setMaxSessionScheduledWriteBytes(long maxSessionScheduledWriteBytes)
           
 void setMaxSessionScheduledWriteMessages(int maxSessionScheduledWriteMessages)
           
 void setPolicy(WriteThrottlePolicy policy)
           
 
Methods inherited from class org.apache.mina.common.IoFilterAdapter
destroy, filterClose, filterSetTrafficMask, init, messageReceived, onPostAdd, onPostRemove, onPreRemove, sessionCreated, sessionIdle, sessionOpened
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WriteThrottleFilter

public WriteThrottleFilter()
Creates a new instance with the default policy (WriteThrottlePolicy.LOG) and limit values.


WriteThrottleFilter

public WriteThrottleFilter(WriteThrottlePolicy policy)
Creates a new instance with the specified policy and the default limit values.


WriteThrottleFilter

public WriteThrottleFilter(int maxSessionScheduledWriteMessages,
                           long maxSessionScheduledWriteBytes,
                           int maxServiceScheduledWriteMessages,
                           long maxServiceScheduledWriteBytes,
                           int maxGlobalScheduledWriteMessages,
                           long maxGlobalScheduledWriteBytes)
Creates a new instance with the default policy (WriteThrottlePolicy.LOG) and the specified limit values.


WriteThrottleFilter

public WriteThrottleFilter(WriteThrottlePolicy policy,
                           int maxSessionScheduledWriteMessages,
                           long maxSessionScheduledWriteBytes,
                           int maxServiceScheduledWriteMessages,
                           long maxServiceScheduledWriteBytes,
                           int maxGlobalScheduledWriteMessages,
                           long maxGlobalScheduledWriteBytes)
Creates a new instance with the specified policy and limit values.

Method Detail

getGlobalScheduledWriteMessages

public static int getGlobalScheduledWriteMessages()

getGlobalScheduledWriteBytes

public static long getGlobalScheduledWriteBytes()

getPolicy

public WriteThrottlePolicy getPolicy()

setPolicy

public void setPolicy(WriteThrottlePolicy policy)

getMaxSessionScheduledWriteMessages

public int getMaxSessionScheduledWriteMessages()

setMaxSessionScheduledWriteMessages

public void setMaxSessionScheduledWriteMessages(int maxSessionScheduledWriteMessages)

getMaxSessionScheduledWriteBytes

public long getMaxSessionScheduledWriteBytes()

setMaxSessionScheduledWriteBytes

public void setMaxSessionScheduledWriteBytes(long maxSessionScheduledWriteBytes)

getMaxServiceScheduledWriteMessages

public int getMaxServiceScheduledWriteMessages()

setMaxServiceScheduledWriteMessages

public void setMaxServiceScheduledWriteMessages(int maxServiceScheduledWriteMessages)

getMaxServiceScheduledWriteBytes

public long getMaxServiceScheduledWriteBytes()

setMaxServiceScheduledWriteBytes

public void setMaxServiceScheduledWriteBytes(long maxServiceScheduledWriteBytes)

getMaxGlobalScheduledWriteMessages

public int getMaxGlobalScheduledWriteMessages()

setMaxGlobalScheduledWriteMessages

public void setMaxGlobalScheduledWriteMessages(int maxGlobalScheduledWriteMessages)

getMaxGlobalScheduledWriteBytes

public long getMaxGlobalScheduledWriteBytes()

setMaxGlobalScheduledWriteBytes

public void setMaxGlobalScheduledWriteBytes(long maxGlobalScheduledWriteBytes)

onPreAdd

public void onPreAdd(IoFilterChain parent,
                     String name,
                     IoFilter.NextFilter nextFilter)
              throws Exception
Description copied from interface: IoFilter
Invoked before this filter is added to the specified parent. Please note that this method can be invoked more than once if this filter is added to more than one parents. This method is not invoked before IoFilter.init() is invoked.

Specified by:
onPreAdd in interface IoFilter
Overrides:
onPreAdd in class IoFilterAdapter
Parameters:
parent - the parent who called this method
name - the name assigned to this filter
nextFilter - the IoFilter.NextFilter for this filter. You can reuse this object until this filter is removed from the chain.
Throws:
Exception

filterWrite

public void filterWrite(IoFilter.NextFilter nextFilter,
                        IoSession session,
                        WriteRequest writeRequest)
                 throws Exception
Description copied from interface: IoFilter
Filters IoSession.write(Object) method invocation.

Specified by:
filterWrite in interface IoFilter
Overrides:
filterWrite in class IoFilterAdapter
Throws:
Exception

messageSent

public void messageSent(IoFilter.NextFilter nextFilter,
                        IoSession session,
                        WriteRequest writeRequest)
                 throws Exception
Description copied from interface: IoFilter
Filters IoHandler.messageSent(IoSession,Object) event.

Specified by:
messageSent in interface IoFilter
Overrides:
messageSent in class IoFilterAdapter
Throws:
Exception

exceptionCaught

public void exceptionCaught(IoFilter.NextFilter nextFilter,
                            IoSession session,
                            Throwable cause)
                     throws Exception
Description copied from interface: IoFilter
Filters IoHandler.exceptionCaught(IoSession,Throwable) event.

Specified by:
exceptionCaught in interface IoFilter
Overrides:
exceptionCaught in class IoFilterAdapter
Throws:
Exception

sessionClosed

public void sessionClosed(IoFilter.NextFilter nextFilter,
                          IoSession session)
                   throws Exception
Description copied from interface: IoFilter
Filters IoHandler.sessionClosed(IoSession) event.

Specified by:
sessionClosed in interface IoFilter
Overrides:
sessionClosed in class IoFilterAdapter
Throws:
Exception


Copyright © 2004-2009 Apache MINA Project. All Rights Reserved.