/*
 * * Copyright (C) 2013-2015 Matt Baxter http://kitteh.org
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.kitteh.irc.client.library;

import net.engio.mbassy.bus.SyncMessageBus;
import net.engio.mbassy.bus.common.Properties;
import net.engio.mbassy.bus.config.BusConfiguration;
import net.engio.mbassy.bus.config.Feature;
import net.engio.mbassy.bus.error.IPublicationErrorHandler;
import net.engio.mbassy.bus.error.PublicationError;
import net.engio.mbassy.listener.Handler;
import org.kitteh.irc.client.library.exception.KittehEventException;

import java.util.HashSet;
import java.util.Set;

/**
 * Processes and registers events for a single {@link Client} instance. This
 * event manager utilizes MBassador, a lightweight event bus.
 */
public final class EventManager {
    private class Exceptional implements IPublicationErrorHandler {
        @Override
        public void handleError(PublicationError publicationError) {
            EventManager.this.client.getExceptionListener().queue(new KittehEventException(publicationError.getCause()));
        }
    }

    private final SyncMessageBus<Object> bus = new SyncMessageBus<>(new BusConfiguration().addFeature(Feature.SyncPubSub.Default()).setProperty(Properties.Handler.PublicationError, new Exceptional()));
    private final IRCClient client;
    private final Set<Object> listeners = new HashSet<>();

    EventManager(IRCClient client) {
        this.client = client;
    }

    /**
     * Registers annotated with {@link Handler} with sync invocation,
     * provided they have a single parameter. This parameter is the event.
     *
     * @param listener listener in which to register events
     */
    public void registerEventListener(Object listener) {
        this.listeners.add(listener);
        this.bus.subscribe(listener);
    }

    /**
     * Calls an event, triggering any registered methods for the event class.
     *
     * @param event event to call
     */
    public void callEvent(Object event) {
        this.bus.publish(event);
    }
}
@@ -2480,32 +2480,470 @@
  client;%0A    %7D%0A%0A
+    /**%0A     * Calls an event, triggering any registered methods for the event class.%0A     *%0A     * @param event event to call%0A     */%0A    public void callEvent(Object event) %7B%0A        this.bus.publish(event);%0A    %7D%0A%0A    /**%0A     * Gets all registered listener objects.%0A     *%0A     * @return a set of objects%0A     */%0A    public synchronized Set%3CObject%3E getRegisteredEventListeners() %7B%0A        return new HashSet%3C%3E(this.listeners);%0A    %7D%0A%0A
     /**%0A     * R
@@ -3161,24 +3161,37 @@
 %0A    public 
+synchronized 
 void registe
@@ -3326,200 +3326,243 @@
   * 
-Calls an event, triggering any registered methods for the event class.%0A     *%0A     * @param event event to call%0A     */%0A    public void callEvent(Object event) %7B%0A        this.bus.publish(event
+Unregisters a listener.%0A     *%0A     * @param listener listener to unregister%0A     */%0A    public synchronized void unregisterEventListener(Object listener) %7B%0A        this.listeners.remove(listener);%0A        this.bus.unsubscribe(listener
 );%0A 

Add more functionality to EventManager