- possibly better termination for SplitTable

- better abstraction in DidYouMean

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6375 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 87780f2562
commit f8371707e5

@ -97,7 +97,7 @@ public class DidYouMean {
* @return
*/
public SortedSet<String> getSuggestions(final String word, long timeout, int preSortSelection) {
if (word.indexOf(' ') > 0) return getSuggestions(word.split(" "), timeout, preSortSelection);
if (word.indexOf(' ') > 0) return getSuggestions(word.split(" "), timeout, preSortSelection, this.index);
long startTime = System.currentTimeMillis();
SortedSet<String> preSorted = getSuggestions(word, timeout);
long timelimit = 2 * System.currentTimeMillis() - startTime + timeout;
@ -123,11 +123,10 @@ public class DidYouMean {
* @return
*/
@SuppressWarnings("unchecked")
public SortedSet<String> getSuggestions(final String[] words, long timeout, int preSortSelection) {
public static SortedSet<String> getSuggestions(final String[] words, long timeout, int preSortSelection, final IndexCell<WordReference> index) {
SortedSet<String>[] s = new SortedSet[words.length];
for (int i = 0; i < words.length; i++) {
s[i] = getSuggestions(words[i], timeout / words.length, preSortSelection);
this.reset();
s[i] = new DidYouMean(index).getSuggestions(words[i], timeout / words.length, preSortSelection);
}
// make all permutations
SortedSet<String> result = new TreeSet<String>();

@ -83,7 +83,7 @@ public class SplitTable implements ObjectIndex {
private boolean useTailCache;
private boolean exceed134217727;
private BlockingQueue<DiscoverOrder> orderQueue;
private int discoverThreads;
private Discovery[] discoveryThreads;
public SplitTable(
final File path,
@ -111,9 +111,10 @@ public class SplitTable implements ObjectIndex {
this.exceed134217727 = exceed134217727;
this.entryOrder = new Row.EntryComparator(rowdef.objectOrder);
this.orderQueue = new LinkedBlockingQueue<DiscoverOrder>();
this.discoverThreads = Runtime.getRuntime().availableProcessors() + 1;
for (int i = 0; i < this.discoverThreads; i++) {
new Discovery(this.orderQueue).start();
this.discoveryThreads = new Discovery[Runtime.getRuntime().availableProcessors() + 1];
for (int i = 0; i < this.discoveryThreads.length; i++) {
this.discoveryThreads[i] = new Discovery(this.orderQueue);
this.discoveryThreads[i].start();
}
init();
}
@ -417,10 +418,26 @@ public class SplitTable implements ObjectIndex {
// check if in the given objectIndex is the key as given in the order
order.executeOrder();
}
Log.logInfo("SplitTable.Discovery", "terminated discovery thread " + this.getName());
}
}
private boolean discoveriesAlive() {
for (int i = 0; i < this.discoveryThreads.length; i++) {
if (!this.discoveryThreads[i].isAlive()) return false;
}
return true;
}
private ObjectIndex keeperOf(final byte[] key) {
if (!discoveriesAlive()) {
synchronized (tables) {
for (ObjectIndex oi: tables.values()) {
if (oi.has(key)) return oi;
}
return null;
}
}
Challenge challenge = null;
synchronized (tables) {
int tableCount = this.tables.size();
@ -587,7 +604,7 @@ public class SplitTable implements ObjectIndex {
public synchronized void close() {
// stop discover threads
if (this.orderQueue != null) for (int i = 0; i < this.discoverThreads; i++) {
if (this.orderQueue != null) for (int i = 0; i < this.discoveryThreads.length; i++) {
try {
this.orderQueue.put(poisonDiscoverOrder);
} catch (InterruptedException e) {

Loading…
Cancel
Save