X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fplugin%2FPluginConnector.java;h=0090aa85a208e84b167dd0e2466a14b2f2956043;hb=11b5cd71eb4ce8a88b96b3c18b1cb038215a7710;hp=e7bf82820cf4a7e8389f166b9f4b8840c6ce6ede;hpb=4a2fdf3b0b3dfcfc761c83797018237ec4c82a4b;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java b/src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java
index e7bf828..0090aa8 100644
--- a/src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java
+++ b/src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java
@@ -1,5 +1,5 @@
/*
- * Sone - PluginConnector.java - Copyright © 2010 David Roden
+ * Sone - PluginConnector.java - Copyright © 2010â2016 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,11 +17,12 @@
package net.pterodactylus.sone.freenet.plugin;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import net.pterodactylus.sone.freenet.plugin.event.ReceivedReplyEvent;
+
+import com.google.common.eventbus.EventBus;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
-import net.pterodactylus.util.collection.Pair;
import freenet.pluginmanager.FredPluginTalker;
import freenet.pluginmanager.PluginNotFoundException;
import freenet.pluginmanager.PluginRespirator;
@@ -35,57 +36,30 @@ import freenet.support.api.Bucket;
*
* @author David âBombeâ Roden
*/
+@Singleton
public class PluginConnector implements FredPluginTalker {
+ /** The event bus. */
+ private final EventBus eventBus;
+
/** The plugin respirator. */
private final PluginRespirator pluginRespirator;
- /** Connector listener managers for all plugin connections. */
- private final Map, ConnectorListenerManager> connectorListenerManagers = Collections.synchronizedMap(new HashMap, ConnectorListenerManager>());
-
/**
* Creates a new plugin connector.
*
+ * @param eventBus
+ * The event bus
* @param pluginRespirator
* The plugin respirator
*/
- public PluginConnector(PluginRespirator pluginRespirator) {
+ @Inject
+ public PluginConnector(EventBus eventBus, PluginRespirator pluginRespirator) {
+ this.eventBus = eventBus;
this.pluginRespirator = pluginRespirator;
}
//
- // LISTENER MANAGEMENT
- //
-
- /**
- * Adds a connection listener for the given plugin connection.
- *
- * @param pluginName
- * The name of the plugin
- * @param identifier
- * The identifier of the connection
- * @param connectorListener
- * The listener to add
- */
- public void addConnectorListener(String pluginName, String identifier, ConnectorListener connectorListener) {
- getConnectorListenerManager(pluginName, identifier).addListener(connectorListener);
- }
-
- /**
- * Removes a connection listener for the given plugin connection.
- *
- * @param pluginName
- * The name of the plugin
- * @param identifier
- * The identifier of the connection
- * @param connectorListener
- * The listener to remove
- */
- public void removeConnectorListener(String pluginName, String identifier, ConnectorListener connectorListener) {
- getConnectorListenerManager(pluginName, identifier).removeListener(connectorListener);
- }
-
- //
// ACTIONS
//
@@ -128,43 +102,6 @@ public class PluginConnector implements FredPluginTalker {
//
/**
- * Returns the connection listener manager for the given plugin connection,
- * creating a new one if none does exist yet.
- *
- * @param pluginName
- * The name of the plugin
- * @param identifier
- * The identifier of the connection
- * @return The connection listener manager
- */
- private ConnectorListenerManager getConnectorListenerManager(String pluginName, String identifier) {
- return getConnectorListenerManager(pluginName, identifier, true);
- }
-
- /**
- * Returns the connection listener manager for the given plugin connection,
- * optionally creating a new one if none does exist yet.
- *
- * @param pluginName
- * The name of the plugin
- * @param identifier
- * The identifier of the connection
- * @param create
- * {@code true} to create a new manager if there is none,
- * {@code false} to return {@code null} in that case
- * @return The connection listener manager, or {@code null} if none existed
- * and {@code create} is {@code false}
- */
- private ConnectorListenerManager getConnectorListenerManager(String pluginName, String identifier, boolean create) {
- ConnectorListenerManager connectorListenerManager = connectorListenerManagers.get(new Pair(pluginName, identifier));
- if (create && (connectorListenerManager == null)) {
- connectorListenerManager = new ConnectorListenerManager(this);
- connectorListenerManagers.put(new Pair(pluginName, identifier), connectorListenerManager);
- }
- return connectorListenerManager;
- }
-
- /**
* Returns the plugin talker for the given plugin connection.
*
* @param pluginName
@@ -192,12 +129,7 @@ public class PluginConnector implements FredPluginTalker {
*/
@Override
public void onReply(String pluginName, String identifier, SimpleFieldSet params, Bucket data) {
- ConnectorListenerManager connectorListenerManager = getConnectorListenerManager(pluginName, identifier, false);
- if (connectorListenerManager == null) {
- /* we donât care about events for this plugin. */
- return;
- }
- connectorListenerManager.fireReceivedReply(params, data);
+ eventBus.post(new ReceivedReplyEvent(this, pluginName, identifier, params, data));
}
}