From 3c00c5f6c7c205585b72ea775f40e6b1243b6dcc Mon Sep 17 00:00:00 2001 From: theli Date: Mon, 12 Sep 2005 11:39:32 +0000 Subject: [PATCH] *) Complete Index Transfer See: http://www.yacy-forum.de/viewtopic.php?p=9622 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@711 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/IndexTransfer_p.html | 2 +- htroot/IndexTransfer_p.java | 9 ++++-- .../plasma/plasmaWordIndexDistribution.java | 32 +++++++++++++------ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/htroot/IndexTransfer_p.html b/htroot/IndexTransfer_p.html index 973b812b6..ed1f7b8f8 100644 --- a/htroot/IndexTransfer_p.html +++ b/htroot/IndexTransfer_p.html @@ -39,7 +39,7 @@

:: - #[status]# + #[status]# #[twcount]# (#[twpercent]#%) #[twrange]# #[peerName]# diff --git a/htroot/IndexTransfer_p.java b/htroot/IndexTransfer_p.java index 0ddcc14ea..8615ad655 100644 --- a/htroot/IndexTransfer_p.java +++ b/htroot/IndexTransfer_p.java @@ -69,10 +69,13 @@ public class IndexTransfer_p { switchboard.indexDistribution.startTransferWholeIndex(seed,true); } else if (post.containsKey("stopIndexTransfer")) { - switchboard.indexDistribution.stopTransferWholeIndex(); + switchboard.indexDistribution.stopTransferWholeIndex(true); + } else if (post.containsKey("newIndexTransfer")) { - switchboard.indexDistribution.abortTransferWholeIndex(); + switchboard.indexDistribution.abortTransferWholeIndex(true); } + prop.put("LOCATION",""); + return prop; } @@ -86,7 +89,7 @@ public class IndexTransfer_p { int transferedIdxCount = transfThread.getTransferedIndexCount(); prop.put("running_status",transfThread.getStatus()); prop.put("running_twcount",transferedIdxCount); - prop.put("running_twpercent",Float.toString(transferedIdxCount*100/wcount)); + prop.put("running_twpercent",Float.toString(transfThread.getTransferedIndexPercent())); prop.put("running_twrange", transfThread.getRange()); prop.put("running_peerName",transfThread.getSeed().getName()); prop.put("running_stopped",(transfThread.isFinished()) || (!transfThread.isAlive())?1:0); diff --git a/source/de/anomic/plasma/plasmaWordIndexDistribution.java b/source/de/anomic/plasma/plasmaWordIndexDistribution.java index 8c8b6d7ce..458b69d8d 100644 --- a/source/de/anomic/plasma/plasmaWordIndexDistribution.java +++ b/source/de/anomic/plasma/plasmaWordIndexDistribution.java @@ -67,7 +67,7 @@ public class plasmaWordIndexDistribution { public void close() { closed = true; if (transferIdxThread != null) { - stopTransferWholeIndex(); + stopTransferWholeIndex(false); } } @@ -400,15 +400,20 @@ public class plasmaWordIndexDistribution { } } - public void stopTransferWholeIndex() { - if ((transferIdxThread != null) && (!transferIdxThread.isFinished())) { - this.transferIdxThread.stopIt(); + public void stopTransferWholeIndex(boolean wait) { + if ((transferIdxThread != null) && (transferIdxThread.isAlive()) && (!transferIdxThread.isFinished())) { + try { + this.transferIdxThread.stopIt(wait); + } catch (InterruptedException e) { } } } - public void abortTransferWholeIndex() { + public void abortTransferWholeIndex(boolean wait) { if (transferIdxThread != null) { - if (!transferIdxThread.isFinished()) this.transferIdxThread.stopIt(); + if (!transferIdxThread.isFinished()) + try { + this.transferIdxThread.stopIt(wait); + } catch (InterruptedException e) { } transferIdxThread = null; } } @@ -421,19 +426,22 @@ public class plasmaWordIndexDistribution { private boolean finished = false; private int transferedIndexCount = 0; private String status = "running"; - private String startPointHash = "------------"; + private String oldStartingPointHash = "------------", startPointHash = "------------"; + private int wordsDBSize = 0; public transferIndexThread(yacySeed seed, boolean delete) { this.seed = seed; this.delete = delete; + this.wordsDBSize = plasmaSwitchboard.getSwitchboard().wordIndex.size(); } public void run() { performTransferWholeIndex(); } - public void stopIt() { + public void stopIt(boolean wait) throws InterruptedException { this.finished = true; + this.join(); } public boolean isFinished() { @@ -444,6 +452,11 @@ public class plasmaWordIndexDistribution { return this.transferedIndexCount; } + public float getTransferedIndexPercent() { + if (wordsDBSize == 0) return 100; + else return (float)(this.transferedIndexCount*100/wordsDBSize); + } + public yacySeed getSeed() { return this.seed; } @@ -453,7 +466,7 @@ public class plasmaWordIndexDistribution { } public String getRange() { - return "[------------ .. " + startPointHash + "]"; + return "[" + oldStartingPointHash + " .. " + startPointHash + "]"; } public void performTransferWholeIndex() { @@ -485,6 +498,7 @@ public class plasmaWordIndexDistribution { } // find start point for DHT-selection + oldStartingPointHash = startPointHash; startPointHash = indexEntities[indexEntities.length - 1].wordHash(); // DHT targets must have greater hashes String error;