01: /**
02: * $RCSfile: $
03: * $Revision: $
04: * $Date: $
05: *
06: * Copyright (C) 2007 Jive Software. All rights reserved.
07: *
08: * This software is published under the terms of the GNU Public License (GPL),
09: * a copy of which is included in this distribution.
10: */package org.jivesoftware.openfire.muc.spi;
11:
12: import org.jivesoftware.openfire.PacketException;
13: import org.jivesoftware.openfire.auth.UnauthorizedException;
14: import org.jivesoftware.openfire.muc.MUCRole;
15: import org.jivesoftware.openfire.muc.MUCUser;
16: import org.xmpp.packet.*;
17:
18: /**
19: * User hosted by another cluster node that is presente in a local room. Remote users are
20: * only created when processing unavailable presences sent when the node hosting the actual
21: * user went down. Each cluster node remaining in the cluster will create an unavailable
22: * presence for each user hosted in the cluster node that went down as a way to indicate
23: * the remaining room occupants that the user is offline.
24: *
25: * @author Gaston Dombiak
26: */
27: public class RemoteMUCUser implements MUCUser {
28: /**
29: * JID of the user hosted by other cluster node.
30: */
31: private JID realjid;
32: /**
33: * Local room that keep a reference to the RemoteMUCRole for this user.
34: */
35: private LocalMUCRoom room;
36:
37: public RemoteMUCUser(JID realjid, LocalMUCRoom room) {
38: this .realjid = realjid;
39: this .room = room;
40: }
41:
42: public JID getAddress() {
43: return realjid;
44: }
45:
46: public void process(Packet packet) throws UnauthorizedException,
47: PacketException {
48: if (packet instanceof IQ) {
49: throw new UnsupportedOperationException(
50: "Cannot process IQ packets of remote users: "
51: + packet);
52: } else if (packet instanceof Message) {
53: throw new UnsupportedOperationException(
54: "Cannot process Message packets of remote users: "
55: + packet);
56: } else if (packet instanceof Presence) {
57: process((Presence) packet);
58: }
59: }
60:
61: private void process(Presence presence) {
62: if (presence.getType() == Presence.Type.unavailable) {
63: MUCRole mucRole = room.getOccupantByFullJID(realjid);
64: if (mucRole != null) {
65: room.leaveRoom(mucRole);
66: }
67: } else {
68: throw new UnsupportedOperationException(
69: "Cannot process Presence packets of remote users: "
70: + presence);
71: }
72: }
73: }
|