Search in sources :

Example 1 with TransportInstance

use of net.sf.kraken.TransportInstance in project Openfire by igniterealtime.

the class TransportSessionRouter method leftCluster.

/**
     * @see org.jivesoftware.openfire.cluster.ClusterEventListener#leftCluster(byte[])
     */
public void leftCluster(byte[] leavingNodeID) {
    KrakenPlugin plugin = getPlugin();
    // TODO: Is this correct?  Lets say another node updates an entry before I get to it, will I see the update?
    for (Map.Entry<String, byte[]> entry : sessionLocations.entrySet()) {
        if (Arrays.equals(entry.getValue(), leavingNodeID)) {
            Lock l = CacheFactory.getLock(entry.getKey() + "lc", sessionLocations);
            try {
                l.lock();
                String jid = entry.getKey().substring(0, entry.getKey().lastIndexOf("@"));
                String trType = entry.getKey().substring(entry.getKey().lastIndexOf("@") + 1);
                Log.debug("Kraken: Node handling session " + jid + " on " + trType + " lost, taking over session...");
                sessionLocations.remove(jid + "@" + trType);
                TransportInstance trInstance = plugin.getTransportInstance(trType);
                if (trInstance != null) {
                    BaseTransport<? extends TransportBuddy> transport = trInstance.getTransport();
                    if (transport != null) {
                        Collection<ClientSession> sessions = XMPPServer.getInstance().getSessionManager().getSessions(new JID(jid).getNode());
                        for (ClientSession session : sessions) {
                            transport.processPacket(session.getPresence());
                        }
                    }
                }
            } finally {
                l.unlock();
            }
        }
    }
}
Also used : JID(org.xmpp.packet.JID) ClientSession(org.jivesoftware.openfire.session.ClientSession) TransportInstance(net.sf.kraken.TransportInstance) KrakenPlugin(net.sf.kraken.KrakenPlugin) Map(java.util.Map) Lock(java.util.concurrent.locks.Lock)

Aggregations

Map (java.util.Map)1 Lock (java.util.concurrent.locks.Lock)1 KrakenPlugin (net.sf.kraken.KrakenPlugin)1 TransportInstance (net.sf.kraken.TransportInstance)1 ClientSession (org.jivesoftware.openfire.session.ClientSession)1 JID (org.xmpp.packet.JID)1