ConnectionManagerImpl.java 1.91 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
6
 * Copyright (C) 2004 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
8 9
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10
 */
11

Matt Tucker's avatar
Matt Tucker committed
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
package org.jivesoftware.net.spi;

import org.jivesoftware.net.ConnectionManager;
import org.jivesoftware.net.Connection;
import org.jivesoftware.net.ConnectionMonitor;

import java.util.Iterator;

import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.util.ConcurrentHashSet;
import org.jivesoftware.util.BasicResultFilter;

public class ConnectionManagerImpl extends BasicModule implements ConnectionManager {

    private ConcurrentHashSet connections = new ConcurrentHashSet();
    private ConnectionMonitor connectedMonitor = new TransientConnectionMonitor();
    private ConnectionMonitor configMonitor = new TransientConnectionMonitor();
    private ConnectionMonitor disconnectedMonitor = new TransientConnectionMonitor();

    public ConnectionManagerImpl() {
        super("Connection Manager");
    }

    public int getConnectionCount() {
        return connections.size();
    }

    public Iterator getConnections() {
        return connections.iterator();
    }

    public Iterator getConnections(BasicResultFilter filter) {
        return filter.filter(connections.iterator());
    }

    public void addConnection(Connection conn) {
        connections.add(conn);
        conn.setConnectionManager(this);
        connectedMonitor.addSample(conn);
    }

    public void removeConnection(Connection conn) {
        connections.remove(conn);
        disconnectedMonitor.addSample(conn);
    }

    public ConnectionMonitor getConnectedMonitor() {
        return connectedMonitor;
    }

    public ConnectionMonitor getConfigMonitor() {
        return configMonitor;
    }

    public ConnectionMonitor getDisconnectedMonitor() {
        return disconnectedMonitor;
    }
}