diff --git a/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java b/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java index 1f5ee3ac4..192c99482 100644 --- a/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java +++ b/ttorrent-client/src/main/java/com/turn/ttorrent/client/CommunicationManager.java @@ -270,7 +270,7 @@ public void removeTorrent(String torrentHash) { SharedTorrent torrent = torrents.first(); if (torrent != null) { torrent.setClientState(ClientState.DONE); - torrent.close(); + torrent.closeFully(); } List peers = getPeersForTorrent(torrentHash); for (SharingPeer peer : peers) { @@ -474,7 +474,7 @@ void stop(int timeout, TimeUnit timeUnit) { for (SharedTorrent torrent : this.torrentsStorage.activeTorrents()) { logger.trace("try close torrent {}", torrent); - torrent.close(); + torrent.closeFully(); if (torrent.isFinished()) { torrent.setClientState(ClientState.DONE); } else { diff --git a/ttorrent-client/src/main/java/com/turn/ttorrent/client/SharedTorrent.java b/ttorrent-client/src/main/java/com/turn/ttorrent/client/SharedTorrent.java index 3f6309850..db85ca2dd 100644 --- a/ttorrent-client/src/main/java/com/turn/ttorrent/client/SharedTorrent.java +++ b/ttorrent-client/src/main/java/com/turn/ttorrent/client/SharedTorrent.java @@ -268,6 +268,17 @@ private void hashSingleThread() { } public synchronized void close() { + logger.trace("Closing torrent", myTorrentMetadata.getDirectoryName()); + try { + this.pieceStorage.close(); + isFileChannelOpen = false; + } catch (IOException ioe) { + logger.error("Error closing torrent byte storage: {}", + ioe.getMessage()); + } + } + + public synchronized void closeFully() { logger.trace("Closing torrent", myTorrentMetadata.getDirectoryName()); try { this.pieceStorage.closeFully(); diff --git a/ttorrent-client/src/main/java/com/turn/ttorrent/client/TorrentsStorage.java b/ttorrent-client/src/main/java/com/turn/ttorrent/client/TorrentsStorage.java index 73a50b2ae..27b49cef7 100644 --- a/ttorrent-client/src/main/java/com/turn/ttorrent/client/TorrentsStorage.java +++ b/ttorrent-client/src/main/java/com/turn/ttorrent/client/TorrentsStorage.java @@ -105,7 +105,7 @@ public Pair remove(String hash) { } } if (result.first() != null) { - result.first().close(); + result.first().closeFully(); } return result; } @@ -156,7 +156,7 @@ public void clear() { readWriteLock.writeLock().unlock(); } for (SharedTorrent sharedTorrent : sharedTorrents) { - sharedTorrent.close(); + sharedTorrent.closeFully(); } for (LoadedTorrent loadedTorrent : loadedTorrents) { try {