SipApplicationRouterProvider
The SipApplicationRouterProvider is an abstract class used by the SIP Servlet container to load and instantiate the application router. This class follows the Service Provider framework, allowing the application router to be packaged and discovered according to specific deployment rules. It provides a mechanism for integrating a custom application router into the container.
How the Application Router is Packaged and Discovered
The application router must be implemented as a concrete subclass of SipApplicationRouterProvider with a no-argument public constructor.
The JAR file containing the implementation must include a META-INF/services/javax.servlet.sip.ar.spi.SipApplicationRouterProvider file.
This file should specify the name of the concrete subclass of SipApplicationRouterProvider.
The application router provider can be installed in one of the following ways:
- By including the JAR in the system classpath.
- By including the JAR in the extension classpath.
- Through container-specific means, such as proprietary deployment mechanisms.
public class AcmeAppRouter implements SipApplicationRouter {
// Implementation of the application router
}
public class AcmeAppRouterProvider extends SipApplicationRouterProvider {
private final AcmeAppRouter appRouter = new AcmeAppRouter();
public AcmeAppRouterProvider() {
// No-argument constructor
}
public SipApplicationRouter getSipApplicationRouter() {
return appRouter;
}
}
The AcmeAppRouter is packaged in a JAR and added to the system classpath.
Container Behavior
The container discovers the application router by iterating through available providers in the system classpath using the Service Provider framework. It selects the first provider available, as shown in the example:
SipApplicationRouter getSipApplicationRouter() {
Iterator ps = Service.providers(SipApplicationRouterProvider.class);
while (ps.hasNext()) {
SipApplicationRouterProvider p = (SipApplicationRouterProvider) ps.next();
return p.getSipApplicationRouter();
}
return null;
}
The javax.servlet.sip.ar.spi.SipApplicationRouterProvider system property can override the default loading behavior, forcing the container to use a specific provider implementation. Containers should respect this property for consistency and portability if specified by the deployer.
At any given time, the SIP Servlet specification allows only one application router to be active. The container selects the first provider unless overridden by the system property.
Constructor:
SipApplicationRouterProvider
public SipApplicationRouterProvider()
This no-argument constructor initializes an instance of the SipApplicationRouterProvider class. It is required for the Service Provider framework, enabling the SIP Servlet container to dynamically discover and instantiate application router providers during deployment. Subclasses of SipApplicationRouterProvider must implement this constructor to ensure compatibility with the container's service loading mechanism. While the constructor does not include any specific initialization logic, it is a critical requirement for integrating custom application routers into the SIP Servlet environment.
Methods:
getSipApplicationRouter
public abstract SipApplicationRouter getSipApplicationRouter()
This abstract method retrieves an instance of the application router created by the current provider. The method is called by the SIP Servlet container to obtain the SipApplicationRouter instance that will handle routing decisions for SIP requests.
Returns:
An instance of SipApplicationRouter created by the provider.
Methods inherited from class java.lang.Object:
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait.
These methods are not overridden in this implementation.
Start innovating with Mobius
What's next? Let's talk!