Remove dependency on utils package.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 6 Apr 2014 20:03:03 +0000 (22:03 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 6 Apr 2014 20:03:03 +0000 (22:03 +0200)
pom.xml
src/main/java/net/pterodactylus/fcp/FcpConnection.java
src/main/java/net/pterodactylus/fcp/FcpConnectionHandler.java
src/main/java/net/pterodactylus/fcp/FcpListenerManager.java
src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java
src/main/java/net/pterodactylus/fcp/highlevel/FcpClientListenerManager.java

diff --git a/pom.xml b/pom.xml
index c2a5995..4721108 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -20,9 +20,9 @@
                        <scope>test</scope>
                </dependency>
                <dependency>
-                       <groupId>net.pterodactylus</groupId>
-                       <artifactId>utils</artifactId>
-                       <version>0.6.1</version>
+                       <groupId>com.google.guava</groupId>
+                       <artifactId>guava</artifactId>
+                       <version>16.0.1</version>
                </dependency>
        </dependencies>
        <repositories>
index 858b783..66377a2 100644 (file)
@@ -31,8 +31,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Logger;
 
-import net.pterodactylus.util.logging.Logging;
-
 /**
  * An FCP connection to a Freenet node.
  *
@@ -41,7 +39,7 @@ import net.pterodactylus.util.logging.Logging;
 public class FcpConnection implements Closeable {
 
        /** Logger. */
-       private static final Logger logger = Logging.getLogger(FcpConnection.class.getName());
+       private static final Logger logger = Logger.getLogger(FcpConnection.class.getName());
 
        /** The default port for FCP v2. */
        public static final int DEFAULT_PORT = 9481;
index e46966a..36be123 100644 (file)
@@ -25,8 +25,6 @@ import java.nio.charset.Charset;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import net.pterodactylus.util.logging.Logging;
-
 /**
  * Handles an FCP connection to a node.
  *
@@ -35,7 +33,7 @@ import net.pterodactylus.util.logging.Logging;
 class FcpConnectionHandler implements Runnable {
 
        /** The logger. */
-       private static final Logger logger = Logging.getLogger(FcpConnectionHandler.class.getName());
+       private static final Logger logger = Logger.getLogger(FcpConnectionHandler.class.getName());
 
        /** The underlying connection. */
        private final FcpConnection fcpConnection;
index 4f3b9dd..7969da1 100644 (file)
 
 package net.pterodactylus.fcp;
 
-import net.pterodactylus.util.event.AbstractListenerManager;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * Manages FCP listeners and event firing.
  *
  * @author David ‘Bombe’ Roden &lt;bombe@pterodactylus.net&gt;
  */
-public class FcpListenerManager extends AbstractListenerManager<FcpConnection, FcpListener> {
+public class FcpListenerManager {
+
+       private final FcpConnection source;
+       private final List<FcpListener> listeners = new CopyOnWriteArrayList<FcpListener>();
 
        /**
         * Creates a new listener manager.
@@ -34,7 +38,23 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
         *            The source FCP connection
         */
        public FcpListenerManager(FcpConnection fcpConnection) {
-               super(fcpConnection);
+               this.source = fcpConnection;
+       }
+
+       public void addListener(FcpListener fcpListener) {
+               listeners.add(fcpListener);
+       }
+
+       public void removeListener(FcpListener fcpListener) {
+               listeners.remove(fcpListener);
+       }
+
+       private FcpConnection getSource() {
+               return source;
+       }
+
+       private List<FcpListener> getListeners() {
+               return listeners;
        }
 
        /**
index 56fb90d..bc1092e 100644 (file)
@@ -18,6 +18,8 @@
 
 package net.pterodactylus.fcp.highlevel;
 
+import static com.google.common.collect.FluentIterable.from;
+
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
@@ -32,6 +34,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
 
 import net.pterodactylus.fcp.AddPeer;
 import net.pterodactylus.fcp.AllData;
@@ -68,10 +71,8 @@ import net.pterodactylus.fcp.RemovePeer;
 import net.pterodactylus.fcp.SSKKeypair;
 import net.pterodactylus.fcp.SimpleProgress;
 import net.pterodactylus.fcp.WatchGlobal;
-import net.pterodactylus.util.filter.Filter;
-import net.pterodactylus.util.filter.Filters;
-import net.pterodactylus.util.io.TemporaryInputStream;
-import net.pterodactylus.util.thread.ObjectWrapper;
+
+import com.google.common.base.Predicate;
 
 /**
  * High-level FCP client that hides the details of the underlying FCP
@@ -380,13 +381,7 @@ public class FcpClient implements Closeable {
                                if (!allData.getIdentifier().equals(identifier)) {
                                        return;
                                }
-                               InputStream temporaryInputStream;
-                               try {
-                                       temporaryInputStream = new TemporaryInputStream(allData.getPayloadInputStream());
-                                       getResult.success(true).contentType(allData.getContentType()).contentLength(allData.getDataLength()).inputStream(temporaryInputStream);
-                               } catch (IOException ioe1) {
-                                       getResult.success(false).exception(ioe1);
-                               }
+                               getResult.success(true).contentType(allData.getContentType()).contentLength(allData.getDataLength()).inputStream(allData.getPayloadInputStream());
                                completionLatch.countDown();
                        }
 
@@ -742,7 +737,7 @@ public class FcpClient implements Closeable {
         *             if an FCP error occurs
         */
        public PeerNote getPeerNote(final Peer peer) throws IOException, FcpException {
-               final ObjectWrapper<PeerNote> objectWrapper = new ObjectWrapper<PeerNote>();
+               final AtomicReference<PeerNote> objectWrapper = new AtomicReference<PeerNote>();
                new ExtendedFcpAdapter() {
 
                        /**
@@ -828,7 +823,7 @@ public class FcpClient implements Closeable {
         *             if an FCP error occurs
         */
        public SSKKeypair generateKeyPair() throws IOException, FcpException {
-               final ObjectWrapper<SSKKeypair> sskKeypairWrapper = new ObjectWrapper<SSKKeypair>();
+               final AtomicReference<SSKKeypair> sskKeypairWrapper = new AtomicReference<SSKKeypair>();
                new ExtendedFcpAdapter() {
 
                        /**
@@ -870,16 +865,12 @@ public class FcpClient implements Closeable {
         *             if an FCP error occurs
         */
        public Collection<Request> getGetRequests(final boolean global) throws IOException, FcpException {
-               return Filters.filteredCollection(getRequests(global), new Filter<Request>() {
-
-                       /**
-                        * {@inheritDoc}
-                        */
+               return from(getRequests(global)).filter(new Predicate<Request>() {
                        @Override
-                       public boolean filterObject(Request request) {
+                       public boolean apply(Request request) {
                                return request instanceof GetRequest;
                        }
-               });
+               }).toList();
        }
 
        /**
@@ -896,16 +887,12 @@ public class FcpClient implements Closeable {
         *             if an FCP error occurs
         */
        public Collection<Request> getPutRequests(final boolean global) throws IOException, FcpException {
-               return Filters.filteredCollection(getRequests(global), new Filter<Request>() {
-
-                       /**
-                        * {@inheritDoc}
-                        */
+               return from(getRequests(global)).filter(new Predicate<Request>() {
                        @Override
-                       public boolean filterObject(Request request) {
+                       public boolean apply(Request request) {
                                return request instanceof PutRequest;
                        }
-               });
+               }).toList();
        }
 
        /**
@@ -1119,7 +1106,7 @@ public class FcpClient implements Closeable {
         *             if an I/O error occurs
         */
        public NodeData getNodeInformation(final Boolean giveOpennetRef, final Boolean withPrivate, final Boolean withVolatile) throws IOException, FcpException {
-               final ObjectWrapper<NodeData> nodeDataWrapper = new ObjectWrapper<NodeData>();
+               final AtomicReference<NodeData> nodeDataWrapper = new AtomicReference<NodeData>();
                new ExtendedFcpAdapter() {
 
                        @Override
index aa797e4..eb9ef2f 100644 (file)
 
 package net.pterodactylus.fcp.highlevel;
 
-import net.pterodactylus.util.event.AbstractListenerManager;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * Manages {@link FcpClientListener}s and fires events.
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class FcpClientListenerManager extends AbstractListenerManager<FcpClient, FcpClientListener> {
+public class FcpClientListenerManager {
+
+       private final FcpClient source;
+       private final List<FcpClientListener> listeners = new CopyOnWriteArrayList<FcpClientListener>();
 
        /**
         * Creates a new FCP client listener manager.
@@ -34,7 +38,15 @@ public class FcpClientListenerManager extends AbstractListenerManager<FcpClient,
         *            The source FCP client
         */
        public FcpClientListenerManager(FcpClient fcpClient) {
-               super(fcpClient);
+               this.source = fcpClient;
+       }
+
+       private FcpClient getSource() {
+               return source;
+       }
+
+       public List<FcpClientListener> getListeners() {
+               return listeners;
        }
 
        /**
@@ -48,4 +60,12 @@ public class FcpClientListenerManager extends AbstractListenerManager<FcpClient,
                }
        }
 
+       public void addListener(FcpClientListener fcpClientListener) {
+               listeners.add(fcpClientListener);
+       }
+
+       public void removeListener(FcpClientListener fcpClientListener) {
+               listeners.remove(fcpClientListener);
+       }
+
 }