Commit f0de75f6 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed change of role when running in a cluster. JM-1330

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@10229 b35dd754-fafc-0310-a699-88a17e54d16e
parent bc4363fd
...@@ -35,7 +35,7 @@ public class UpdateOccupantRequest extends MUCRoomTask { ...@@ -35,7 +35,7 @@ public class UpdateOccupantRequest extends MUCRoomTask {
private Element answer; private Element answer;
private String nickname; private String nickname;
private int role; private int role;
private int affiliation; private MUCRole.Affiliation affiliation;
public UpdateOccupantRequest() { public UpdateOccupantRequest() {
...@@ -46,7 +46,7 @@ public class UpdateOccupantRequest extends MUCRoomTask { ...@@ -46,7 +46,7 @@ public class UpdateOccupantRequest extends MUCRoomTask {
super(room); super(room);
this.nickname = nickname; this.nickname = nickname;
this.role = newRole.ordinal(); this.role = newRole.ordinal();
this.affiliation = newAffiliation.ordinal(); this.affiliation = newAffiliation;
} }
public String getNickname() { public String getNickname() {
...@@ -58,7 +58,11 @@ public class UpdateOccupantRequest extends MUCRoomTask { ...@@ -58,7 +58,11 @@ public class UpdateOccupantRequest extends MUCRoomTask {
} }
public MUCRole.Affiliation getAffiliation() { public MUCRole.Affiliation getAffiliation() {
return MUCRole.Affiliation.values()[affiliation]; return affiliation;
}
public boolean isAffiliationChanged() {
return affiliation != null;
} }
public Object getResult() { public Object getResult() {
...@@ -80,13 +84,18 @@ public class UpdateOccupantRequest extends MUCRoomTask { ...@@ -80,13 +84,18 @@ public class UpdateOccupantRequest extends MUCRoomTask {
super.writeExternal(out); super.writeExternal(out);
ExternalizableUtil.getInstance().writeSafeUTF(out, nickname); ExternalizableUtil.getInstance().writeSafeUTF(out, nickname);
ExternalizableUtil.getInstance().writeInt(out, role); ExternalizableUtil.getInstance().writeInt(out, role);
ExternalizableUtil.getInstance().writeInt(out, affiliation); ExternalizableUtil.getInstance().writeBoolean(out, affiliation != null);
if (affiliation != null) {
ExternalizableUtil.getInstance().writeInt(out, affiliation.ordinal());
}
} }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in); super.readExternal(in);
nickname = ExternalizableUtil.getInstance().readSafeUTF(in); nickname = ExternalizableUtil.getInstance().readSafeUTF(in);
role = ExternalizableUtil.getInstance().readInt(in); role = ExternalizableUtil.getInstance().readInt(in);
affiliation = ExternalizableUtil.getInstance().readInt(in); if (ExternalizableUtil.getInstance().readBoolean(in)) {
affiliation = MUCRole.Affiliation.values()[ExternalizableUtil.getInstance().readInt(in)];
}
} }
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: 3158 $ * $Revision: 3158 $
* $Date: 2005-12-04 22:55:49 -0300 (Sun, 04 Dec 2005) $ * $Date: 2005-12-04 22:55:49 -0300 (Sun, 04 Dec 2005) $
* *
* Copyright (C) 2008 Jive Software. All rights reserved. * Copyright (C) 2004-2008 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution, or a commercial license * a copy of which is included in this distribution, or a commercial license
...@@ -1145,12 +1145,28 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -1145,12 +1145,28 @@ public class LocalMUCRoom implements MUCRoom {
// Try looking the role in the bare JID list // Try looking the role in the bare JID list
MUCRole role = occupantsByFullJID.get(jid); MUCRole role = occupantsByFullJID.get(jid);
if (role != null) { if (role != null) {
// Update the presence with the new role if (role.isLocal()) {
role.setRole(newRole); // Update the presence with the new role
// Notify the othe cluster nodes to update the occupant role.setRole(newRole);
CacheFactory.doClusterTask(new UpdateOccupant(this, role)); // Notify the othe cluster nodes to update the occupant
// Prepare a new presence to be sent to all the room occupants CacheFactory.doClusterTask(new UpdateOccupant(this, role));
return role.getPresence().createCopy(); // Prepare a new presence to be sent to all the room occupants
return role.getPresence().createCopy();
}
else {
// Ask the cluster node hosting the occupant to make the changes. Note that if the change
// is not allowed a NotAllowedException will be thrown
Element element = (Element) CacheFactory.doSynchronousClusterTask(
new UpdateOccupantRequest(this, role.getNickname(), null, newRole),
role.getNodeID().toByteArray());
if (element != null) {
// Prepare a new presence to be sent to all the room occupants
return new Presence(element, true);
}
else {
throw new NotAllowedException();
}
}
} }
return null; return null;
} }
...@@ -1504,7 +1520,8 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -1504,7 +1520,8 @@ public class LocalMUCRoom implements MUCRoom {
} }
else { else {
Log.error("Tried to update local occupant with info of local occupant?. Occupant nickname: " + Log.error("Tried to update local occupant with info of local occupant?. Occupant nickname: " +
update.getNickname()); update.getNickname() + " new role: " + update.getRole() + " new affiliation: " +
update.getAffiliation());
} }
} }
else { else {
...@@ -1515,7 +1532,9 @@ public class LocalMUCRoom implements MUCRoom { ...@@ -1515,7 +1532,9 @@ public class LocalMUCRoom implements MUCRoom {
public Presence updateOccupant(UpdateOccupantRequest updateRequest) throws NotAllowedException { public Presence updateOccupant(UpdateOccupantRequest updateRequest) throws NotAllowedException {
MUCRole occupantRole = occupants.get(updateRequest.getNickname().toLowerCase()); MUCRole occupantRole = occupants.get(updateRequest.getNickname().toLowerCase());
if (occupantRole != null) { if (occupantRole != null) {
occupantRole.setAffiliation(updateRequest.getAffiliation()); if (updateRequest.isAffiliationChanged()) {
occupantRole.setAffiliation(updateRequest.getAffiliation());
}
occupantRole.setRole(updateRequest.getRole()); occupantRole.setRole(updateRequest.getRole());
// Notify the othe cluster nodes to update the occupant // Notify the othe cluster nodes to update the occupant
CacheFactory.doClusterTask(new UpdateOccupant(this, occupantRole)); CacheFactory.doClusterTask(new UpdateOccupant(this, occupantRole));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment