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

    private SessionType sessionType;
    private JID address;
    private StreamID streamID;
    private Packet packet;

    public ProcessPacketTask() {
        super();
    }

    ProcessPacketTask(RemoteSession remoteSession, JID address, Packet packet) {
        if (remoteSession instanceof RemoteClientSession) {
            this.sessionType = SessionType.client;
        }
        else if (remoteSession instanceof RemoteOutgoingServerSession) {
            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.packet = packet;
    }

    ProcessPacketTask(StreamID streamID, Packet packet) {
        this.sessionType = SessionType.incomingServer;
        this.streamID = streamID;
        this.packet = packet;
    }

    public Void getResult() {
        return null;
    }

    public void run() {
        getSession().process(packet);
    }

    public void writeExternal(ObjectOutput out) throws IOException {
        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() );
        }
        ExternalizableUtil.getInstance().writeInt(out, sessionType.ordinal());
        if (packet instanceof IQ) {
            ExternalizableUtil.getInstance().writeInt(out, 1);
        } else if (packet instanceof Message) {
            ExternalizableUtil.getInstance().writeInt(out, 2);
        } else if (packet instanceof Presence) {
            ExternalizableUtil.getInstance().writeInt(out, 3);
        }
        ExternalizableUtil.getInstance().writeSerializable(out, (DefaultElement) packet.getElement());
    }

    public void readExternal(ObjectInput in) throws IOException {
        if (ExternalizableUtil.getInstance().readBoolean(in)) {
            address = (JID) ExternalizableUtil.getInstance().readSerializable(in);
        }
        if (ExternalizableUtil.getInstance().readBoolean(in)) {
            streamID = BasicStreamIDFactory.createStreamID( ExternalizableUtil.getInstance().readSafeUTF(in) );
        }
        sessionType = SessionType.values()[ExternalizableUtil.getInstance().readInt(in)];
        int packetType = ExternalizableUtil.getInstance().readInt(in);
        Element packetElement = (Element) ExternalizableUtil.getInstance().readSerializable(in);
        switch (packetType) {
            case 1:
                packet = new IQ(packetElement, true);
                break;
            case 2:
                packet = new Message(packetElement, true);
                break;
            case 3:
                packet = new Presence(packetElement, true);
                break;
        }
    }

    Session getSession() {<FILL_FUNCTION_BODY>}

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

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

        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) {
            final DomainPair pair = new DomainPair(packet.getFrom().getDomain(), address.getDomain());
            return SessionManager.getInstance().getOutgoingServerSession(pair);
        }
        else if (sessionType == SessionType.incomingServer) {
            return SessionManager.getInstance().getIncomingServerSession(streamID);
        }
        Log.error("Found unknown session type: " + sessionType);
        return null;
    
<no_super_class>