Oracle OCCAS平台下SIPServlet的TimerListener使用问题
Hey, let's walk through getting that timer properly set up in your SIP Servlet running on Oracle OCCAS. Since you already have the foundational pieces in place (implemented TimerListener, added @SipListener, overridden the timeout() method), here's how to tie it all together when handling INVITE messages:
First, a quick recap of what you've already nailed (great start!):
- Your servlet implements the
TimerListenerinterface - You've annotated the class with
@SipListener - You've overridden the
timeout()method to define your trigger action
Now let's connect the dots for scheduling the timer during INVITE processing:
Retrieve the TimerService instance
When handling an INVITE (in yourdoInvite()method, for example), grab theTimerServicefrom the servlet context:TimerService timerService = (TimerService) getServletContext().getAttribute(TimerService.class.getName());Schedule the timer
Use thecreateTimer()method to set when your timer should fire. For a one-time timeout after 30 seconds (adjust the delay as needed), use this:// Schedule timer to trigger after 30000ms (30 seconds) Timer timer = timerService.createTimer(30000, false, "INVITE_TIMEOUT");- The second parameter (
false) marks this as a one-time timer (not recurring). - The third parameter is a context object (here a string) to help you identify which timer fired in the
timeout()method.
- The second parameter (
Execute your action on timeout
In your overriddentimeout()method, use the timer's context to run your specific logic tied to the INVITE:@Override public void timeout(Timer timer) { String timerContext = (String) timer.getInfo(); if ("INVITE_TIMEOUT".equals(timerContext)) { // Add your custom action here: send a CANCEL, log the timeout, update state, etc. System.out.println("INVITE timer triggered - running specified action"); // Insert your business logic here } }Clean up timers when needed
If the INVITE gets answered before the timer fires, cancel the timer to avoid unnecessary actions:// Store the timer reference when creating it, then call cancel() later timer.cancel();
Quick Notes for Oracle OCCAS
- Double-check that the
@SipListenerannotation is properly recognized by the OCCAS container during deployment. - OCCAS has specific timer service configurations—ensure the timer service is enabled in your deployment descriptor or OCCAS admin console if you hit issues.
- Make sure any resources used in the
timeout()method are thread-safe, since timer events run in a separate thread pool.
内容的提问来源于stack exchange,提问作者ACoutu

