Class containerClass = loader.loadClass("org.jivesoftware.messenger.XMPPServer");
containerClass.newInstance();
|
public void start() {
try {
initialize();
// If the server has already been setup then we can start all the server's modules
if (!setupMode) {
verifyDataSource();
// First load all the modules so that modules may access other modules while
// being initialized
loadModules()
;
// Initize all the modules
initModules();
// Start all the modules
startModules();
}
// Load plugins. First, initialize component manager.
InternalComponentManager.getInstance().start();
File pluginDir = new File(messengerHome, "plugins");
pluginManager = new PluginManager(pluginDir);
pluginManager.start();
…….
}
catch (Exception e) {
…..
shutdownServer();
}
}
|
private void loadModules() {
// Load boot modules
loadModule(RoutingTableImpl.class.getName());
loadModule(AuditManagerImpl.class.getName());
loadModule(RosterManager.class.getName());
loadModule(PrivateStorage.class.getName());
// Load core modules
loadModule(PresenceManagerImpl.class.getName());
loadModule(SessionManager.class.getName());
loadModule(PacketRouter.class.getName());
loadModule(IQRouter.class.getName());
loadModule(MessageRouter.class.getName());
loadModule(PresenceRouter.class.getName());
loadModule(PacketTransporterImpl.class.getName());
loadModule(PacketDelivererImpl.class.getName());
loadModule(TransportHandler.class.getName());
loadModule(OfflineMessageStrategy.class.getName());
loadModule(OfflineMessageStore.class.getName());
// Load standard modules
loadModule(IQAuthHandler.class.getName());
loadModule(IQPrivateHandler.class.getName());
loadModule(IQRegisterHandler.class.getName());
loadModule(IQRosterHandler.class.getName());
loadModule(IQTimeHandler.class.getName());
loadModule(IQvCardHandler.class.getName());
loadModule(IQVersionHandler.class.getName());
loadModule(IQLastActivityHandler.class.getName());
loadModule(PresenceSubscribeHandler.class.getName());
loadModule(PresenceUpdateHandler.class.getName());
loadModule(IQDiscoInfoHandler.class.getName());
loadModule(IQDiscoItemsHandler.class.getName());
loadModule(IQOfflineMessagesHandler.class.getName());
loadModule(MultiUserChatServerImpl.class.getName());
loadModule(MulticastDNSService.class.getName());
// Load this module always last since we don't want to start listening for clients
// before the rest of the modules have been started
loadModule(ConnectionManagerImpl.class.getName());
}
|
public void start() {
super.start();
isStarted = true;
serverName = server.getServerInfo().getName();
createSocket();
SocketSendingTracker.getInstance().start();
}
|
//ConnectionManagerImpl.java
public void initialize(XMPPServer server) {
super.initialize(server);
this.server = server;
router
= server.getPacketRouter();
deliverer
= server.getPacketDeliverer();
sessionManager
= server.getSessionManager();
}
|
//ConnectionManagerImpl.java
public void start() {
super.start();
isStarted = true;
serverName = server.getServerInfo().getName();
createSocket();
SocketSendingTracker.getInstance().start();
}
|
//ConnectionManagerImpl.java
private void createSocket() {
……
// Start the port listener for s2s communication
startServerListener(localIPAddress);
// Start the port listener for external components
startComponentListener(localIPAddress);
// Start the port listener for clients
startClientListeners(localIPAddress);
// Start the port listener for secured clients
startClientSSLListeners(localIPAddress);
}
|
//ConnectionManagerImpl.java
private void startClientListeners(String localIPAddress) {
……
try {
socketThread = new
SocketAcceptThread
(this, serverPort);
ports.add(serverPort);
socketThread.setDaemon(true);
socketThread.start();
……
}
catch (Exception e) {
…..
}
}
}
|
// SocketAcceptTread.java
public void run() {
while (notTerminated) {
try {
Socket sock = serverSocket.accept();
if (sock != null) {
Log.debug("Connect " + sock.toString());
connManager.addSocket(sock, false, serverPort);
}
}
catch (IOException ie) {
…..
}
…..
}
//
线程结束的时候后面处理关闭
serverSocket
……
}
|
//ConnectionManagerImpl.java
public void addSocket(Socket
sock
, boolean isSecure, ServerPort serverPort) {
try {
SocketConnection conn = new SocketConnection(deliverer,
sock
, isSecure);
SocketReader reader = null;
String threadName = null;
if (serverPort.isClientPort()) {
reader
= new ClientSocketReader(router, serverName,
sock
,
conn
);
threadName = "Client SR";
}
else if (serverPort.isComponentPort()) {
reader = new ComponentSocketReader(router, serverName, sock, conn);
threadName = "Component SR";
}
else {
reader = new ServerSocketReader(router, serverName, sock, conn);
threadName = "Server SR";
}
Thread thread = new Thread(reader, threadName);
thread.setDaemon(true);
thread.start();
}
catch (IOException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
|
//SocketReader.java
public void run() {
try {
reader = new XPPPacketReader();
reader.setXPPFactory(factory);
reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(),
CHARSET));
// Read in the opening tag and prepare for packet stream
try {
//socketReader
启动的时,需要创建一个
Session
来负责和
Client
的会话
createSession();
}
catch (IOException e) {
…..
}
//
会话结束后的处理
if (session != null) {
readStream();
}
}
catch (EOFException eof) {
// Normal disconnect
}
}
|
//ClientSocketReader.java
Boolean createSession(String namespace) …{
if ("jabber:client".equals(namespace)) {
// ClientSession
负责创建一个
ClientSession
session = ClientSession.createSession(serverName, reader, connection);
return true;
}
return false;
}
|
//ClientSeesion.java
public static Session createSession(String serverName, XPPPacketReader reader,
SocketConnection connection)
throws XmlPullParserException, UnauthorizedException,IOException{
……
//
为用户创建一个
Session
Session session = SessionManager.getInstance().createClientSession(connection);
Writer writer = connection.getWriter();
//
创建
packet response
的开头
……
boolean done = false;
while (!done) {
if (xpp.next() == XmlPullParser.START_TAG) {
done = true;
if (xpp.getName().equals("starttls") &&
xpp.getNamespace(xpp.getPrefix()).equals(TLS_NAMESPACE))
{
writer.write("
if (isFlashClient) {
writer.write('/0');
}
writer.flush();
// TODO: setup SSLEngine and negotiate TLS.
}
}
}
return session;}
|
//SessionManager.java
public Session createClientSession(Connection conn) throws UnauthorizedException {
if (serverName == null) {
throw new UnauthorizedException("Server not initialized");
}
StreamID id = nextStreamID();
ClientSession session = new ClientSession(serverName, conn, id);
conn.init(session);
// Register to receive close notification on this session so we can
// remove and also send an unavailable presence if it wasn't
// sent before
conn.registerCloseListener(clientSessionListener, session);
// Add to pre-authenticated sessions.
preAuthenticatedSessions.put(session.getAddress().toString(), session);
return session;
}
|