Fields Summary |
---|
protected com.sun.midp.security.SecurityToken | securityTokenSecurity token for SIP/SIPS protocol class |
protected boolean | tcpFlagFlag indicating tcp connection in use. |
protected boolean | udpFlagFlag indicating udp connection in use. |
protected String | outboundProxyThe outbound proxy location. |
protected int | outboundPortThe outbound proxy server port. |
protected boolean | toExitFlag that indicates that the stack is active. |
protected String | badMessageLogBad message log. The name of a file that stores bum messages for
debugging. |
protected boolean | debugFlagInternal flag for debugging |
protected String | stackNameName of the stack. |
protected String | stackAddressIP address of stack. |
protected SIPStackMessageFactory | sipMessageFactoryRequest factory interface (to be provided by the application). |
protected Router | routerRouter to determine where to forward the request. |
protected int | threadPoolSizeStarts a single processing thread for all UDP messages
(otherwise, the stack will start a new thread for each UDP
message). |
protected int | maxConnectionsMax number of simultaneous connections. |
private Vector | messageProcessorsA collection of message processors. |
Methods Summary |
---|
public void | addMessageProcessor(MessageProcessor newMessageProcessor)Adds a new MessageProcessor to the list of running processors
for this SIPMessageStack and starts it. You can use this method
for dynamic stack configuration.
Acknowledgement: This code is contributed by Jeff Keyser.
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"addMessageProcessor " +
newMessageProcessor.getPort() + " / " +
newMessageProcessor.getTransport());
}
synchronized (messageProcessors) {
messageProcessors.addElement(newMessageProcessor);
newMessageProcessor.start();
}
|
public MessageChannel | createMessageChannel(Hop nextHop)Creates a new MessageChannel for a given Hop.
Host targetHost;
HostPort targetHostPort;
MessageProcessor nextProcessor;
MessageChannel newChannel;
// Create the host/port of the target hop
targetHost = new Host();
targetHost.setHostname(nextHop.getHost());
targetHostPort = new HostPort();
targetHostPort.setHost(targetHost);
targetHostPort.setPort(nextHop.getPort());
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"createMessageChannel " + nextHop);
}
// Search each processor for the correct transport
newChannel = null;
Enumeration processorIterator = messageProcessors.elements();
while (processorIterator.hasMoreElements() && newChannel == null) {
nextProcessor =
(MessageProcessor) processorIterator.nextElement();
// If a processor that supports the correct
// transport is found,
if (Utils.equalsIgnoreCase
(nextHop.getTransport(), nextProcessor.getTransport())) {
try {
// Create a channel to the target host/port
newChannel = nextProcessor.
createMessageChannel(targetHostPort);
} catch (IOException e) {
e.printStackTrace();
// Ignore channel creation error -
// try next processor
}
}
}
if (newChannel == null) { // Message processor was not found
// Try to create it
try {
MessageProcessor processor = createMessageProcessor(
nextHop.getPort(), nextHop.getTransport());
// IMPL_NOTE: The previous message processor should be
// removed on level of re-routing SIP messages
newChannel = processor.createMessageChannel(targetHostPort);
} catch (IOException ex) {
} catch (IllegalArgumentException ex) {
}
}
// Return the newly-created channel
return newChannel;
|
public MessageProcessor | createMessageProcessor(int port, java.lang.String transport)Creates the equivalent of a JAIN listening point and attaches
to the stack.
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
"createMessageProcessor : " +
port + " / " + transport);
}
if (Utils.equalsIgnoreCase(transport, SIPConstants.TRANSPORT_UDP)) {
UDPMessageProcessor
udpMessageProcessor =
new UDPMessageProcessor(this, port);
this.addMessageProcessor(udpMessageProcessor);
this.udpFlag = true;
return udpMessageProcessor;
} else if (Utils.equalsIgnoreCase(transport,
SIPConstants.TRANSPORT_TCP)) {
TCPMessageProcessor
tcpMessageProcessor =
new TCPMessageProcessor(this, port);
this.addMessageProcessor(tcpMessageProcessor);
this.tcpFlag = true;
return tcpMessageProcessor;
} else {
throw new IllegalArgumentException("bad transport");
}
|
public java.lang.String | getBadMessageLog()Gets the file name of the bad message log.
return this.badMessageLog;
|
public Hop | getDefaultRoute()Gets the default route.
return this.router.getOutboundProxy();
|
public RouteHeader | getDefaultRouteHeader()Gets the route header corresponding to the default route.
if (router.getOutboundProxy() != null) {
Hop hop = ((Hop) router.getOutboundProxy());
return getRouteHeader(hop);
} else
return null;
|
public java.lang.String | getHostAddress()Gets my address.
return this.stackAddress;
|
public MessageProcessor | getMessageProcessor(java.lang.String transport)Gets a message processor for the given transport.
synchronized (messageProcessors) {
Enumeration it = messageProcessors.elements();
while (it.hasMoreElements()) {
MessageProcessor mp = (MessageProcessor) it.nextElement();
if (Utils.equalsIgnoreCase(mp.getTransport(), transport)) {
return mp;
}
}
return null;
}
|
public java.util.Vector | getMessageProcessors()Gets an array of running MessageProcessors on this SIPMessageStack.
Acknowledgement: Jeff Keyser suggested that applications should
have access to the running message processors and contributed
this code.
return messageProcessors;
|
public Hop | getNextHop()Gets the default next hop from the router.
return (Hop) this.router.getOutboundProxy();
|
public int | getPort(java.lang.String transport)Gets port of the message processor (based on the transport). If
multiple ports are enabled for the same transport then the first
one is retrieved.
synchronized (messageProcessors) {
Enumeration it = messageProcessors.elements();
while (it.hasMoreElements()) {
MessageProcessor mp = (MessageProcessor) it.nextElement();
if (Utils.equalsIgnoreCase(mp.getTransport(), transport))
return mp.getPort();
}
throw new IllegalArgumentException
("Transport not supported " + transport);
}
|
public RouteHeader | getRouteHeader(Hop hop)Gets the route header for this hop.
HostPort hostPort = new HostPort();
Host h = new Host(hop.getHost());
hostPort.setHost(h);
hostPort.setPort(hop.getPort());
gov.nist.siplite.address.SipURI uri = new SipURI();
uri.setHostPort(hostPort);
uri.setScheme(SIPConstants.SCHEME_SIP);
try {
uri.setTransportParam(hop.getTransport());
} catch (ParseException ex) {
InternalErrorHandler.handleException(ex);
}
Address address = new Address();
address.setURI(uri);
RouteHeader route = new RouteHeader();
route.setAddress(address);
return route;
|
public Router | getRouter()Gets the router algorithm.
return router;
|
protected com.sun.midp.security.SecurityToken | getSecurityToken()Return a security token associated with the protocol class
return securityToken;
|
public java.lang.String | getStackName()Gets the Stack name.
return this.stackName;
|
public synchronized boolean | isAlive()Returns the status of the toExit flag.
return !toExit;
|
public boolean | isTransportEnabled(java.lang.String transport)Returns true if a transport is enabled.
synchronized (messageProcessors) {
Enumeration it = messageProcessors.elements();
while (it.hasMoreElements()) {
MessageProcessor mp = (MessageProcessor) it.nextElement();
if (Utils.equalsIgnoreCase(mp.getTransport(), transport))
return true;
}
return false;
}
|
public boolean | isTransportEnabled(java.lang.String transport, int port)Returns true if the transport is enabled for a given port.
synchronized (messageProcessors) {
Enumeration it = messageProcessors.elements();
while (it.hasMoreElements()) {
MessageProcessor mp = (MessageProcessor) it.nextElement();
if (Utils.equalsIgnoreCase(mp.getTransport(), transport) &&
mp.getPort() == port)
return true;
}
return false;
}
|
public void | logBadMessage(java.lang.String message)Logs a bad message (invoked when a parse exception arises).
if (badMessageLog != null) {
if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
message + badMessageLog);
}
}
|
protected SIPServerRequestInterface | newSIPServerRequest(Request siprequest, MessageChannel msgchan)Generates a new SIPSeverRequest from the given Request. A
SIPServerRequest is generated by the application
SIPServerRequestFactoryImpl. The application registers the
factory implementation at the time the stack is initialized.
return sipMessageFactory.newSIPServerRequest
(siprequest, msgchan);
|
SIPServerResponseInterface | newSIPServerResponse(Response sipresponse, MessageChannel msgchan)Generates a new SIPSeverResponse from the given Response.
return sipMessageFactory.newSIPServerResponse
(sipresponse, msgchan);
|
public void | removeMessageProcessor(MessageProcessor oldMessageProcessor)Removes a MessageProcessor from this SIPMessageStack. Acknowledgement:
Code contributed by Jeff Keyser.
synchronized (messageProcessors) {
if (messageProcessors.removeElement(oldMessageProcessor)) {
oldMessageProcessor.stop();
}
}
|
public void | setHostAddress(java.lang.String stackAddress)Sets my address.
if (stackAddress.indexOf(':") != stackAddress.lastIndexOf(':")
&& stackAddress.trim().charAt(0) != '[")
this.stackAddress = '[" + stackAddress + ']";
else
this.stackAddress = stackAddress;
|
public void | setMaxConnections(int nconnections)Sets the max # of simultaneously handled TCP connections.
this.maxConnections = nconnections;
|
protected void | setMessageFactory(SIPStackMessageFactory messageFactory)Sets the message factory.
this.sipMessageFactory = messageFactory;
|
public void | setRouter(Router router)Sets the router algorithm.
this.router = router;
|
protected void | setSecurityToken(com.sun.midp.security.SecurityToken token)Set the security token associated with the protocol class
securityToken = token;
|
public void | setSingleThreaded()Sets the flag that instructs the stack to only start a single
thread for sequentially processing incoming udp messages (thus
serializing the processing).
Caution: If the user-defined function called by the
processing thread blocks, then the entire server will block.
this.threadPoolSize = 1;
|
public void | setStackMessageFactory(SIPStackMessageFactory messageFactory)Sets the server Request and response factories.
sipMessageFactory = messageFactory;
|
public void | setStackName(java.lang.String stackName)Sets the descriptive name of the stack.
this.stackName = stackName;
ServerLog.setDescription(stackName);
ServerLog.stackIpAddress = stackAddress;
|
public void | setThreadPoolSize(int size)Sets the thread pool size for processing incoming UDP messages.
Limit the total number of threads for processing udp messages.
Caution: If the user-defined function called by the
processing thread blocks, then the entire server will block.
this.threadPoolSize = size;
|
public void | stopStack()Makes the stack close all accept connections and return. This
is useful if you want to start/stop the stack several times from
your application. Caution : use of this function could cause
peculiar bugs as messages are prcessed asynchronously by the stack.
synchronized (this.messageProcessors) {
// Threads must periodically check this flag.
this.toExit = true;
Vector processorList;
processorList = getMessageProcessors();
/*
* IMPL_NOTE:
* Normally, messageprocessors are already stopped before
* stopStack() is explicitely invoked from close() of
* SipConnectionNotifier. So it is not needed to iterate through the
* list. However, this part of the code is not yet removed as it is
* not known if sipStack() needs to be closed independantly.
* A safetly check is added before invoking stop() for a message
* processor to verify if it was already closed
*/
for (int i = 0; i < processorList.size(); i++) {
MessageProcessor mp =
(MessageProcessor) processorList.elementAt(i);
if (!mp.toExit()) {
mp.stop();
}
}
processorList.removeAllElements();
}
|