Package org.apache.mina.filter.statistic
Class ProfilerTimerFilter
- java.lang.Object
-
- org.apache.mina.core.filterchain.IoFilterAdapter
-
- 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 theIoFilterAdapter
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);
The profiledIoEventType
are :- IoEventType.MESSAGE_RECEIVED
- IoEventType.MESSAGE_SENT
- IoEventType.SESSION_CREATED
- IoEventType.SESSION_OPENED
- IoEventType.SESSION_IDLE
- IoEventType.SESSION_CLOSED
- Author:
- Apache MINA Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilter
IoFilter.NextFilter
-
-
Constructor Summary
Constructors Constructor Description ProfilerTimerFilter()
Creates a new instance of ProfilerFilter.ProfilerTimerFilter(TimeUnit timeUnit)
Creates a new instance of ProfilerFilter.ProfilerTimerFilter(TimeUnit timeUnit, IoEventType... eventTypes)
Creates a new instance of ProfilerFilter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getAverageTime(IoEventType type)
Get the average time for the specified method represented by theIoEventType
Set<IoEventType>
getEventsToProfile()
Return the set ofIoEventType
which are profiled.long
getMaximumTime(IoEventType type)
The maximum time the method represented byIoEventType
has executedlong
getMinimumTime(IoEventType type)
The minimum time the method represented byIoEventType
has executedlong
getTotalCalls(IoEventType type)
Gets the total number of times the method has been called that is represented by theIoEventType
long
getTotalTime(IoEventType type)
The total time this method has been executingvoid
messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message)
Profile a MessageReceived event.void
messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
Profile a MessageSent event.void
profile(IoEventType type)
Set theIoEventType
to be profiledvoid
sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
Profile a SessionClosed event.void
sessionCreated(IoFilter.NextFilter nextFilter, IoSession session)
Profile a SessionCreated event.void
sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status)
Profile a SessionIdle event.void
sessionOpened(IoFilter.NextFilter nextFilter, IoSession session)
Profile a SessionOpened event.void
setEventsToProfile(IoEventType... eventTypes)
Set the profilers for a list ofIoEventType
void
setTimeUnit(TimeUnit timeUnit)
Sets theTimeUnit
being used.void
stopProfile(IoEventType type)
Stop profiling anIoEventType
-
Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, exceptionCaught, filterClose, filterWrite, init, inputClosed, onPostAdd, onPostRemove, onPreAdd, onPreRemove, toString
-
-
-
-
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 timeUnit)
Creates a new instance of ProfilerFilter. This is the default constructor and will print out timings for messageReceived and messageSent.- Parameters:
timeUnit
- the time increment to set
-
ProfilerTimerFilter
public ProfilerTimerFilter(TimeUnit timeUnit, IoEventType... eventTypes)
Creates a new instance of ProfilerFilter. An example of this call would be:new ProfilerTimerFilter( TimeUnit.MILLISECONDS, IoEventType.MESSAGE_RECEIVED, IoEventType.MESSAGE_SENT);
Note : you can add as manyIoEventType
as you want. The method accepts a variable number of arguments.- Parameters:
timeUnit
- Used to determine the level of precision you need in your timing.eventTypes
- A list ofIoEventType
representation of the methods to profile
-
-
Method Detail
-
setTimeUnit
public void setTimeUnit(TimeUnit timeUnit)
Sets theTimeUnit
being used.- Parameters:
timeUnit
- the newTimeUnit
to be used.
-
profile
public void profile(IoEventType type)
Set theIoEventType
to be profiled- Parameters:
type
- TheIoEventType
to profile
-
stopProfile
public void stopProfile(IoEventType type)
Stop profiling anIoEventType
- Parameters:
type
- TheIoEventType
to stop profiling
-
getEventsToProfile
public Set<IoEventType> getEventsToProfile()
Return the set ofIoEventType
which are profiled.- Returns:
- a Set containing all the profiled
IoEventType
-
setEventsToProfile
public void setEventsToProfile(IoEventType... eventTypes)
Set the profilers for a list ofIoEventType
- Parameters:
eventTypes
- the list ofIoEventType
to profile
-
messageReceived
public void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message) throws Exception
Profile a MessageReceived event. This method will gather the following informations : - the method duration - the shortest execution time - the slowest execution time - the average execution time - the global number of calls- Specified by:
messageReceived
in interfaceIoFilter
- Overrides:
messageReceived
in classIoFilterAdapter
- Parameters:
nextFilter
- The filter to call nextsession
- The associated sessionmessage
- the received message- Throws:
Exception
- If an error occurred while processing the event
-
messageSent
public void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
Profile a MessageSent event. This method will gather the following informations : - the method duration - the shortest execution time - the slowest execution time - the average execution time - the global number of calls- Specified by:
messageSent
in interfaceIoFilter
- Overrides:
messageSent
in classIoFilterAdapter
- Parameters:
nextFilter
- The filter to call nextsession
- The associated sessionwriteRequest
- the sent message- Throws:
Exception
- If an error occurred while processing the event
-
sessionCreated
public void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
Profile a SessionCreated event. This method will gather the following informations : - the method duration - the shortest execution time - the slowest execution time - the average execution time - the global number of calls- Specified by:
sessionCreated
in interfaceIoFilter
- Overrides:
sessionCreated
in classIoFilterAdapter
- Parameters:
nextFilter
- The filter to call nextsession
- The associated session- Throws:
Exception
- If an error occurred while processing the event
-
sessionOpened
public void sessionOpened(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
Profile a SessionOpened event. This method will gather the following informations : - the method duration - the shortest execution time - the slowest execution time - the average execution time - the global number of calls- Specified by:
sessionOpened
in interfaceIoFilter
- Overrides:
sessionOpened
in classIoFilterAdapter
- Parameters:
nextFilter
- The filter to call nextsession
- The associated session- Throws:
Exception
- If an error occurred while processing the event
-
sessionIdle
public void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception
Profile a SessionIdle event. This method will gather the following informations : - the method duration - the shortest execution time - the slowest execution time - the average execution time - the global number of calls- Specified by:
sessionIdle
in interfaceIoFilter
- Overrides:
sessionIdle
in classIoFilterAdapter
- Parameters:
nextFilter
- The filter to call nextsession
- The associated sessionstatus
- The session's status- Throws:
Exception
- If an error occurred while processing the event
-
sessionClosed
public void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
Profile a SessionClosed event. This method will gather the following informations : - the method duration - the shortest execution time - the slowest execution time - the average execution time - the global number of calls- Specified by:
sessionClosed
in interfaceIoFilter
- Overrides:
sessionClosed
in classIoFilterAdapter
- Parameters:
nextFilter
- The filter to call nextsession
- The associated session- Throws:
Exception
- If an error occurred while processing the event
-
getAverageTime
public double getAverageTime(IoEventType type)
Get the average time for the specified method represented by theIoEventType
- Parameters:
type
- TheIoEventType
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 theIoEventType
- Parameters:
type
- TheIoEventType
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
- TheIoEventType
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 byIoEventType
has executed- Parameters:
type
- TheIoEventType
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 byIoEventType
has executed- Parameters:
type
- TheIoEventType
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
-
-