org.apache.mina.filter.statistic
Class ProfilerTimerFilter

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

public class ProfilerTimerFilter
extends IoFilterAdapter

This class will measure, the time it takes for a method in the IoFilterAdapter class to execute. The basic premise of the logic in this class is to get the current time at the beginning of the method, call method on nextFilter, and then get the current time again. An example of how to use the filter is:

 ProfilerTimerFilter profiler = new ProfilerTimerFilter(
         TimeUnit.MILLISECOND, IoEventType.MESSAGE_RECEIVED);
 chain.addFirst("Profiler", profiler);
 

Version:
$Rev: 597988 $, $Date: 2007-11-25 15:02:29 +0100 (Sun, 25 Nov 2007) $
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
ProfilerTimerFilter()
          Creates a new instance of ProfilerFilter.
ProfilerTimerFilter(TimeUnit unit)
          Creates a new instance of ProfilerFilter.
ProfilerTimerFilter(TimeUnit unit, EnumSet<IoEventType> eventTypes)
          Creates a new instance of ProfilerFilter.
ProfilerTimerFilter(TimeUnit unit, IoEventType firstEventType, IoEventType... otherEventTypes)
          Creates a new instance of ProfilerFilter.
 
Method Summary
 void addEventToProfile(IoEventType type)
          Add an IoEventType to profile
 double getAverageTime(IoEventType type)
          Get the average time for the specified method represented by the IoEventType
 Set<IoEventType> getEventsToProfile()
          Return the bitmask that is being used to display timing information for this filter.
 long getMaximumTime(IoEventType type)
          The maximum time the method represented by IoEventType has executed
 long getMinimumTime(IoEventType type)
          The minimum time the method represented by IoEventType has executed
 long getTotalCalls(IoEventType type)
          Gets the total number of times the method has been called that is represented by the IoEventType
 long getTotalTime(IoEventType type)
          The total time this method has been executing
 void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message)
          Filters IoHandler.messageReceived(IoSession,Object) event.
 void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
          Filters IoHandler.messageSent(IoSession,Object) event.
 void removeEventToProfile(IoEventType type)
          Remove an IoEventType to profile
 void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
          Filters IoHandler.sessionClosed(IoSession) event.
 void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session)
          Filters IoHandler.sessionCreated(IoSession) event.
 void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status)
          Filters IoHandler.sessionIdle(IoSession,IdleStatus) event.
 void sessionOpened(IoFilter.NextFilter nextFilter, IoSession session)
          Filters IoHandler.sessionOpened(IoSession) event.
 void setEventsToProfile(IoEventType firstEventType, IoEventType... otherEventTypes)
          Set the bitmask in order to tell this filter which methods to print out timing information
 void setEventsToProfile(Set<IoEventType> eventTypes)
          Set the bitmask in order to tell this filter which methods to print out timing information
 void setTimeUnit(TimeUnit unit)
          Sets the TimeUnit being used.
 
Methods inherited from class org.apache.mina.common.IoFilterAdapter
destroy, exceptionCaught, filterClose, filterSetTrafficMask, filterWrite, init, onPostAdd, onPostRemove, onPreAdd, onPreRemove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProfilerTimerFilter

public ProfilerTimerFilter()
Creates a new instance of ProfilerFilter. This is the default constructor and will print out timings for messageReceived and messageSent and the time increment will be in milliseconds.


ProfilerTimerFilter

public ProfilerTimerFilter(TimeUnit unit)
Creates a new instance of ProfilerFilter. This is the default constructor and will print out timings for messageReceived and messageSent and the time increment will be in milliseconds.


ProfilerTimerFilter

public ProfilerTimerFilter(TimeUnit unit,
                           IoEventType firstEventType,
                           IoEventType... otherEventTypes)
Creates a new instance of ProfilerFilter. An example of this call would be:
 new ProfilerTimerFilter(
         TimeUnit.MILLISECONDS,
         IoEventType.MESSAGE_RECEIVED, IoEventType.MESSAGE_SENT);
 

Parameters:
unit - Used to determine the level of precision you need in your timing.
firstEventType - an event type to profile
otherEventTypes - event types to profile

ProfilerTimerFilter

public ProfilerTimerFilter(TimeUnit unit,
                           EnumSet<IoEventType> eventTypes)
Creates a new instance of ProfilerFilter. An example of this call would be:
 new ProfilerTimerFilter(
         TimeUnit.MILLISECONDS,
         EnumSet.of(IoEventType.MESSAGE_RECEIVED, IoEventType.MESSAGE_SENT));
 

Parameters:
unit - Used to determine the level of precision you need in your timing.
eventTypes - A set of IoEventType representation of the methods to profile
Method Detail

setTimeUnit

public void setTimeUnit(TimeUnit unit)
Sets the TimeUnit being used.

Parameters:
unit - the new TimeUnit to be used.

addEventToProfile

public void addEventToProfile(IoEventType type)
Add an IoEventType to profile

Parameters:
type - The IoEventType to profile

removeEventToProfile

public void removeEventToProfile(IoEventType type)
Remove an IoEventType to profile

Parameters:
type - The IoEventType to profile

getEventsToProfile

public Set<IoEventType> getEventsToProfile()
Return the bitmask that is being used to display timing information for this filter.

Returns:
An int representing the methods that will be logged

setEventsToProfile

public void setEventsToProfile(IoEventType firstEventType,
                               IoEventType... otherEventTypes)
Set the bitmask in order to tell this filter which methods to print out timing information


setEventsToProfile

public void setEventsToProfile(Set<IoEventType> eventTypes)
Set the bitmask in order to tell this filter which methods to print out timing information

Parameters:
eventTypes - An int representing the new methods that should be logged

messageReceived

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

Specified by:
messageReceived in interface IoFilter
Overrides:
messageReceived 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

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

sessionCreated

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

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

sessionIdle

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

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

sessionOpened

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

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

getAverageTime

public double getAverageTime(IoEventType type)
Get the average time for the specified method represented by the IoEventType

Parameters:
type - The IoEventType that the user wants to get the average method call time
Returns:
The average time it took to execute the method represented by the IoEventType

getTotalCalls

public long getTotalCalls(IoEventType type)
Gets the total number of times the method has been called that is represented by the IoEventType

Parameters:
type - The IoEventType that the user wants to get the total number of method calls
Returns:
The total number of method calls for the method represented by the IoEventType

getTotalTime

public long getTotalTime(IoEventType type)
The total time this method has been executing

Parameters:
type - The IoEventType that the user wants to get the total time this method has been executing
Returns:
The total time for the method represented by the IoEventType

getMinimumTime

public long getMinimumTime(IoEventType type)
The minimum time the method represented by IoEventType has executed

Parameters:
type - The IoEventType that the user wants to get the minimum time this method has executed
Returns:
The minimum time this method has executed represented by the IoEventType

getMaximumTime

public long getMaximumTime(IoEventType type)
The maximum time the method represented by IoEventType has executed

Parameters:
type - The IoEventType that the user wants to get the maximum time this method has executed
Returns:
The maximum time this method has executed represented by the IoEventType


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