Skip to content

Commit

Permalink
#22 log usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Nov 20, 2016
1 parent 30437fd commit 527f8e7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/io/jare/Logs.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.jcabi.aspects.ScheduleWithFixedDelay;
import com.jcabi.aspects.Tv;
import com.jcabi.log.Logger;
import com.jcabi.s3.Bucket;
import com.jcabi.s3.Ocket;
import io.jare.model.Base;
Expand Down Expand Up @@ -105,8 +106,9 @@ public void run() {
final Iterator<String> ockets = this.bucket.list("").iterator();
if (ockets.hasNext()) {
final String name = ockets.next();
this.process(name);
final long bytes = this.process(name);
this.bucket.remove(name);
Logger.info(this, "ocket %s processed, %d bytes", name, bytes);
}
} catch (final IOException ex) {
throw new IllegalStateException(ex);
Expand All @@ -116,9 +118,10 @@ public void run() {
/**
* Process one ocket.
* @param name The name of the ocket
* @return Bytes in total
* @throws IOException If fails
*/
private void process(final String name) throws IOException {
private long process(final String name) throws IOException {
final Ocket ocket = this.bucket.ocket(name);
final Path path = Files.createTempFile("jare", ".gz");
ocket.read(new FileOutputStream(path.toFile()));
Expand All @@ -141,6 +144,7 @@ private void process(final String name) throws IOException {
} finally {
input.close();
}
long total = 0L;
for (final Map.Entry<String, Map<Date, Long>> entry : map.entrySet()) {
for (final Map.Entry<Date, Long> usg
: entry.getValue().entrySet()) {
Expand All @@ -152,8 +156,10 @@ private void process(final String name) throws IOException {
usg.getValue()
);
}
total += usg.getValue();
}
}
return total;
}

/**
Expand Down

0 comments on commit 527f8e7

Please sign in to comment.