projects
/
sonitus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Initialize start time with a value that will always be different.
[sonitus.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sonitus
/
data
/
filter
/
TimeCounterFilter.java
diff --git
a/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java
b/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java
index
1864b1c
..
6f31830
100644
(file)
--- a/
src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java
+++ b/
src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java
@@
-19,12
+19,11
@@
package net.pterodactylus.sonitus.data.filter;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
import net.pterodactylus.sonitus.data.Filter;
import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Filter;
import net.pterodactylus.sonitus.data.Metadata;
-import com.google.common.eventbus.EventBus;
-
/**
* {@link Filter} implementation that uses the number of bytes that have been
* {@link #process(byte[]) processed} together with the {@link Metadata} to
/**
* {@link Filter} implementation that uses the number of bytes that have been
* {@link #process(byte[]) processed} together with the {@link Metadata} to
@@
-37,35
+36,37
@@
public class TimeCounterFilter extends DummyFilter {
/** The byte counter. */
private final AtomicLong counter = new AtomicLong();
/** The byte counter. */
private final AtomicLong counter = new AtomicLong();
+ /** The parent’s metdata. */
+ private final AtomicReference<Metadata> parentMetadata = new AtomicReference<Metadata>();
+
/** Whether to reset the counter on a metadata update. */
private final boolean resetOnMetadataUpdate;
/** Whether to reset the counter on a metadata update. */
private final boolean resetOnMetadataUpdate;
+ /** The last displayed timestamp. */
+ private final AtomicLong lastTimestamp = new AtomicLong(-1);
+
/**
* Creates a new time counter filter that automatically resets the counter when
* the metadata is {@link #metadataUpdated(Metadata) updated}.
*
/**
* Creates a new time counter filter that automatically resets the counter when
* the metadata is {@link #metadataUpdated(Metadata) updated}.
*
- * @param eventBus
- * The event bus
* @param name
* The name of the filter
*/
* @param name
* The name of the filter
*/
- public TimeCounterFilter(
EventBus eventBus,
String name) {
- this(
eventBus,
name, true);
+ public TimeCounterFilter(String name) {
+ this(name, true);
}
/**
* Creates a new time counter filter.
*
}
/**
* Creates a new time counter filter.
*
- * @param eventBus
- * The event bus
* @param name
* The name of the filter
* @param resetOnMetadataUpdate
* {@code true} if the counter should automatically be reset if the metadata
* is updated, {@code false} otherwise
*/
* @param name
* The name of the filter
* @param resetOnMetadataUpdate
* {@code true} if the counter should automatically be reset if the metadata
* is updated, {@code false} otherwise
*/
- public TimeCounterFilter(
EventBus eventBus,
String name, boolean resetOnMetadataUpdate) {
- super(
eventBus,
name);
+ public TimeCounterFilter(String name, boolean resetOnMetadataUpdate) {
+ super(name);
this.resetOnMetadataUpdate = resetOnMetadataUpdate;
}
this.resetOnMetadataUpdate = resetOnMetadataUpdate;
}
@@
-100,6
+101,7
@@
public class TimeCounterFilter extends DummyFilter {
@Override
public void metadataUpdated(Metadata metadata) {
super.metadataUpdated(metadata);
@Override
public void metadataUpdated(Metadata metadata) {
super.metadataUpdated(metadata);
+ parentMetadata.set(metadata);
if (resetOnMetadataUpdate) {
reset();
}
if (resetOnMetadataUpdate) {
reset();
}
@@
-109,6
+111,10
@@
public class TimeCounterFilter extends DummyFilter {
public void process(byte[] buffer) throws IOException {
super.process(buffer);
counter.getAndAdd(buffer.length);
public void process(byte[] buffer) throws IOException {
super.process(buffer);
counter.getAndAdd(buffer.length);
+ long timestamp = getMillis() / 1000;
+ if (lastTimestamp.get() != timestamp) {
+ super.metadataUpdated(parentMetadata.get().title(String.format("%s (%02d:%02d)", parentMetadata.get().title(), timestamp / 60, timestamp % 60)));
+ }
}
}
}
}