?? smscconnectionmanager.java
字號:
package smgpgw;
import java.io.*;
import java.net.*;
import java.util.*;
import java.lang.*;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2002
* Company: TALKWEB LTD.
* @author Li yongjun
* @version 2.0
*/
public class SMSCConnectionManager {
private int mysize;
private String myname;
private ServerSocket ServerSocket = null;
private boolean smscStopFlag = false;
public static Hashtable SmppHost = null;
private static Hashtable myconnection = null;
private ServerListenThread svrLsnMOThread = null;
private ServerListenThread svrLsnMTThread = null;
private static SMSCConnectionManager smsc = null;
public String getName() {
return myname;
}
public int getSize() {
return myconnection.size();
}
public SMSCConnectionManager(String name, int size) {
myname = name;
mysize = size > 0 ? size : 1;
SmppHost = new Hashtable(10);
myconnection = new Hashtable (size);
}
public static SMSCConnectionManager instance() {
if(smsc == null)
smsc = new SMSCConnectionManager("TW SMGPConnectionManager", 4);
return smsc;
}
public boolean setupSMSCServer(String name,int Port) {
try {
if(ServerSocket != null) {
try {
ServerSocket.close();
} catch(Exception e) { }
}
ServerSocket = new ServerSocket(Port );
Thread Server = new Thread(new Runnable() {
public void run()
{
while(!smscStopFlag){
try
{
Socket socket = ServerSocket.accept();
SmgpServer.startSmgpServer(socket);
SMSCConnectionManager.instance().addHost(ServerSocket.getInetAddress().getLocalHost().getHostAddress(),
ServerSocket.getInetAddress().getLocalHost().getHostAddress());
SMSCFrame.RecvArea.append("One Socket created .\n");
try{
Thread.sleep(1000) ;
}catch (Exception e){}
}
catch (IOException ex) {
System.out.println("error : socket at "+"setupConnection()");
}
}
}
});
Server.start();
SMSCFrame.RecvArea.append("Create ISMG server Listener succeed .\n");
SMSCFrame.RecvArea.append("Listen Server name = " + ServerSocket.getInetAddress().getLocalHost().getHostName() +
" address = " + ServerSocket.getInetAddress().getLocalHost().getHostAddress() +
" port = " + Port + "\n");
return true;
} catch (Exception e) {
SMSCFrame.RecvArea.append("Create ISMG server exception, " +
e.getMessage() + " .\n");
return false;
}
}
public boolean stopSMSCServer() {
int i, nHostSize = 0;
//String strConnID, strDest;
// Enumeration AllHost = null;
// SMSCConnection tmpConn = null;
try {
if(null != SmgpServer.instance())
SmgpServer.instance().stopServer();
smscStopFlag = true;
this.ServerSocket.close();
this.SmppHost.clear();
} catch(Exception eHost) {
System.out.println(eHost);
return false;
}
return true;
}
public boolean send(SmscShortMsg smpp)
{
SmgpData smgpData = ProtocolConverter.Smpptosmgp(smpp);
smgpData.MsgID=SmgpServer.getMsgID();
SmgpServer.instance().sendDeliver(smgpData);
return true;
}
public boolean removeHost(String hostIP) {
try {
SmppHost.remove(hostIP);
return true;
} catch(Exception e) {
return false;
}
}
public boolean addHost(String host, String hostIP) {
try {
SmppHost.put(host, hostIP);
//SMSCFrame.RecvArea.append("Add " + host + " to hash table succeed .\n");
return true;
} catch(Exception e) {
SMSCFrame.RecvArea.append("Insert host address to hash table failed .\n");
return false;
}
}
public SMSCConnection route(String smppID) {
try {
return (SMSCConnection) myconnection.get(smppID);
} catch(Exception e) {
SMSCFrame.SendArea.append("SMSC manager could not find peer " + smppID + " .\n");
return null;
}
}
public void setConncection(String smppID, SmgpServer sc) {
try {
myconnection.put(smppID, sc);
} catch(Exception e) {
SMSCFrame.RecvArea.append(" Insert SMSC connetion handle to hash table failed .\n");
}
}
public void delConnection(String smppID) {
try {
myconnection.remove(smppID);
} catch(Exception e) { }
}
public boolean isConncected(String smppID) {
if( myconnection.containsKey(smppID) )
return true;
else
return false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -