import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.TemporaryImage;
-import net.pterodactylus.util.collection.Pair;
import net.pterodactylus.util.logging.Logging;
import com.db4o.ObjectContainer;
* The URI to fetch
* @return The result of the fetch, or {@code null} if an error occured
*/
- public Pair<FreenetURI, FetchResult> fetchUri(FreenetURI uri) {
+ public Fetched fetchUri(FreenetURI uri) {
FetchResult fetchResult = null;
FreenetURI currentUri = new FreenetURI(uri);
while (true) {
try {
fetchResult = client.fetch(currentUri);
- return new Pair<FreenetURI, FetchResult>(currentUri, fetchResult);
+ return new Fetched(currentUri, fetchResult);
} catch (FetchException fe1) {
if (fe1.getMode() == FetchException.PERMANENT_REDIRECT) {
currentUri = fe1.newURI;
}
/**
+ * Container for a fetched URI and the {@link FetchResult}.
+ *
+ * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
+ */
+ public static class Fetched {
+
+ /** The fetched URI. */
+ private final FreenetURI freenetUri;
+
+ /** The fetch result. */
+ private final FetchResult fetchResult;
+
+ /**
+ * Creates a new fetched URI.
+ *
+ * @param freenetUri
+ * The URI that was fetched
+ * @param fetchResult
+ * The fetch result
+ */
+ public Fetched(FreenetURI freenetUri, FetchResult fetchResult) {
+ this.freenetUri = freenetUri;
+ this.fetchResult = fetchResult;
+ }
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the fetched URI.
+ *
+ * @return The fetched URI
+ */
+ public FreenetURI getFreenetUri() {
+ return freenetUri;
+ }
+
+ /**
+ * Returns the fetch result.
+ *
+ * @return The fetch result
+ */
+ public FetchResult getFetchResult() {
+ return fetchResult;
+ }
+
+ }
+
+ /**
* Callback for USK watcher events.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
import java.util.logging.Level;
import java.util.logging.Logger;
+import net.pterodactylus.sone.core.FreenetInterface.Fetched;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.SoneStatus;
-import net.pterodactylus.util.collection.Pair;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.number.Numbers;
FreenetURI requestUri = soneUri.setMetaString(new String[] { "sone.xml" });
sone.setStatus(SoneStatus.downloading);
try {
- Pair<FreenetURI, FetchResult> fetchResults = freenetInterface.fetchUri(requestUri);
+ Fetched fetchResults = freenetInterface.fetchUri(requestUri);
if (fetchResults == null) {
/* TODO - mark Sone as bad. */
return null;
}
- logger.log(Level.FINEST, String.format("Got %d bytes back.", fetchResults.getRight().size()));
- Sone parsedSone = parseSone(sone, fetchResults.getRight(), fetchResults.getLeft());
+ logger.log(Level.FINEST, String.format("Got %d bytes back.", fetchResults.getFetchResult().size()));
+ Sone parsedSone = parseSone(sone, fetchResults.getFetchResult(), fetchResults.getFreenetUri());
if (parsedSone != null) {
if (!fetchOnly) {
core.updateSone(parsedSone);
import java.util.logging.Level;
import java.util.logging.Logger;
+import net.pterodactylus.sone.core.FreenetInterface.Fetched;
import net.pterodactylus.sone.main.SonePlugin;
-import net.pterodactylus.util.collection.Pair;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.version.Version;
-import freenet.client.FetchResult;
import freenet.keys.FreenetURI;
import freenet.support.api.Bucket;
public void editionFound(FreenetURI uri, long edition, boolean newKnownGood, boolean newSlot) {
logger.log(Level.FINEST, String.format("Found update for %s: %d, %s, %s", uri, edition, newKnownGood, newSlot));
if (newKnownGood || newSlot) {
- Pair<FreenetURI, FetchResult> uriResult = freenetInterface.fetchUri(uri.setMetaString(new String[] { "sone.properties" }));
+ Fetched uriResult = freenetInterface.fetchUri(uri.setMetaString(new String[] { "sone.properties" }));
if (uriResult == null) {
logger.log(Level.WARNING, String.format("Could not fetch properties of latest homepage: %s", uri));
return;
}
- Bucket resultBucket = uriResult.getRight().asBucket();
+ Bucket resultBucket = uriResult.getFetchResult().asBucket();
try {
parseProperties(resultBucket.getInputStream(), edition);
latestEdition = edition;
import java.util.HashMap;
import java.util.Map;
-import net.pterodactylus.util.collection.Pair;
-
import com.google.inject.Inject;
import freenet.pluginmanager.FredPluginTalker;
private final PluginRespirator pluginRespirator;
/** Connector listener managers for all plugin connections. */
- private final Map<Pair<String, String>, ConnectorListenerManager> connectorListenerManagers = Collections.synchronizedMap(new HashMap<Pair<String, String>, ConnectorListenerManager>());
+ private final Map<PluginIdentifier, ConnectorListenerManager> connectorListenerManagers = Collections.synchronizedMap(new HashMap<PluginIdentifier, ConnectorListenerManager>());
/**
* Creates a new plugin connector.
* and {@code create} is {@code false}
*/
private ConnectorListenerManager getConnectorListenerManager(String pluginName, String identifier, boolean create) {
- ConnectorListenerManager connectorListenerManager = connectorListenerManagers.get(new Pair<String, String>(pluginName, identifier));
+ ConnectorListenerManager connectorListenerManager = connectorListenerManagers.get(new PluginIdentifier(pluginName, identifier));
if (create && (connectorListenerManager == null)) {
connectorListenerManager = new ConnectorListenerManager(this);
- connectorListenerManagers.put(new Pair<String, String>(pluginName, identifier), connectorListenerManager);
+ connectorListenerManagers.put(new PluginIdentifier(pluginName, identifier), connectorListenerManager);
}
return connectorListenerManager;
}
connectorListenerManager.fireReceivedReply(params, data);
}
+ /**
+ * Container for identifying plugins. Plugins are identified by their plugin
+ * name and their unique identifier.
+ *
+ * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
+ */
+ private static class PluginIdentifier {
+
+ /** The plugin name. */
+ private final String pluginName;
+
+ /** The plugin identifier. */
+ private final String identifier;
+
+ /**
+ * Creates a new plugin identifier.
+ *
+ * @param pluginName
+ * The name of the plugin
+ * @param identifier
+ * The identifier of the plugin
+ */
+ public PluginIdentifier(String pluginName, String identifier) {
+ this.pluginName = pluginName;
+ this.identifier = identifier;
+ }
+
+ //
+ // OBJECT METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return pluginName.hashCode() ^ identifier.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object object) {
+ if (!(object instanceof PluginIdentifier)) {
+ return false;
+ }
+ PluginIdentifier pluginIdentifier = (PluginIdentifier) object;
+ return pluginName.equals(pluginIdentifier.pluginName) && identifier.equals(pluginIdentifier.identifier);
+ }
+
+ }
+
}