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

    protected Object result;
    protected Operation operation;

    public RemoteSessionTask() {
    }

    protected RemoteSessionTask(Operation operation) {
        this.operation = operation;
    }

    abstract Session getSession();

    public Object getResult() {
        return result;
    }

    public void run() {
        if (operation == Operation.getStreamID) {
            result = getSession().getStreamID();
        }
        else if (operation == Operation.getServerName) {
            result = getSession().getServerName();
        }
        else if (operation == Operation.getCreationDate) {
            result = getSession().getCreationDate();
        }
        else if (operation == Operation.getLastActiveDate) {
            result = getSession().getLastActiveDate();
        }
        else if (operation == Operation.getNumClientPackets) {
            result = getSession().getNumClientPackets();
        }
        else if (operation == Operation.getNumServerPackets) {
            result = getSession().getNumServerPackets();
        }
        else if (operation == Operation.getTLSProtocolName) {
            result = getSession().getTLSProtocolName();
        }
        else if (operation == Operation.getCipherSuiteName) {
            result = getSession().getCipherSuiteName();
        }
        else if (operation == Operation.getPeerCertificates) {
            result = getSession().getPeerCertificates();
        }
        else if (operation == Operation.getSoftwareVersion) {
            result = getSession().getSoftwareVersion();
        }
        else if (operation == Operation.close) {
            // Run in another thread so we avoid blocking calls (in hazelcast) 
            final Session session = getSession();
            if (session != null) {
                final Future<?> future = TaskEngine.getInstance().submit( () -> {
                    try {
                        if (session instanceof LocalSession) {
                            // OF-2311: If closed by another cluster node, chances are that the session needs to be closed forcibly.
                            // Chances of the session being resumed are neglectable, while retaining the session in a detached state
                            // causes problems (eg: IQBindHandler could have re-issued the resource to a replacement session).
                            ((LocalSession) session).getStreamManager().formalClose();
                        }
                        session.close();
                    } catch (Exception e) {
                        Log.info("An exception was logged while closing session: {}", session, e);
                    }
                });
                // Wait until the close operation is done or timeout is met
                try {
                    future.get(15, TimeUnit.SECONDS);
                }
                catch (Exception e) {
                    Log.info("An exception was logged while executing RemoteSessionTask to close session: {}", session, e);
                }
            }
        }
        else if (operation == Operation.isClosed) {
            result = getSession().isClosed();
        }
        else if (operation == Operation.isEncrypted) {
            result = getSession().isEncrypted();
        }
        else if (operation == Operation.getHostAddress) {
            try {
                result = getSession().getHostAddress();
            } catch (UnknownHostException e) {
                Log.error("Error getting address of session: " + getSession(), e);
            }
        }
        else if (operation == Operation.getHostName) {
            try {
                result = getSession().getHostName();
            } catch (UnknownHostException e) {
                Log.error("Error getting address of session: " + getSession(), e);
            }
        }
        else if (operation == Operation.validate) {
            result = getSession().validate();
        }
        else if (operation == Operation.removeDetached) {
            final Session session = getSession();
            if (session instanceof LocalSession) {
                Log.debug("Terminating local session as instructed by another cluster node: {}", session);

                final Future<?> future = TaskEngine.getInstance().submit( () -> {
                    try {
                        SessionManager.getInstance().terminateDetached((LocalSession) session);
                    } catch (Exception e) {
                        Log.info("An exception was logged while closing session: {}", session, e);
                    }
                });
                // Wait until the close operation is done or timeout is met
                try {
                    future.get(15, TimeUnit.SECONDS);
                }
                catch (Exception e) {
                    Log.info("An exception was logged while executing RemoteSessionTask to close session: {}", session, e);
                }
            }
        }
    }

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

    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        if (ExternalizableUtil.getInstance().readBoolean(in)) {
            operation = Operation.values()[ExternalizableUtil.getInstance().readInt(in)];
        }
    }

    public enum Operation {
        /**
         * Basic session operations
         */
        getStreamID,
        getServerName,
        getCreationDate,
        getLastActiveDate,
        getNumClientPackets,
        getNumServerPackets,
        getTLSProtocolName,
        getCipherSuiteName,
        getPeerCertificates,
        getSoftwareVersion,
        close,
        isClosed,
        @Deprecated isSecure, // Replaced with 'isEncrypted', replace in Openfire 4.9 or later.
        isEncrypted,
        getHostAddress,
        getHostName,
        validate,
        removeDetached,
        
        /**
         * Operations of c2s sessions
         */
        isInitialized,
        incrementConflictCount,
        hasRequestedBlocklist,
        
        /**
         * Operations of outgoing server sessions
         */
        getOutgoingDomainPairs,
        getAuthenticationMethod,

        /**
         * Operations of external component sessions
         */
        getType,
        getCategory,
        getInitialSubdomain,
        getSubdomains,
        getName,
        getDescription,
        start,
        shutdown,

        /**
         * Operations of incoming server sessions
         */
        getLocalDomain,
        getAddress,
        getValidatedDomains
    }
}

        ExternalizableUtil.getInstance().writeBoolean(out, operation != null);
        if (operation != null) {
            ExternalizableUtil.getInstance().writeInt(out, operation.ordinal());
        }
    
<no_super_class>