-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #665 No functional changes.
- Loading branch information
Showing
3 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/ru/mystamps/web/service/TimedDownloaderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2009-2018 Slava Semushin <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package ru.mystamps.web.service; | ||
|
||
import org.apache.commons.lang3.time.StopWatch; | ||
|
||
import org.slf4j.Logger; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import ru.mystamps.web.service.dto.DownloadResult; | ||
|
||
@RequiredArgsConstructor | ||
public class TimedDownloaderService implements DownloaderService { | ||
|
||
private final Logger log; | ||
private final DownloaderService service; | ||
|
||
// @todo #665 TimedDownloaderService: add unit tests | ||
@Override | ||
public DownloadResult download(String url) { | ||
// Why we don't use Spring's StopWatch? | ||
// 1) because its javadoc says that it's not intended for production | ||
// 2) because we don't want to have strong dependencies on the Spring Framework | ||
StopWatch timer = new StopWatch(); | ||
|
||
// start() and stop() may throw IllegalStateException and in this case it's possible | ||
// that we won't generate anything or lose already generated result. I don't want to | ||
// make method body too complicated by adding many try/catches and I believe that such | ||
// exception will never happen because it would mean that we're using API in a wrong way. | ||
timer.start(); | ||
DownloadResult result = service.download(url); | ||
timer.stop(); | ||
|
||
if (result.hasSucceeded()) { | ||
log.debug( | ||
"{} bytes have been downloaded in {} msecs", | ||
result.getData().length, | ||
timer.getTime() | ||
); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
829173f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
665-32370c4c
discovered insrc/main/java/ru/mystamps/web/service/TimedDownloaderService.java
and submitted as #800. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, butwe discovered it only now.