class PresenceEventDispatcher {
    private static final Logger Log = LoggerFactory.getLogger(PresenceEventDispatcher.class);

    private static List<PresenceEventListener> listeners =
            new CopyOnWriteArrayList<>();

    /**
     * Registers a listener to receive events.
     *
     * @param listener the listener.
     */
    public static void addListener(PresenceEventListener listener) {<FILL_FUNCTION_BODY>}

    /**
     * Unregisters a listener to receive events.
     *
     * @param listener the listener.
     */
    public static void removeListener(PresenceEventListener listener) {
        listeners.remove(listener);
    }

    /**
     * Notification message indicating that a session that was not available is now
     * available. A session becomes available when an available presence is received.
     * Sessions that are available will have a route in the routing table thus becoming
     * eligible for receiving messages (in particular messages sent to the user bare JID).
     *
     * @param session the session that is now available.
     * @param presence the received available presence.
     */
    public static void availableSession(ClientSession session, Presence presence) {
        if (!listeners.isEmpty()) {
            for (PresenceEventListener listener : listeners) {
                try {
                    listener.availableSession(session, presence);
                } catch (Exception e) {
                    Log.warn("An exception occurred while dispatching a 'availableSession' event!", e);
                }
            }
        }
    }

    /**
     * Notification message indicating that a session that was available is no longer
     * available. A session becomes unavailable when an unavailable presence is received.
     * The entity may still be connected to the server and may send an available presence
     * later to indicate that communication can proceed.
     *
     * @param session the session that is no longer available.
     * @param presence the received unavailable presence.
     */
    public static void unavailableSession(ClientSession session, Presence presence) {
        if (!listeners.isEmpty()) {
            for (PresenceEventListener listener : listeners) {
                try {
                    listener.unavailableSession(session, presence);
                } catch (Exception e) {
                    Log.warn("An exception occurred while dispatching a 'unavailableSession' event!", e);
                }
            }
        }
    }


    /**
     * Notification message indicating that an available session has changed its
     * presence. This is the case when the user presence changed the show value
     * (e.g. away, dnd, etc.) or the presence status message.
     *
     * @param session the affected session.
     * @param presence the received available presence with the new information.
     */
    public static void presenceChanged(ClientSession session, Presence presence) {
        if (!listeners.isEmpty()) {
            for (PresenceEventListener listener : listeners) {
                try {
                    listener.presenceChanged(session, presence); 
                } catch (Exception e) {
                    Log.warn("An exception occurred while dispatching a 'presenceChanged' event!", e);
                }
            }
        }
    }

    /**
     * Notification message indicating that a user has successfully subscribed
     * to the presence of another user.
     * 
     * @param subscriberJID the user that initiated the subscription.
     * @param authorizerJID the user that authorized the subscription.
     */
    public static void subscribedToPresence(JID subscriberJID, JID authorizerJID) {
        if (!listeners.isEmpty()) {
            for (PresenceEventListener listener : listeners) {
                try {
                    listener.subscribedToPresence(subscriberJID, authorizerJID);   
                } catch (Exception e) {
                    Log.warn("An exception occurred while dispatching a 'subscribedToPresence' event!", e);
                }
            }
        }
    }
    
    /**
     * Notification message indicating that a user has unsubscribed
     * to the presence of another user.
     * 
     * @param unsubscriberJID the user that initiated the unsubscribe request.
     * @param recipientJID    the recipient user of the unsubscribe request.
     */
    public static void unsubscribedToPresence(JID unsubscriberJID, JID recipientJID) {
        if (!listeners.isEmpty()) {
            for (PresenceEventListener listener : listeners) {
                try {
                    listener.unsubscribedToPresence(unsubscriberJID, recipientJID); 
                } catch (Exception e) {
                    Log.warn("An exception occurred while dispatching a 'unsubscribedToPresence' event!", e);
                }
            }
        }
    }
}

        if (listener == null) {
            throw new NullPointerException();
        }
        listeners.add(listener);
    
<no_super_class>