Count and expose the number of bytes that have been read from the connection’s source.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 May 2013 20:15:55 +0000 (22:15 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 May 2013 20:56:28 +0000 (22:56 +0200)
src/main/java/net/pterodactylus/sonitus/data/Pipeline.java

index a38d6fe..4409151 100644 (file)
@@ -260,6 +260,9 @@ public class Pipeline implements Iterable<Controlled> {
                /** The executor service. */
                private final ExecutorService executorService;
 
+               /** The number of copied bytes. */
+               private long counter;
+
                /**
                 * Creates a new connection.
                 *
@@ -279,6 +282,20 @@ public class Pipeline implements Iterable<Controlled> {
                }
 
                //
+               // ACCESSORS
+               //
+
+               /**
+                * Returns the number of bytes that this connection has received from its
+                * source during its lifetime.
+                *
+                * @return The number of processed input bytes
+                */
+               public long counter() {
+                       return counter;
+               }
+
+               //
                // ACTIONS
                //
 
@@ -333,6 +350,7 @@ public class Pipeline implements Iterable<Controlled> {
                                        for (Future<Void> future : futures) {
                                                future.get();
                                        }
+                                       counter += buffer.length;
                                } catch (IOException e) {
                                        /* TODO */
                                        e.printStackTrace();