AffiliationTask.java 2.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 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
package org.jivesoftware.openfire.pubsub.cluster;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import org.jivesoftware.openfire.pubsub.Node;
import org.jivesoftware.openfire.pubsub.NodeAffiliate;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;

public class AffiliationTask extends NodeTask
{
    private static final Logger log = LoggerFactory.getLogger(AffiliationTask.class);

    private JID jid;
	private NodeAffiliate.Affiliation affiliation;

	public AffiliationTask()
	{
	}

	public AffiliationTask(Node node, JID jid, NodeAffiliate.Affiliation affiliation)
	{
		super(node);
		this.jid = jid;
		this.affiliation = affiliation;
	}

	public JID getJID()
	{
		return jid;
	}

	public NodeAffiliate.Affiliation getAffilation()
	{
		return affiliation;
	}
	
	public void run() {
		log.debug("[TASK] New affiliation : {}", toString());

		Node node = getNode();
		NodeAffiliate affiliate = node.getAffiliate(jid);
		if (affiliate == null) {
        	affiliate = new NodeAffiliate(node, jid);
        	affiliate.setAffiliation(affiliation);
        	node.addAffiliate(affiliate);
		} else {
			affiliate.setAffiliation(affiliation);
		}
	}

	@Override
	public void writeExternal(ObjectOutput out) throws IOException
	{
		super.writeExternal(out);
60 61
        ExternalizableUtil.getInstance().writeSerializable(out, jid);
        ExternalizableUtil.getInstance().writeSerializable(out, affiliation);
62 63 64 65 66 67
	}

	@Override
	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
	{
		super.readExternal(in);
68
		jid = (JID) ExternalizableUtil.getInstance().readSerializable(in);
69 70 71 72 73 74 75 76 77 78
		affiliation = (NodeAffiliate.Affiliation) ExternalizableUtil.getInstance().readSerializable(in);
	}

	@Override
	public String toString()
	{
		return getClass().getSimpleName() + " [(service=" + serviceId + "), (nodeId=" + nodeId + 
				"), (JID=" + jid + "),(affiliation=" + affiliation + ")]";
	}
}