Add humanReadableValue() in InfoHash

This commit is contained in:
anthonyraymond 2018-01-08 00:17:23 +01:00
parent 49482e5f33
commit 123c758b78
6 changed files with 28 additions and 24 deletions

View file

@ -98,7 +98,7 @@ public class BandwidthDispatcher implements BandwidthDispatcherFacade, Runnable
public void updateTorrentPeers(final InfoHash infoHash, final int seeders, final int leechers) {
if (logger.isDebugEnabled()) {
logger.debug("Updating Peers stats for {}", infoHash.value());
logger.debug("Updating Peers stats for {}", infoHash.humanReadableValue());
}
this.lock.writeLock().lock();
try {
@ -111,7 +111,7 @@ public class BandwidthDispatcher implements BandwidthDispatcherFacade, Runnable
public void registerTorrent(final InfoHash infoHash) {
if (logger.isDebugEnabled()) {
logger.debug("{} has been added to bandwidth dispatcher.", infoHash.value());
logger.debug("{} has been added to bandwidth dispatcher.", infoHash.humanReadableValue());
}
this.lock.writeLock().lock();
try {
@ -124,7 +124,7 @@ public class BandwidthDispatcher implements BandwidthDispatcherFacade, Runnable
public void unregisterTorrent(final InfoHash infoHash) {
if (logger.isDebugEnabled()) {
logger.debug("{} has been removed from bandwidth dispatcher.", infoHash.value());
logger.debug("{} has been removed from bandwidth dispatcher.", infoHash.humanReadableValue());
}
this.lock.writeLock().lock();
try {

View file

@ -9,6 +9,10 @@ public class InfoHash {
this.infoHash = new String(bytes, MockedTorrent.BYTE_ENCODING);
}
public String humanReadableValue() {
return infoHash.replaceAll("\\p{C}", "");
}
public String value() {
return infoHash;
}

View file

@ -27,7 +27,7 @@ public class Announcer {
public SuccessAnnounceResponse announce(final RequestEvent event) throws AnnounceException, TooMuchAnnouncesFailedInARawException {
if (logger.isDebugEnabled()) {
logger.debug("Attempt to announce {} for {}", event.getEventName(), this.torrent.getTorrentInfoHash().value());
logger.debug("Attempt to announce {} for {}", event.getEventName(), this.torrent.getTorrentInfoHash().humanReadableValue());
}
try {
@ -36,7 +36,7 @@ public class Announcer {
this.announceDataAccessor.getHttpHeadersForTorrent()
);
if (logger.isInfoEnabled()) {
logger.info("{} has announced successfully. Response: {} seeders, {} leechers, {}s interval", this.torrent.getTorrentInfoHash().value(), responseMessage.getSeeders(), responseMessage.getLeechers(), responseMessage.getInterval());
logger.info("{} has announced successfully. Response: {} seeders, {} leechers, {}s interval", this.torrent.getTorrentInfoHash().humanReadableValue(), responseMessage.getSeeders(), responseMessage.getLeechers(), responseMessage.getInterval());
}
this.consecutiveFails = 0;
@ -45,13 +45,13 @@ public class Announcer {
return responseMessage;
} catch (final AnnounceException e) {
if (logger.isWarnEnabled()) {
logger.warn("{} has failed to announce", this.torrent.getTorrentInfoHash().value(), e);
logger.warn("{} has failed to announce", this.torrent.getTorrentInfoHash().humanReadableValue(), e);
}
++this.consecutiveFails;
if (this.consecutiveFails == 5) {
if (logger.isInfoEnabled()) {
logger.info("{} has failed to announce 5 times in a raw", this.torrent.getTorrentInfoHash().value());
logger.info("{} has failed to announce 5 times in a raw", this.torrent.getTorrentInfoHash().humanReadableValue());
}
throw new TooMuchAnnouncesFailedInARawException(torrent);
}

View file

@ -24,7 +24,7 @@ public class AnnounceEventPublisher implements AnnounceResponseHandlerChainEleme
@Override
public void onAnnouncerWillAnnounce(final Announcer announcer) {
if(logger.isDebugEnabled()) {
logger.debug("Publish WillAnnounceEvent event for {}.", announcer.getTorrentInfoHash().value());
logger.debug("Publish WillAnnounceEvent event for {}.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
this.eventPublisher.publishEvent(new WillAnnounceEvent(infoHash));
@ -33,7 +33,7 @@ public class AnnounceEventPublisher implements AnnounceResponseHandlerChainEleme
@Override
public void onAnnounceStartSuccess(final Announcer announcer, final SuccessAnnounceResponse result) {
if(logger.isDebugEnabled()) {
logger.debug("Publish SuccessfullyAnnounceEvent event for {}.", announcer.getTorrentInfoHash().value());
logger.debug("Publish SuccessfullyAnnounceEvent event for {}.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
final int interval = result.getInterval();
@ -43,7 +43,7 @@ public class AnnounceEventPublisher implements AnnounceResponseHandlerChainEleme
@Override
public void onAnnounceStartFails(final Announcer announcer, final Throwable throwable) {
if(logger.isDebugEnabled()) {
logger.debug("Publish FailedToAnnounceEvent event for {}.", announcer.getTorrentInfoHash().value());
logger.debug("Publish FailedToAnnounceEvent event for {}.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
final int interval = announcer.getLastKnownInterval();
@ -53,7 +53,7 @@ public class AnnounceEventPublisher implements AnnounceResponseHandlerChainEleme
@Override
public void onAnnounceRegularSuccess(final Announcer announcer, final SuccessAnnounceResponse result) {
if(logger.isDebugEnabled()) {
logger.debug("Publish SuccessfullyAnnounceEvent event for {}.", announcer.getTorrentInfoHash().value());
logger.debug("Publish SuccessfullyAnnounceEvent event for {}.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
final int interval = result.getInterval();
@ -63,7 +63,7 @@ public class AnnounceEventPublisher implements AnnounceResponseHandlerChainEleme
@Override
public void onAnnounceRegularFails(final Announcer announcer, final Throwable throwable) {
if(logger.isDebugEnabled()) {
logger.debug("Publish FailedToAnnounceEvent event for {}.", announcer.getTorrentInfoHash().value());
logger.debug("Publish FailedToAnnounceEvent event for {}.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
final int interval = announcer.getLastKnownInterval();
@ -73,7 +73,7 @@ public class AnnounceEventPublisher implements AnnounceResponseHandlerChainEleme
@Override
public void onAnnounceStopSuccess(final Announcer announcer, final SuccessAnnounceResponse result) {
if(logger.isDebugEnabled()) {
logger.debug("Publish SuccessfullyAnnounceEvent event for {}.", announcer.getTorrentInfoHash().value());
logger.debug("Publish SuccessfullyAnnounceEvent event for {}.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
this.eventPublisher.publishEvent(new SuccessfullyAnnounceEvent(infoHash, 0));
@ -82,7 +82,7 @@ public class AnnounceEventPublisher implements AnnounceResponseHandlerChainEleme
@Override
public void onAnnounceStopFails(final Announcer announcer, final Throwable throwable) {
if(logger.isDebugEnabled()) {
logger.debug("Publish FailedToAnnounceEvent event for {}.", announcer.getTorrentInfoHash().value());
logger.debug("Publish FailedToAnnounceEvent event for {}.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
this.eventPublisher.publishEvent(new FailedToAnnounceEvent(infoHash, 0));
@ -91,7 +91,7 @@ public class AnnounceEventPublisher implements AnnounceResponseHandlerChainEleme
@Override
public void onTooManyAnnounceFailedInARaw(final Announcer announcer, final TooMuchAnnouncesFailedInARawException e) {
if(logger.isDebugEnabled()) {
logger.debug("Publish TooManyAnnouncesFailedEvent event for {}.", announcer.getTorrentInfoHash().value());
logger.debug("Publish TooManyAnnouncesFailedEvent event for {}.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
this.eventPublisher.publishEvent(new TooManyAnnouncesFailedEvent(infoHash));

View file

@ -27,7 +27,7 @@ public class AnnounceReEnqueuer implements AnnounceResponseHandlerChainElement {
@Override
public void onAnnounceStartSuccess(final Announcer announcer, final SuccessAnnounceResponse result) {
if (logger.isDebugEnabled()) {
logger.debug("Enqueue torrent {} in regular queue.", announcer.getTorrentInfoHash().value());
logger.debug("Enqueue torrent {} in regular queue.", announcer.getTorrentInfoHash().humanReadableValue());
}
this.delayQueue.addOrReplace(AnnounceRequest.createRegular(announcer), result.getInterval(), ChronoUnit.SECONDS);
}
@ -35,7 +35,7 @@ public class AnnounceReEnqueuer implements AnnounceResponseHandlerChainElement {
@Override
public void onAnnounceStartFails(final Announcer announcer, final Throwable throwable) {
if (logger.isDebugEnabled()) {
logger.debug("Enqueue torrent {} in start queue once again (because it failed).", announcer.getTorrentInfoHash().value());
logger.debug("Enqueue torrent {} in start queue once again (because it failed).", announcer.getTorrentInfoHash().humanReadableValue());
}
this.delayQueue.addOrReplace(AnnounceRequest.createStart(announcer), 5, ChronoUnit.SECONDS);
}
@ -43,7 +43,7 @@ public class AnnounceReEnqueuer implements AnnounceResponseHandlerChainElement {
@Override
public void onAnnounceRegularSuccess(final Announcer announcer, final SuccessAnnounceResponse result) {
if (logger.isDebugEnabled()) {
logger.debug("Enqueue torrent {} in regular queue.", announcer.getTorrentInfoHash().value());
logger.debug("Enqueue torrent {} in regular queue.", announcer.getTorrentInfoHash().humanReadableValue());
}
this.delayQueue.addOrReplace(AnnounceRequest.createRegular(announcer), result.getInterval(), ChronoUnit.SECONDS);
}
@ -51,7 +51,7 @@ public class AnnounceReEnqueuer implements AnnounceResponseHandlerChainElement {
@Override
public void onAnnounceRegularFails(final Announcer announcer, final Throwable throwable) {
if (logger.isDebugEnabled()) {
logger.debug("Enqueue torrent {} in regular queue once again (because it failed).", announcer.getTorrentInfoHash().value());
logger.debug("Enqueue torrent {} in regular queue once again (because it failed).", announcer.getTorrentInfoHash().humanReadableValue());
}
this.delayQueue.addOrReplace(AnnounceRequest.createRegular(announcer), announcer.getLastKnownInterval(), ChronoUnit.SECONDS);
}
@ -63,7 +63,7 @@ public class AnnounceReEnqueuer implements AnnounceResponseHandlerChainElement {
@Override
public void onAnnounceStopFails(final Announcer announcer, final Throwable throwable) {
if (logger.isDebugEnabled()) {
logger.debug("Enqueue torrent {} in stop queue once again (because it failed).", announcer.getTorrentInfoHash().value());
logger.debug("Enqueue torrent {} in stop queue once again (because it failed).", announcer.getTorrentInfoHash().humanReadableValue());
}
this.delayQueue.addOrReplace(AnnounceRequest.createStop(announcer), 0, ChronoUnit.SECONDS);
}

View file

@ -24,7 +24,7 @@ public class BandwidthDispatcherNotifier implements AnnounceResponseHandlerChain
@Override
public void onAnnounceStartSuccess(final Announcer announcer, final SuccessAnnounceResponse result) {
if(logger.isDebugEnabled()) {
logger.debug("Register {} in bandwidth dispatcher and update stats.", announcer.getTorrentInfoHash().value());
logger.debug("Register {} in bandwidth dispatcher and update stats.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
this.bandwidthDispatcher.registerTorrent(infoHash);
@ -38,7 +38,7 @@ public class BandwidthDispatcherNotifier implements AnnounceResponseHandlerChain
@Override
public void onAnnounceRegularSuccess(final Announcer announcer, final SuccessAnnounceResponse result) {
if(logger.isDebugEnabled()) {
logger.debug("Update {} stats in bandwidth dispatcher.", announcer.getTorrentInfoHash().value());
logger.debug("Update {} stats in bandwidth dispatcher.", announcer.getTorrentInfoHash().humanReadableValue());
}
final InfoHash infoHash = announcer.getTorrentInfoHash();
this.bandwidthDispatcher.updateTorrentPeers(infoHash, result.getSeeders(), result.getLeechers());
@ -51,7 +51,7 @@ public class BandwidthDispatcherNotifier implements AnnounceResponseHandlerChain
@Override
public void onAnnounceStopSuccess(final Announcer announcer, final SuccessAnnounceResponse result) {
if(logger.isDebugEnabled()) {
logger.debug("Unregister {} from bandwidth dispatcher.", announcer.getTorrentInfoHash().value());
logger.debug("Unregister {} from bandwidth dispatcher.", announcer.getTorrentInfoHash().humanReadableValue());
}
this.bandwidthDispatcher.unregisterTorrent(announcer.getTorrentInfoHash());
}
@ -63,7 +63,7 @@ public class BandwidthDispatcherNotifier implements AnnounceResponseHandlerChain
@Override
public void onTooManyAnnounceFailedInARaw(final Announcer announcer, final TooMuchAnnouncesFailedInARawException e) {
if(logger.isDebugEnabled()) {
logger.debug("Unregister {} from bandwidth dispatcher.", announcer.getTorrentInfoHash().value());
logger.debug("Unregister {} from bandwidth dispatcher.", announcer.getTorrentInfoHash().humanReadableValue());
}
this.bandwidthDispatcher.unregisterTorrent(announcer.getTorrentInfoHash());
}