Class ProfilerTimerFilter
java.lang.Object
org.apache.mina.core.filterchain.IoFilterAdapter
org.apache.mina.filter.statistic.ProfilerTimerFilter
- All Implemented Interfaces:
IoFilter
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);
The profiled IoEventType are :
- IoEventType.MESSAGE_RECEIVED
- IoEventType.MESSAGE_SENT
- IoEventType.SESSION_CREATED
- IoEventType.SESSION_OPENED
- IoEventType.SESSION_IDLE
- IoEventType.SESSION_CLOSED
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classClass that will track the time each method takes and be able to provide information for each method.Nested classes/interfaces inherited from interface IoFilter
IoFilter.NextFilter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ProfilerTimerFilter.TimerWorkerA TimerWorker for the MessageReceived eventsprivate ProfilerTimerFilter.TimerWorkerA TimerWorker for the MessageSent eventsprivate booleanA flag to tell the filter that the MessageReceived must be profiledprivate booleanA flag to tell the filter that the MessageSent must be profiledprivate booleanA flag to tell the filter that the SessionClosed must be profiledprivate booleanA flag to tell the filter that the SessionCreated must be profiledprivate booleanA flag to tell the filter that the SessionIdle must be profiledprivate booleanA flag to tell the filter that the SessionOpened must be profiledprivate ProfilerTimerFilter.TimerWorkerA TimerWorker for the SessionClosed eventsprivate ProfilerTimerFilter.TimerWorkerA TimerWorker for the SessionCreated eventsprivate ProfilerTimerFilter.TimerWorkerA TimerWorker for the SessionIdle eventsprivate ProfilerTimerFilter.TimerWorkerA TimerWorker for the SessionOpened eventsprivate TimeUnitTRhe selected time unit -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptiondoublegetAverageTime(IoEventType type) Get the average time for the specified method represented by theIoEventTypeReturn the set ofIoEventTypewhich are profiled.longgetMaximumTime(IoEventType type) The maximum time the method represented byIoEventTypehas executedlonggetMinimumTime(IoEventType type) The minimum time the method represented byIoEventTypehas executedlonggetTotalCalls(IoEventType type) Gets the total number of times the method has been called that is represented by theIoEventTypelonggetTotalTime(IoEventType type) The total time this method has been executingvoidmessageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message) Profile a MessageReceived event.voidmessageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) Profile a MessageSent event.voidprofile(IoEventType type) Set theIoEventTypeto be profiledvoidsessionClosed(IoFilter.NextFilter nextFilter, IoSession session) Profile a SessionClosed event.voidsessionCreated(IoFilter.NextFilter nextFilter, IoSession session) Profile a SessionCreated event.voidsessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status) Profile a SessionIdle event.voidsessionOpened(IoFilter.NextFilter nextFilter, IoSession session) Profile a SessionOpened event.voidsetEventsToProfile(IoEventType... eventTypes) Set the profilers for a list ofIoEventTypeprivate voidsetProfilers(IoEventType... eventTypes) Create the profilers for a list ofIoEventType.voidsetTimeUnit(TimeUnit timeUnit) Sets theTimeUnitbeing used.voidstopProfile(IoEventType type) Stop profiling anIoEventTypeprivate longtimeNow()Methods inherited from class IoFilterAdapter
destroy, event, exceptionCaught, filterClose, filterWrite, init, inputClosed, onPostAdd, onPostRemove, onPreAdd, onPreRemove, toString
-
Field Details
-
timeUnit
TRhe selected time unit -
messageReceivedTimerWorker
A TimerWorker for the MessageReceived events -
profileMessageReceived
private boolean profileMessageReceivedA flag to tell the filter that the MessageReceived must be profiled -
messageSentTimerWorker
A TimerWorker for the MessageSent events -
profileMessageSent
private boolean profileMessageSentA flag to tell the filter that the MessageSent must be profiled -
sessionCreatedTimerWorker
A TimerWorker for the SessionCreated events -
profileSessionCreated
private boolean profileSessionCreatedA flag to tell the filter that the SessionCreated must be profiled -
sessionOpenedTimerWorker
A TimerWorker for the SessionOpened events -
profileSessionOpened
private boolean profileSessionOpenedA flag to tell the filter that the SessionOpened must be profiled -
sessionIdleTimerWorker
A TimerWorker for the SessionIdle events -
profileSessionIdle
private boolean profileSessionIdleA flag to tell the filter that the SessionIdle must be profiled -
sessionClosedTimerWorker
A TimerWorker for the SessionClosed events -
profileSessionClosed
private boolean profileSessionClosedA flag to tell the filter that the SessionClosed must be profiled
-
-
Constructor Details
-
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
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
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 manyIoEventTypeas 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 ofIoEventTyperepresentation of the methods to profile
-
-
Method Details
-
setProfilers
Create the profilers for a list ofIoEventType.- Parameters:
eventTypes- the list ofIoEventTypeto profile
-
setTimeUnit
-
profile
Set theIoEventTypeto be profiled- Parameters:
type- TheIoEventTypeto profile
-
stopProfile
Stop profiling anIoEventType- Parameters:
type- TheIoEventTypeto stop profiling
-
getEventsToProfile
Return the set ofIoEventTypewhich are profiled.- Returns:
- a Set containing all the profiled
IoEventType
-
setEventsToProfile
Set the profilers for a list ofIoEventType- Parameters:
eventTypes- the list ofIoEventTypeto 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:
messageReceivedin interfaceIoFilter- Overrides:
messageReceivedin 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:
messageSentin interfaceIoFilter- Overrides:
messageSentin 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
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:
sessionCreatedin interfaceIoFilter- Overrides:
sessionCreatedin classIoFilterAdapter- Parameters:
nextFilter- The filter to call nextsession- The associated session- Throws:
Exception- If an error occurred while processing the event
-
sessionOpened
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:
sessionOpenedin interfaceIoFilter- Overrides:
sessionOpenedin 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:
sessionIdlein interfaceIoFilter- Overrides:
sessionIdlein 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
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:
sessionClosedin interfaceIoFilter- Overrides:
sessionClosedin classIoFilterAdapter- Parameters:
nextFilter- The filter to call nextsession- The associated session- Throws:
Exception- If an error occurred while processing the event
-
getAverageTime
Get the average time for the specified method represented by theIoEventType- Parameters:
type- TheIoEventTypethat 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
Gets the total number of times the method has been called that is represented by theIoEventType- Parameters:
type- TheIoEventTypethat 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
The total time this method has been executing- Parameters:
type- TheIoEventTypethat 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
The minimum time the method represented byIoEventTypehas executed- Parameters:
type- TheIoEventTypethat 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
The maximum time the method represented byIoEventTypehas executed- Parameters:
type- TheIoEventTypethat the user wants to get the maximum time this method has executed- Returns:
- The maximum time this method has executed represented by the
IoEventType
-
timeNow
private long timeNow()- Returns:
- the current time, expressed using the fixed TimeUnit.
-