📄 calllauncher.java
字号:
package gov.nist.examples.pcc;import java.util.*;import javax.sip.*;import tools.rtpgateway.*;import gov.nist.examples.pcc.registrar.*;/** */public class CallLauncher { protected CallListener callListener; public Registrar registrar; public Configuration configuration; protected Call firstCall; protected Call secondCall; protected RTPHolesManager rtpHolesManager; /** Creates new Proxy */ public CallLauncher(String confFile) throws Exception{ if (confFile==null) { System.out.println ("ERROR: Set the configuration file flag: " + "USE: -cf configuration_file_location.xml" ); } else { try { // First, let's parse the configuration file. CallLauncherConfigurationHandler handler= new CallLauncherConfigurationHandler(confFile); configuration=handler.getConfiguration(); if (configuration==null || !configuration.isValidConfiguration()) { System.out.println ("ERROR: the configuration file is not correct!"+ " Correct the errors first."); throw new Exception ("ERROR: the configuration file is not correct!"+ " Correct the errors first."); } } catch (Exception ex) { System.out.println ("ERROR: exception raised while initializing the 3PPC launcher"); ex.printStackTrace(); throw new Exception ("ERROR: exception raised while initializing the 3PPC launcher"); } } } public Configuration getConfiguration() { return configuration; } /******************** Methods for ******************************* starting and stopping the launcher ***************************************************************************************************/ public void start() throws Exception { if (configuration!=null && configuration.isValidConfiguration()) { Properties properties=new Properties(); /********************************************************************************************* LOGGING ******************************************************* ********************************************************************************/ if (configuration.enableDebug) { CallLauncherDebug.debug=true; CallLauncherDebug.setCallLauncherOutputFile(configuration.outputCallLauncher); CallLauncherDebug.println("DEBUG properties set!"); if (configuration.badMessageLogFile!=null) properties.setProperty("gov.nist.javax.sip.BAD_MESSAGE_LOG", configuration.badMessageLogFile); if (configuration.debugLogFile!=null) properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", configuration.debugLogFile); if (configuration.serverLogFile!=null) properties.setProperty("gov.nist.javax.sip.SERVER_LOG", configuration.serverLogFile); } else { System.out.println("DEBUG properties not set!"); } /********************************************************************************************* SIP STACKS ****************************************************** ********************************************************************************/ SipFactory sipFactory = SipFactory.getInstance(); sipFactory.setPathName("gov.nist"); callListener=new CallListener(this,sipFactory); registrar=new Registrar(callListener); if (configuration.enableRTPGateway) { int rtpPacketSize=5000; CallLauncherDebug.println("CallLauncher, RTP gateway enabled between:" +configuration.minRTPHolePort+" and "+configuration.maxRTPHolePort+" "+ " (Packet size: "+rtpPacketSize+" )"); rtpHolesManager=new RTPHolesManager(configuration.minRTPHolePort, configuration.maxRTPHolePort,rtpPacketSize); } // Create SipStack objects: for (int i=0;i<configuration.stackConfigurationList.size();i++) { StackConfiguration stackConfiguration=(StackConfiguration) configuration.stackConfigurationList.elementAt(i); //System.out.println(stackConfiguration.stackIPAddress); properties.setProperty("javax.sip.IP_ADDRESS", stackConfiguration.stackIPAddress); properties.setProperty("javax.sip.STACK_NAME", stackConfiguration.stackName); if (configuration.check(stackConfiguration.outboundProxy)) properties.setProperty("javax.sip.OUTBOUND_PROXY", stackConfiguration.outboundProxy); if (configuration.check(stackConfiguration.routerPath)) properties.setProperty("javax.sip.ROUTER_PATH", stackConfiguration.routerPath); // This has to be hardcoded to true. disable the retransmissions properties.setProperty("javax.sip.RETRANSMISSION_FILTER", "on"); SipStack sipStack = sipFactory.createSipStack(properties); callListener.sipStacksList.addElement(sipStack); // We create the Listening points: Vector lps=stackConfiguration.getListeningPoints(); for ( int j=0;lps!=null && j<lps.size();j++) { Association a=(Association)lps.elementAt(j); try { CallLauncherDebug.println("CallLauncher, transport:" + a.transport); CallLauncherDebug.println("CallLauncher, port:" + Integer.valueOf(a.port).intValue()); ListeningPoint lp=sipStack.createListeningPoint (Integer.valueOf(a.port).intValue(), a.transport); SipProvider sipProvider = sipStack.createSipProvider(lp); sipProvider.addSipListener( callListener ); } catch(Exception e) { CallLauncherDebug.println ("CallLauncher, ERROR: listening point not created "); CallLauncherDebug.logException(e); } } } // Parse static configuration for registrar. if (configuration.enableRegistrations) { String value=configuration.registrationsFile; CallLauncherDebug.println("Parsing the XML registrations file: "+value); if (value==null || value.trim().equals("")) CallLauncherDebug.println("You have to set the registrations file..."); else registrar.parseXMLregistrations(value); } else CallLauncherDebug.println("No registrations to parse..."); } else { CallLauncherDebug.println("CallLauncher, ERROR: the configuration file is not correct!"+ " Correct the errors first."); } } public void initCalls(Agent firstAgent, Agent secondAgent) { callListener.initCalls(firstAgent,secondAgent); } public Vector getCallerAgentList() { return configuration.callerAgentsList; } /** Stop the stacks, this method has to be called after the start method * throws Exception that which can be caught by the upper application */ public void stop() throws Exception { if (callListener.sipStacksList==null) { CallLauncherDebug.println ("WARNING, STOP_LAUNCHER, No stack to stop!!!"); return; } for ( int i=0; i<callListener.sipStacksList.size();i++) { SipStack sipStack=(SipStack)callListener.sipStacksList.elementAt(i); Iterator listeningPoints=sipStack.getListeningPoints(); if (listeningPoints!=null) { while( listeningPoints.hasNext()) { ListeningPoint lp=(ListeningPoint)listeningPoints.next(); sipStack.deleteListeningPoint(lp); CallLauncherDebug.println("One listening point removed for the stack: "+ sipStack.getStackName() ); } } else { CallLauncherDebug.println ("WARNING, STOP_LAUNCHER, The stack: "+sipStack.getStackName() +" has no listening "+ " points to remove!"); } } } /******************************************************************************//************ The main method: to launch the CallLauncher *******************//******************************************************************************/ public static void main(String args[]) { try{ // the CallLauncher: //String confFile= (String) args[1]; CallLauncher callLauncher=new CallLauncher(".//gov//nist//examples//pcc//configuration//configuration_3pcc.xml"); callLauncher.start(); CallLauncherDebug.println("Controller ready to work"); } catch(Exception e) { System.out.println ("ERROR: Set the configuration file flag: " + "USE: -cf configuration_file_location.xml" ); System.out.println("ERROR, the CallLauncher can not be started, " + " exception raised:\n"); e.printStackTrace(); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -