Search in sources :

Example 1 with ConnectionMultiplexerSession

use of org.jivesoftware.openfire.session.ConnectionMultiplexerSession in project Openfire by igniterealtime.

the class SessionManager method getConnectionMultiplexerSessions.

/**
     * Returns a collection with all the sessions originated from the connection manager
     * whose domain matches the specified domain. If there is no connection manager with
     * the specified domain then an empty list is going to be returned.
     *
     * @param domain the domain of the connection manager.
     * @return a collection with all the sessions originated from the connection manager
     *         whose domain matches the specified domain.
     */
public List<ConnectionMultiplexerSession> getConnectionMultiplexerSessions(String domain) {
    List<ConnectionMultiplexerSession> sessions = new ArrayList<>();
    // Add sessions of CMs connected to this JVM
    for (String address : localSessionManager.getConnnectionManagerSessions().keySet()) {
        JID jid = new JID(address);
        if (domain.equals(jid.getDomain())) {
            sessions.add(localSessionManager.getConnnectionManagerSessions().get(address));
        }
    }
    // Add sessions of CMs connected to other cluster nodes
    RemoteSessionLocator locator = server.getRemoteSessionLocator();
    if (locator != null) {
        for (Map.Entry<String, byte[]> entry : multiplexerSessionsCache.entrySet()) {
            if (!server.getNodeID().equals(entry.getValue())) {
                JID jid = new JID(entry.getKey());
                if (domain.equals(jid.getDomain())) {
                    sessions.add(locator.getConnectionMultiplexerSession(entry.getValue(), new JID(entry.getKey())));
                }
            }
        }
    }
    return sessions;
}
Also used : LocalConnectionMultiplexerSession(org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession) ConnectionMultiplexerSession(org.jivesoftware.openfire.session.ConnectionMultiplexerSession) JID(org.xmpp.packet.JID) RemoteSessionLocator(org.jivesoftware.openfire.session.RemoteSessionLocator) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with ConnectionMultiplexerSession

use of org.jivesoftware.openfire.session.ConnectionMultiplexerSession in project Openfire by igniterealtime.

the class SessionManager method getConnectionMultiplexerSessions.

/**
     * Returns all sessions originated from connection managers.
     *
     * @return all sessions originated from connection managers.
     */
public List<ConnectionMultiplexerSession> getConnectionMultiplexerSessions() {
    List<ConnectionMultiplexerSession> sessions = new ArrayList<>();
    // Add sessions of CMs connected to this JVM
    sessions.addAll(localSessionManager.getConnnectionManagerSessions().values());
    // Add sessions of CMs connected to other cluster nodes
    RemoteSessionLocator locator = server.getRemoteSessionLocator();
    if (locator != null) {
        for (Map.Entry<String, byte[]> entry : multiplexerSessionsCache.entrySet()) {
            if (!server.getNodeID().equals(entry.getValue())) {
                sessions.add(locator.getConnectionMultiplexerSession(entry.getValue(), new JID(entry.getKey())));
            }
        }
    }
    return sessions;
}
Also used : LocalConnectionMultiplexerSession(org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession) ConnectionMultiplexerSession(org.jivesoftware.openfire.session.ConnectionMultiplexerSession) RemoteSessionLocator(org.jivesoftware.openfire.session.RemoteSessionLocator) JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 3 with ConnectionMultiplexerSession

use of org.jivesoftware.openfire.session.ConnectionMultiplexerSession in project Openfire by igniterealtime.

the class ClientSessionConnection method closeVirtualConnection.

/**
     * If the Connection Manager or the Client requested to close the connection then just do
     * nothing. But if the server originated the request to close the connection then we need
     * to send to the Connection Manager a packet letting him know that the Client Session needs
     * to be terminated.
     */
@Override
public void closeVirtualConnection() {
    // Figure out who requested the connection to be closed
    StreamID streamID = session.getStreamID();
    if (multiplexerManager.getClientSession(connectionManagerName, streamID) == null) {
    // Client or Connection manager requested to close the session
    // Do nothing since it has already been removed and closed
    } else {
        ConnectionMultiplexerSession multiplexerSession = multiplexerManager.getMultiplexerSession(connectionManagerName, streamID);
        if (multiplexerSession != null) {
            // Server requested to close the client session so let the connection manager
            // know that he has to finish the client session
            IQ closeRequest = new IQ(IQ.Type.set);
            closeRequest.setFrom(serverName);
            closeRequest.setTo(connectionManagerName);
            Element child = closeRequest.setChildElement("session", "http://jabber.org/protocol/connectionmanager");
            child.addAttribute("id", streamID.getID());
            child.addElement("close");
            multiplexerSession.process(closeRequest);
        }
    }
}
Also used : StreamID(org.jivesoftware.openfire.StreamID) ConnectionMultiplexerSession(org.jivesoftware.openfire.session.ConnectionMultiplexerSession) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ)

Example 4 with ConnectionMultiplexerSession

use of org.jivesoftware.openfire.session.ConnectionMultiplexerSession in project Openfire by igniterealtime.

the class ClientSessionConnection method deliver.

/**
     * Delivers the packet to the Connection Manager that in turn will forward it to the
     * target user. Connection Managers may have one or many connections to the server so
     * just get any connection to the Connection Manager (uses a random) and use it.<p>
     *
     * If the packet to send does not have a TO attribute then wrap the packet with a
     * special IQ packet. The wrapper IQ packet will be sent to the Connection Manager
     * and the stream ID of this Client Session will be used for identifying that the wrapped
     * packet must be sent to the connected user. Since some packets can be exchanged before
     * the user has a binded JID we need to use the stream ID as the unique identifier.
     *
     * @param packet the packet to send to the user.
     */
@Override
public void deliver(Packet packet) {
    StreamID streamID = session.getStreamID();
    ConnectionMultiplexerSession multiplexerSession = multiplexerManager.getMultiplexerSession(connectionManagerName, streamID);
    if (multiplexerSession != null) {
        // Wrap packet so that the connection manager can figure out the target session
        Route wrapper = new Route(streamID);
        wrapper.setFrom(serverName);
        wrapper.setTo(connectionManagerName);
        wrapper.setChildElement(packet.getElement().createCopy());
        // Deliver wrapper
        multiplexerSession.process(wrapper);
        session.incrementServerPacketCount();
    }
}
Also used : StreamID(org.jivesoftware.openfire.StreamID) ConnectionMultiplexerSession(org.jivesoftware.openfire.session.ConnectionMultiplexerSession)

Example 5 with ConnectionMultiplexerSession

use of org.jivesoftware.openfire.session.ConnectionMultiplexerSession in project Openfire by igniterealtime.

the class ClientSessionConnection method deliverRawText.

/**
     * Delivers the stanza to the Connection Manager that in turn will forward it to the
     * target user. Connection Managers may have one or many connections to the server so
     * just get any connection to the Connection Manager (uses a random) and use it.<p>
     *
     * The stanza to send wrapped with a special IQ packet. The wrapper IQ packet will be
     * sent to the Connection Manager and the stream ID of this Client Session will be used
     * for identifying that the wrapped stanza must be sent to the connected user.
     *
     * @param text the stanza to send to the user.
     */
@Override
public void deliverRawText(String text) {
    StreamID streamID = session.getStreamID();
    ConnectionMultiplexerSession multiplexerSession = multiplexerManager.getMultiplexerSession(connectionManagerName, streamID);
    if (multiplexerSession != null) {
        // Wrap packet so that the connection manager can figure out the target session
        StringBuilder sb = new StringBuilder(200 + text.length());
        sb.append("<route from=\"").append(serverName);
        sb.append("\" to=\"").append(connectionManagerName);
        sb.append("\" streamid=\"").append(streamID.getID()).append("\">");
        sb.append(text);
        sb.append("</route>");
        // Deliver the wrapped stanza
        multiplexerSession.deliverRawText(sb.toString());
    }
}
Also used : StreamID(org.jivesoftware.openfire.StreamID) ConnectionMultiplexerSession(org.jivesoftware.openfire.session.ConnectionMultiplexerSession)

Aggregations

ConnectionMultiplexerSession (org.jivesoftware.openfire.session.ConnectionMultiplexerSession)5 StreamID (org.jivesoftware.openfire.StreamID)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 LocalConnectionMultiplexerSession (org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession)2 RemoteSessionLocator (org.jivesoftware.openfire.session.RemoteSessionLocator)2 JID (org.xmpp.packet.JID)2 Element (org.dom4j.Element)1 IQ (org.xmpp.packet.IQ)1