aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/xmpp/s2s/Shutdown.java
blob: fb3543f81d744b8e4d3d2baf7743f2507374f8ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.juick.xmpp.s2s;

import java.sql.SQLException;
import java.util.Iterator;

/**
 *
 * @author ugnich
 */
public class Shutdown extends Thread {

    @Override
    public void run() {
        System.out.println("SHUTTING DOWN");

        synchronized (XMPPComponent.outConnections) {
            for (Iterator<ConnectionOut> i = XMPPComponent.outConnections.iterator(); i.hasNext();) {
                ConnectionOut c = i.next();
                c.closeConnection();
                i.remove();
            }
        }

        synchronized (XMPPComponent.inConnections) {
            for (Iterator<ConnectionIn> i = XMPPComponent.inConnections.iterator(); i.hasNext();) {
                ConnectionIn c = i.next();
                c.closeConnection();
                i.remove();
            }
        }

        XMPPComponent.connRouter.closeConnection();

        synchronized (XMPPComponent.sqlSync) {
            if (XMPPComponent.sql != null) {
                try {
                    XMPPComponent.sql.close();
                    XMPPComponent.sql = null;
                } catch (SQLException e) {
                    System.err.println("SQL ERROR: " + e);
                }
            }
        }
    }
}