SocketAcceptThread.java 3 KB
Newer Older
1
/*
2
 * Copyright (C) 2005-2008 Jive Software. All rights reserved.
3
 *
4 5 6 7 8 9 10 11 12 13 14
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
15 16
 */

17
package org.jivesoftware.openfire.net;
18

19
import org.jivesoftware.util.JiveGlobals;
20 21
import org.jivesoftware.openfire.ConnectionManager;
import org.jivesoftware.openfire.ServerPort;
22 23 24 25 26 27

import java.io.IOException;
import java.net.InetAddress;

/**
 * Implements a network front end with a dedicated thread reading
28 29 30 31
 * each incoming socket. Blocking and non-blocking modes are supported.
 * By default blocking mode is used. Use the <i>xmpp.socket.blocking</i>
 * system property to change the blocking mode. Restart the server after making
 * changes to the system property.
32
 *
33
 * @author Gaston Dombiak
34
 * @deprecated Old, pre NIO / MINA code. Should not be used as NIO offers better performance
35
 */
36
@Deprecated
37 38 39 40 41
public class SocketAcceptThread extends Thread {

    /**
     * Holds information about the port on which the server will listen for connections.
     */
42 43
    private final int tcpPort;
    private InetAddress bindInterface;
44

45
    private SocketAcceptingMode acceptingMode;
46

47
    public SocketAcceptThread( int tcpPort, InetAddress bindInterface )
48
            throws IOException {
49 50 51 52
        super("Socket Listener at port " + tcpPort);
        this.tcpPort = tcpPort;
        this.bindInterface = bindInterface;

53
        // Set the blocking reading mode to use
54
        acceptingMode = new BlockingAcceptingMode(tcpPort, bindInterface);
55 56 57 58 59 60 61 62
    }

    /**
     * Retrieve the port this server socket is bound to.
     *
     * @return the port the socket is bound to.
     */
    public int getPort() {
63
        return tcpPort;
64 65 66 67 68 69 70 71
    }

    /**
     * Returns information about the port on which the server is listening for connections.
     *
     * @return information about the port on which the server is listening for connections.
     */
    public ServerPort getServerPort() {
72
        return new ServerPort(tcpPort, null, bindInterface.getHostName(), false, null, ServerPort.Type.server);
73 74 75 76 77 78
    }

    /**
     * Unblock the thread and force it to terminate.
     */
    public void shutdown() {
79
        acceptingMode.shutdown();
80 81 82 83 84 85
    }

    /**
     * About as simple as it gets.  The thread spins around an accept
     * call getting sockets and handing them to the SocketManager.
     */
86 87
    @Override
	public void run() {
88 89 90
        acceptingMode.run();
        // We stopped accepting new connections so close the listener
        shutdown();
91 92
    }
}