From 6737e4ddfb00215aa274f3075428da6d6c82e112 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Thu, 6 Oct 2011 09:22:56 +0100 Subject: [PATCH] Merged common methods of BatchTransportPlugin and StreamTransportPlugin into a superclass. --- .../briar/api/transport/TransportPlugin.java | 49 +++++++++++++++++++ .../transport/batch/BatchTransportPlugin.java | 43 +--------------- .../stream/StreamTransportPlugin.java | 46 ++--------------- 3 files changed, 55 insertions(+), 83 deletions(-) create mode 100644 api/net/sf/briar/api/transport/TransportPlugin.java diff --git a/api/net/sf/briar/api/transport/TransportPlugin.java b/api/net/sf/briar/api/transport/TransportPlugin.java new file mode 100644 index 0000000000..d4e8948856 --- /dev/null +++ b/api/net/sf/briar/api/transport/TransportPlugin.java @@ -0,0 +1,49 @@ +package net.sf.briar.api.transport; + +import java.io.IOException; +import java.util.Map; + +import net.sf.briar.api.ContactId; +import net.sf.briar.api.TransportId; + +public interface TransportPlugin { + + /** Returns the plugin's transport identifier. */ + TransportId getId(); + + /** + * Stops the plugin. No further connections will be passed to the callback + * after this method has returned. + */ + void stop() throws IOException; + + /** Updates the plugin's local transport properties. */ + void setLocalProperties(Map<String, String> properties) + throws InvalidPropertiesException; + + /** Updates the plugin's transport properties for the given contact. */ + void setRemoteProperties(ContactId c, Map<String, String> properties) + throws InvalidPropertiesException; + + /** Updates the plugin's configuration properties. */ + void setConfig(Map<String, String> config) throws InvalidConfigException; + + /** + * Returns true if the plugin's poll() method should be called + * periodically to attempt to establish connections. + */ + boolean shouldPoll(); + + /** + * Returns the desired interval in milliseconds between calls to the + * plugin's poll() method. + */ + long getPollingInterval(); + + /** + * Attempts to establish connections using the current transport and + * configuration properties, and passes any created connections to the + * callback. + */ + void poll(); +} diff --git a/api/net/sf/briar/api/transport/batch/BatchTransportPlugin.java b/api/net/sf/briar/api/transport/batch/BatchTransportPlugin.java index 02141015bc..b0457b30a1 100644 --- a/api/net/sf/briar/api/transport/batch/BatchTransportPlugin.java +++ b/api/net/sf/briar/api/transport/batch/BatchTransportPlugin.java @@ -4,18 +4,15 @@ import java.io.IOException; import java.util.Map; import net.sf.briar.api.ContactId; -import net.sf.briar.api.TransportId; import net.sf.briar.api.transport.InvalidConfigException; import net.sf.briar.api.transport.InvalidPropertiesException; +import net.sf.briar.api.transport.TransportPlugin; /** * An interface for transport plugins that do not support bidirectional, * reliable, ordered, timely delivery of data. */ -public interface BatchTransportPlugin { - - /** Returns the plugin's transport identifier. */ - TransportId getId(); +public interface BatchTransportPlugin extends TransportPlugin { /** * Starts the plugin. Any connections that are later initiated by contacts @@ -26,42 +23,6 @@ public interface BatchTransportPlugin { Map<String, String> config, BatchTransportCallback c) throws InvalidPropertiesException, InvalidConfigException, IOException; - /** - * Stops the plugin. No further connections will be passed to the callback - * after this method has returned. - */ - void stop() throws IOException; - - /** Updates the plugin's local transport properties. */ - void setLocalProperties(Map<String, String> properties) - throws InvalidPropertiesException; - - /** Updates the plugin's transport properties for the given contact. */ - void setRemoteProperties(ContactId c, Map<String, String> properties) - throws InvalidPropertiesException; - - /** Updates the plugin's configuration properties. */ - void setConfig(Map<String, String> config) throws InvalidConfigException; - - /** - * Returns true if the plugin's poll() method should be called - * periodically to attempt to establish connections. - */ - boolean shouldPoll(); - - /** - * Returns the desired interval in milliseconds between calls to the - * plugin's poll() method. - */ - long getPollingInterval(); - - /** - * Attempts to establish incoming and/or outgoing connections using the - * current transport and configuration properties, and passes any created - * readers and/or writers to the callback. - */ - void poll(); - /** * Attempts to create and return a BatchTransportReader for the given * contact using the current transport and configuration properties. diff --git a/api/net/sf/briar/api/transport/stream/StreamTransportPlugin.java b/api/net/sf/briar/api/transport/stream/StreamTransportPlugin.java index 1a2730ec92..001cfe8d10 100644 --- a/api/net/sf/briar/api/transport/stream/StreamTransportPlugin.java +++ b/api/net/sf/briar/api/transport/stream/StreamTransportPlugin.java @@ -1,20 +1,18 @@ package net.sf.briar.api.transport.stream; +import java.io.IOException; import java.util.Map; import net.sf.briar.api.ContactId; -import net.sf.briar.api.TransportId; import net.sf.briar.api.transport.InvalidConfigException; import net.sf.briar.api.transport.InvalidPropertiesException; +import net.sf.briar.api.transport.TransportPlugin; /** * An interface for transport plugins that support bidirectional, reliable, * ordered, timely delivery of data. */ -public interface StreamTransportPlugin { - - /** Returns the plugin's transport identifier. */ - TransportId getId(); +public interface StreamTransportPlugin extends TransportPlugin { /** * Starts the plugin. Any connections that are later initiated by contacts @@ -23,43 +21,7 @@ public interface StreamTransportPlugin { void start(Map<String, String> localProperties, Map<ContactId, Map<String, String>> remoteProperties, Map<String, String> config, StreamTransportCallback c) - throws InvalidPropertiesException, InvalidConfigException; - - /** - * Stops the plugin. No further connections will be passed to the callback - * after this method has returned. - */ - void stop(); - - /** Updates the plugin's local transport properties. */ - void setLocalProperties(Map<String, String> properties) - throws InvalidPropertiesException; - - /** Updates the plugin's transport properties for the given contact. */ - void setRemoteProperties(ContactId c, Map<String, String> properties) - throws InvalidPropertiesException; - - /** Updates the plugin's configuration properties. */ - void setConfig(Map<String, String> config) throws InvalidConfigException; - - /** - * Returns true if the plugin's poll() method should be called - * periodically to attempt to establish connections. - */ - boolean shouldPoll(); - - /** - * Returns the desired interval in milliseconds between calls to the - * plugin's poll() method. - */ - long getPollingInterval(); - - /** - * Attempts to establish connections using the current transport and - * configuration properties, and passes any created connections to the - * callback. - */ - void poll(); + throws InvalidPropertiesException, InvalidConfigException, IOException; /** * Attempts to create and return a StreamTransportConnection to the given -- GitLab