NodeChangeTask.java 1.27 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 60 61
package org.jivesoftware.openfire.pubsub.cluster;

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

import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.pubsub.Node;
import org.jivesoftware.util.cache.ClusterTask;
import org.jivesoftware.util.cache.ExternalizableUtil;

/**
 * Base class of clustering tasks for pubsub. It simply stores/retrieves the
 * node.
 * 
 * @author Robin Collier
 * 
 */
public abstract class NodeChangeTask implements ClusterTask
{
	private String nodeId;
	transient private Node node;

	public NodeChangeTask()
	{

	}

	public NodeChangeTask(String nodeIdent)
	{
		nodeId = nodeIdent;
	}

	public NodeChangeTask(Node node)
	{
		this.node = node;
		nodeId = node.getNodeID();
	}

	public void writeExternal(ObjectOutput out) throws IOException
	{
		ExternalizableUtil.getInstance().writeSafeUTF(out, nodeId);
	}

	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
	{
		nodeId = ExternalizableUtil.getInstance().readSafeUTF(in);
	}

	public Node getNode()
	{
		if (node == null)
			node = XMPPServer.getInstance().getPubSubModule().getNode(nodeId);
		return node;
	}

	public String getNodeId()
	{
		return nodeId;
	}
}