class DeliverRawTextTask implements ClusterTask<Void> {
    private static final Logger Log = LoggerFactory.getLogger(DeliverRawTextTask.class);

    private SessionType sessionType;
    private JID address;
    private StreamID streamID;
    private String text;

    public DeliverRawTextTask() {
        super();
    }

    DeliverRawTextTask(RemoteSession remoteSession, JID address, String text) {
        if (remoteSession instanceof RemoteClientSession) {
            this.sessionType = SessionType.client;
        }
        else if (remoteSession instanceof RemoteOutgoingServerSession) {
            Log.error("OutgoingServerSession used with DeliverRawTextTask; should be using DeliverRawTextServerTask: " + remoteSession);
            this.sessionType = SessionType.outgoingServer;
        }
        else if (remoteSession instanceof RemoteComponentSession) {
            this.sessionType = SessionType.component;
        }
        else if (remoteSession instanceof RemoteConnectionMultiplexerSession) {
            this.sessionType = SessionType.connectionManager;
        }
        else {
            Log.error("Invalid RemoteSession was used for task: " + remoteSession);
        }
        this.address = address;
        this.text = text;
    }

    DeliverRawTextTask(StreamID streamID, String text) {
        this.sessionType = SessionType.incomingServer;
        this.streamID = streamID;
        this.text = text;
    }

    public Void getResult() {
        return null;
    }

    public void run() {
        getSession().deliverRawText(text);
    }

    public void writeExternal(ObjectOutput out) throws IOException {<FILL_FUNCTION_BODY>}

    public void readExternal(ObjectInput in) throws IOException {
        text = ExternalizableUtil.getInstance().readSafeUTF(in);
        sessionType = SessionType.values()[ExternalizableUtil.getInstance().readInt(in)];
        if (ExternalizableUtil.getInstance().readBoolean(in)) {
            address = (JID) ExternalizableUtil.getInstance().readSerializable(in);
        }
        if (ExternalizableUtil.getInstance().readBoolean(in)) {
            streamID = BasicStreamIDFactory.createStreamID( ExternalizableUtil.getInstance().readSafeUTF(in) );
        }
    }

    Session getSession() {
        if (sessionType == SessionType.client) {
            return XMPPServer.getInstance().getRoutingTable().getClientRoute(address);
        }
        else if (sessionType == SessionType.component) {
            return SessionManager.getInstance().getComponentSession(address.getDomain());
        }
        else if (sessionType == SessionType.connectionManager) {
            return SessionManager.getInstance().getConnectionMultiplexerSession(address);
        }
        else if (sessionType == SessionType.outgoingServer) {
            Log.error("Trying to write raw data to a server session across the cluster: " + address.toString());
            return null;
        }
        else if (sessionType == SessionType.incomingServer) {
            return SessionManager.getInstance().getIncomingServerSession(streamID);
        }
        Log.error("Found unknown session type: " + sessionType);
        return null;
    }

    public String toString() {
        return super.toString() + " sessionType: " + sessionType + " address: " + address;
    }

    private enum SessionType {
        client,
        outgoingServer,
        incomingServer,
        component,
        connectionManager
    }
}

        ExternalizableUtil.getInstance().writeSafeUTF(out, text);
        ExternalizableUtil.getInstance().writeInt(out, sessionType.ordinal());
        ExternalizableUtil.getInstance().writeBoolean(out, address != null);
        if (address != null) {
            ExternalizableUtil.getInstance().writeSerializable(out, address);
        }
        ExternalizableUtil.getInstance().writeBoolean(out, streamID != null);
        if (streamID != null) {
            ExternalizableUtil.getInstance().writeSafeUTF( out, streamID.getID() );
        }
    
<no_super_class>