change '\n' -> '\r\n' git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1720 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
60dac4325e
commit
2ee5796e76
@ -1,84 +1,87 @@
|
|||||||
// yacyNewsAction.java
|
// yacyNewsAction.java
|
||||||
// -----------------------
|
// -----------------------
|
||||||
// part of YaCy
|
// part of YaCy
|
||||||
// (C) by Michael Peter Christen; mc@anomic.de
|
// (C) by Michael Peter Christen; mc@anomic.de
|
||||||
// first published on http://www.anomic.de
|
// first published on http://www.anomic.de
|
||||||
// Frankfurt, Germany, 2005
|
// Frankfurt, Germany, 2005
|
||||||
// last major change: 29.07.2005
|
//
|
||||||
//
|
// $LastChangedDate$
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// $LastChangedRevision$
|
||||||
// it under the terms of the GNU General Public License as published by
|
// $LastChangedBy$
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
//
|
||||||
// (at your option) any later version.
|
// 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
|
||||||
// This program is distributed in the hope that it will be useful,
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// (at your option) any later version.
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
//
|
||||||
// GNU General Public License for more details.
|
// This program is distributed in the hope that it will be useful,
|
||||||
//
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// You should have received a copy of the GNU General Public License
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// along with this program; if not, write to the Free Software
|
// GNU General Public License for more details.
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
//
|
||||||
//
|
// You should have received a copy of the GNU General Public License
|
||||||
// Using this software in any meaning (reading, learning, copying, compiling,
|
// along with this program; if not, write to the Free Software
|
||||||
// running) means that you agree that the Author(s) is (are) not responsible
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
// for cost, loss of data or any harm that may be caused directly or indirectly
|
//
|
||||||
// by usage of this softare or this documentation. The usage of this software
|
// Using this software in any meaning (reading, learning, copying, compiling,
|
||||||
// is on your own risk. The installation and usage (starting/running) of this
|
// running) means that you agree that the Author(s) is (are) not responsible
|
||||||
// software may allow other people or application to access your computer and
|
// for cost, loss of data or any harm that may be caused directly or indirectly
|
||||||
// any attached devices and is highly dependent on the configuration of the
|
// by usage of this softare or this documentation. The usage of this software
|
||||||
// software which must be done by the user of the software; the author(s) is
|
// is on your own risk. The installation and usage (starting/running) of this
|
||||||
// (are) also not responsible for proper configuration and usage of the
|
// software may allow other people or application to access your computer and
|
||||||
// software, even if provoked by documentation provided together with
|
// any attached devices and is highly dependent on the configuration of the
|
||||||
// the software.
|
// software which must be done by the user of the software; the author(s) is
|
||||||
//
|
// (are) also not responsible for proper configuration and usage of the
|
||||||
// Any changes to this file according to the GPL as documented in the file
|
// software, even if provoked by documentation provided together with
|
||||||
// gpl.txt aside this file in the shipment you received can be done to the
|
// the software.
|
||||||
// lines that follows this copyright notice here, but changes must not be
|
//
|
||||||
// done inside the copyright notice above. A re-distribution must contain
|
// Any changes to this file according to the GPL as documented in the file
|
||||||
// the intact and unchanged copyright notice.
|
// gpl.txt aside this file in the shipment you received can be done to the
|
||||||
// Contributions and changes to the program code must be marked as such.
|
// lines that follows this copyright notice here, but changes must not be
|
||||||
|
// done inside the copyright notice above. A re-distribution must contain
|
||||||
package de.anomic.yacy;
|
// the intact and unchanged copyright notice.
|
||||||
|
// Contributions and changes to the program code must be marked as such.
|
||||||
import java.io.IOException;
|
|
||||||
|
package de.anomic.yacy;
|
||||||
import de.anomic.server.serverCodings;
|
|
||||||
import de.anomic.server.logging.serverLog;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class yacyNewsAction implements yacyPeerAction {
|
import de.anomic.server.serverCodings;
|
||||||
|
import de.anomic.server.logging.serverLog;
|
||||||
yacyNewsPool pool;
|
|
||||||
|
public class yacyNewsAction implements yacyPeerAction {
|
||||||
public yacyNewsAction(yacyNewsPool pool) {
|
|
||||||
this.pool = pool;
|
yacyNewsPool pool;
|
||||||
}
|
|
||||||
|
public yacyNewsAction(yacyNewsPool pool) {
|
||||||
public void processPeerArrival(yacySeed peer, boolean direct) {
|
this.pool = pool;
|
||||||
String recordString = peer.get("news", null);
|
}
|
||||||
//System.out.println("### triggered news arrival from peer " + peer.getName() + ", news " + ((recordString == null) ? "empty" : "attached"));
|
|
||||||
if ((recordString == null) || (recordString.length() == 0)) return;
|
public void processPeerArrival(yacySeed peer, boolean direct) {
|
||||||
String decodedString = de.anomic.tools.crypt.simpleDecode(recordString, "");
|
String recordString = peer.get("news", null);
|
||||||
yacyNewsRecord record = new yacyNewsRecord(decodedString);
|
//System.out.println("### triggered news arrival from peer " + peer.getName() + ", news " + ((recordString == null) ? "empty" : "attached"));
|
||||||
//System.out.println("### news arrival from peer " + peer.getName() + ", decoded=" + decodedString + ", record=" + recordString + ", news=" + record.toString());
|
if ((recordString == null) || (recordString.length() == 0)) return;
|
||||||
String cre1 = (String) serverCodings.string2map(decodedString).get("cre");
|
String decodedString = de.anomic.tools.crypt.simpleDecode(recordString, "");
|
||||||
String cre2 = (String) serverCodings.string2map(record.toString()).get("cre");
|
yacyNewsRecord record = new yacyNewsRecord(decodedString);
|
||||||
if ((cre1 == null) || (cre2 == null) || (!(cre1.equals(cre2)))) {
|
//System.out.println("### news arrival from peer " + peer.getName() + ", decoded=" + decodedString + ", record=" + recordString + ", news=" + record.toString());
|
||||||
System.out.println("### ERROR - cre are not equal: cre1=" + cre1 + ", cre2=" + cre2);
|
String cre1 = (String) serverCodings.string2map(decodedString).get("cre");
|
||||||
return;
|
String cre2 = (String) serverCodings.string2map(record.toString()).get("cre");
|
||||||
}
|
if ((cre1 == null) || (cre2 == null) || (!(cre1.equals(cre2)))) {
|
||||||
try {
|
System.out.println("### ERROR - cre are not equal: cre1=" + cre1 + ", cre2=" + cre2);
|
||||||
synchronized (pool) {this.pool.enqueueIncomingNews(record);}
|
return;
|
||||||
} catch (IOException e) {
|
}
|
||||||
serverLog.logSevere("YACY", "processPeerArrival", e);
|
try {
|
||||||
}
|
synchronized (pool) {this.pool.enqueueIncomingNews(record);}
|
||||||
}
|
} catch (IOException e) {
|
||||||
|
serverLog.logSevere("YACY", "processPeerArrival", e);
|
||||||
public void processPeerDeparture(yacySeed peer) {
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processPeerPing(yacySeed peer) {
|
public void processPeerDeparture(yacySeed peer) {
|
||||||
processPeerArrival(peer, true);
|
}
|
||||||
}
|
|
||||||
|
public void processPeerPing(yacySeed peer) {
|
||||||
}
|
processPeerArrival(peer, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,189 +1,192 @@
|
|||||||
// yacyNewsQueue.java
|
// yacyNewsQueue.java
|
||||||
// -----------------------
|
// -----------------------
|
||||||
// part of YaCy
|
// part of YaCy
|
||||||
// (C) by Michael Peter Christen; mc@anomic.de
|
// (C) by Michael Peter Christen; mc@anomic.de
|
||||||
// first published on http://www.anomic.de
|
// first published on http://www.anomic.de
|
||||||
// Frankfurt, Germany, 2005
|
// Frankfurt, Germany, 2005
|
||||||
// last major change: 13.07.2005
|
//
|
||||||
//
|
// $LastChangedDate$
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// $LastChangedRevision$
|
||||||
// it under the terms of the GNU General Public License as published by
|
// $LastChangedBy$
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
//
|
||||||
// (at your option) any later version.
|
// 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
|
||||||
// This program is distributed in the hope that it will be useful,
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// (at your option) any later version.
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
//
|
||||||
// GNU General Public License for more details.
|
// This program is distributed in the hope that it will be useful,
|
||||||
//
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// You should have received a copy of the GNU General Public License
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// along with this program; if not, write to the Free Software
|
// GNU General Public License for more details.
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
//
|
||||||
//
|
// You should have received a copy of the GNU General Public License
|
||||||
// Using this software in any meaning (reading, learning, copying, compiling,
|
// along with this program; if not, write to the Free Software
|
||||||
// running) means that you agree that the Author(s) is (are) not responsible
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
// for cost, loss of data or any harm that may be caused directly or indirectly
|
//
|
||||||
// by usage of this softare or this documentation. The usage of this software
|
// Using this software in any meaning (reading, learning, copying, compiling,
|
||||||
// is on your own risk. The installation and usage (starting/running) of this
|
// running) means that you agree that the Author(s) is (are) not responsible
|
||||||
// software may allow other people or application to access your computer and
|
// for cost, loss of data or any harm that may be caused directly or indirectly
|
||||||
// any attached devices and is highly dependent on the configuration of the
|
// by usage of this softare or this documentation. The usage of this software
|
||||||
// software which must be done by the user of the software; the author(s) is
|
// is on your own risk. The installation and usage (starting/running) of this
|
||||||
// (are) also not responsible for proper configuration and usage of the
|
// software may allow other people or application to access your computer and
|
||||||
// software, even if provoked by documentation provided together with
|
// any attached devices and is highly dependent on the configuration of the
|
||||||
// the software.
|
// software which must be done by the user of the software; the author(s) is
|
||||||
//
|
// (are) also not responsible for proper configuration and usage of the
|
||||||
// Any changes to this file according to the GPL as documented in the file
|
// software, even if provoked by documentation provided together with
|
||||||
// gpl.txt aside this file in the shipment you received can be done to the
|
// the software.
|
||||||
// lines that follows this copyright notice here, but changes must not be
|
//
|
||||||
// done inside the copyright notice above. A re-distribution must contain
|
// Any changes to this file according to the GPL as documented in the file
|
||||||
// the intact and unchanged copyright notice.
|
// gpl.txt aside this file in the shipment you received can be done to the
|
||||||
// Contributions and changes to the program code must be marked as such.
|
// lines that follows this copyright notice here, but changes must not be
|
||||||
|
// done inside the copyright notice above. A re-distribution must contain
|
||||||
package de.anomic.yacy;
|
// the intact and unchanged copyright notice.
|
||||||
|
// Contributions and changes to the program code must be marked as such.
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
package de.anomic.yacy;
|
||||||
import java.util.Iterator;
|
|
||||||
|
import java.io.File;
|
||||||
import de.anomic.yacy.yacyCore;
|
import java.io.IOException;
|
||||||
import de.anomic.kelondro.kelondroBase64Order;
|
import java.util.Iterator;
|
||||||
import de.anomic.kelondro.kelondroTree;
|
|
||||||
import de.anomic.kelondro.kelondroException;
|
import de.anomic.yacy.yacyCore;
|
||||||
import de.anomic.server.serverCodings;
|
import de.anomic.kelondro.kelondroBase64Order;
|
||||||
import de.anomic.server.serverDate;
|
import de.anomic.kelondro.kelondroTree;
|
||||||
|
import de.anomic.kelondro.kelondroException;
|
||||||
public class yacyNewsDB {
|
import de.anomic.server.serverCodings;
|
||||||
|
import de.anomic.server.serverDate;
|
||||||
private File path;
|
|
||||||
private int bufferkb;
|
public class yacyNewsDB {
|
||||||
private kelondroTree news;
|
|
||||||
|
private File path;
|
||||||
public static final int attributesMaxLength = yacyNewsRecord.maxNewsRecordLength
|
private int bufferkb;
|
||||||
- yacyNewsRecord.idLength()
|
private kelondroTree news;
|
||||||
- yacyNewsRecord.categoryStringLength
|
|
||||||
- yacyCore.universalDateShortPattern.length()
|
public static final int attributesMaxLength = yacyNewsRecord.maxNewsRecordLength
|
||||||
- 2;
|
- yacyNewsRecord.idLength()
|
||||||
|
- yacyNewsRecord.categoryStringLength
|
||||||
public yacyNewsDB(File path, int bufferkb) {
|
- yacyCore.universalDateShortPattern.length()
|
||||||
this.path = path;
|
- 2;
|
||||||
this.bufferkb = bufferkb;
|
|
||||||
|
public yacyNewsDB(File path, int bufferkb) {
|
||||||
if (path.exists()) try {
|
this.path = path;
|
||||||
news = new kelondroTree(path, bufferkb * 0x400);
|
this.bufferkb = bufferkb;
|
||||||
} catch (IOException e) {
|
|
||||||
news = createDB(path, bufferkb);
|
if (path.exists()) try {
|
||||||
} else {
|
news = new kelondroTree(path, bufferkb * 0x400);
|
||||||
news = createDB(path, bufferkb);
|
} catch (IOException e) {
|
||||||
}
|
news = createDB(path, bufferkb);
|
||||||
}
|
} else {
|
||||||
|
news = createDB(path, bufferkb);
|
||||||
private static kelondroTree createDB(File path, int bufferkb) {
|
}
|
||||||
return new kelondroTree(path, bufferkb * 0x400, new int[] {
|
}
|
||||||
yacyNewsRecord.idLength(), // id = created + originator
|
|
||||||
yacyNewsRecord.categoryStringLength, // category
|
private static kelondroTree createDB(File path, int bufferkb) {
|
||||||
yacyCore.universalDateShortPattern.length(), // received
|
return new kelondroTree(path, bufferkb * 0x400, new int[] {
|
||||||
2,
|
yacyNewsRecord.idLength(), // id = created + originator
|
||||||
attributesMaxLength
|
yacyNewsRecord.categoryStringLength, // category
|
||||||
}, true);
|
yacyCore.universalDateShortPattern.length(), // received
|
||||||
}
|
2,
|
||||||
|
attributesMaxLength
|
||||||
private void resetDB() {
|
}, true);
|
||||||
try {close();} catch (Exception e) {}
|
}
|
||||||
if (path.exists()) path.delete();
|
|
||||||
news = createDB(path, bufferkb);
|
private void resetDB() {
|
||||||
}
|
try {close();} catch (Exception e) {}
|
||||||
|
if (path.exists()) path.delete();
|
||||||
public int[] dbCacheChunkSize() {
|
news = createDB(path, bufferkb);
|
||||||
return news.cacheChunkSize();
|
}
|
||||||
}
|
|
||||||
|
public int[] dbCacheChunkSize() {
|
||||||
public int[] dbCacheFillStatus() {
|
return news.cacheChunkSize();
|
||||||
return news.cacheFillStatus();
|
}
|
||||||
}
|
|
||||||
|
public int[] dbCacheFillStatus() {
|
||||||
public void close() {
|
return news.cacheFillStatus();
|
||||||
if (news != null) try {news.close();} catch (IOException e) {}
|
}
|
||||||
news = null;
|
|
||||||
}
|
public void close() {
|
||||||
|
if (news != null) try {news.close();} catch (IOException e) {}
|
||||||
public void finalize() {
|
news = null;
|
||||||
close();
|
}
|
||||||
}
|
|
||||||
|
public void finalize() {
|
||||||
public int size() {
|
close();
|
||||||
return news.size();
|
}
|
||||||
}
|
|
||||||
|
public int size() {
|
||||||
public void remove(String id) throws IOException {
|
return news.size();
|
||||||
news.remove(id.getBytes());
|
}
|
||||||
}
|
|
||||||
|
public void remove(String id) throws IOException {
|
||||||
public synchronized yacyNewsRecord put(yacyNewsRecord record) throws IOException {
|
news.remove(id.getBytes());
|
||||||
try {
|
}
|
||||||
return b2r(news.put(r2b(record)));
|
|
||||||
} catch (kelondroException e) {
|
public synchronized yacyNewsRecord put(yacyNewsRecord record) throws IOException {
|
||||||
resetDB();
|
try {
|
||||||
return b2r(news.put(r2b(record)));
|
return b2r(news.put(r2b(record)));
|
||||||
}
|
} catch (kelondroException e) {
|
||||||
}
|
resetDB();
|
||||||
|
return b2r(news.put(r2b(record)));
|
||||||
public synchronized Iterator news() throws IOException {
|
}
|
||||||
// the iteration iterates yacyNewsRecord - type objects
|
}
|
||||||
return new recordIterator();
|
|
||||||
}
|
public synchronized Iterator news() throws IOException {
|
||||||
|
// the iteration iterates yacyNewsRecord - type objects
|
||||||
public class recordIterator implements Iterator {
|
return new recordIterator();
|
||||||
|
}
|
||||||
Iterator nodeIterator;
|
|
||||||
|
public class recordIterator implements Iterator {
|
||||||
public recordIterator() throws IOException {
|
|
||||||
nodeIterator = news.rows(true, false);
|
Iterator nodeIterator;
|
||||||
}
|
|
||||||
|
public recordIterator() throws IOException {
|
||||||
public boolean hasNext() {
|
nodeIterator = news.rows(true, false);
|
||||||
return nodeIterator.hasNext();
|
}
|
||||||
}
|
|
||||||
|
public boolean hasNext() {
|
||||||
public Object next() {
|
return nodeIterator.hasNext();
|
||||||
return b2r((byte[][]) nodeIterator.next());
|
}
|
||||||
}
|
|
||||||
|
public Object next() {
|
||||||
public void remove() {
|
return b2r((byte[][]) nodeIterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public void remove() {
|
||||||
|
}
|
||||||
public synchronized yacyNewsRecord get(String id) throws IOException {
|
|
||||||
try {
|
}
|
||||||
return b2r(news.get(id.getBytes()));
|
|
||||||
} catch (kelondroException e) {
|
public synchronized yacyNewsRecord get(String id) throws IOException {
|
||||||
resetDB();
|
try {
|
||||||
return null;
|
return b2r(news.get(id.getBytes()));
|
||||||
}
|
} catch (kelondroException e) {
|
||||||
}
|
resetDB();
|
||||||
|
return null;
|
||||||
private static yacyNewsRecord b2r(byte[][] b) {
|
}
|
||||||
if (b == null) return null;
|
}
|
||||||
return new yacyNewsRecord(
|
|
||||||
new String(b[0]),
|
private static yacyNewsRecord b2r(byte[][] b) {
|
||||||
new String(b[1]),
|
if (b == null) return null;
|
||||||
(b[2] == null) ? null : yacyCore.parseUniversalDate(new String(b[2]), serverDate.UTCDiffString()),
|
return new yacyNewsRecord(
|
||||||
(int) kelondroBase64Order.enhancedCoder.decodeLong(new String(b[3])),
|
new String(b[0]),
|
||||||
serverCodings.string2map(new String(b[4]))
|
new String(b[1]),
|
||||||
);
|
(b[2] == null) ? null : yacyCore.parseUniversalDate(new String(b[2]), serverDate.UTCDiffString()),
|
||||||
}
|
(int) kelondroBase64Order.enhancedCoder.decodeLong(new String(b[3])),
|
||||||
|
serverCodings.string2map(new String(b[4]))
|
||||||
private static byte[][] r2b(yacyNewsRecord r) {
|
);
|
||||||
if (r == null) return null;
|
}
|
||||||
String attributes = r.attributes().toString();
|
|
||||||
if (attributes.length() > attributesMaxLength) throw new IllegalArgumentException("attribute length=" + attributes.length() + " exceeds maximum size=" + attributesMaxLength);
|
private static byte[][] r2b(yacyNewsRecord r) {
|
||||||
byte[][] b = new byte[5][];
|
if (r == null) return null;
|
||||||
b[0] = r.id().getBytes();
|
String attributes = r.attributes().toString();
|
||||||
b[1] = r.category().getBytes();
|
if (attributes.length() > attributesMaxLength) throw new IllegalArgumentException("attribute length=" + attributes.length() + " exceeds maximum size=" + attributesMaxLength);
|
||||||
b[2] = (r.received() == null) ? null : yacyCore.universalDateShortString(r.received()).getBytes();
|
byte[][] b = new byte[5][];
|
||||||
b[3] = kelondroBase64Order.enhancedCoder.encodeLong(r.distributed(), 2).getBytes();
|
b[0] = r.id().getBytes();
|
||||||
b[4] = attributes.getBytes();
|
b[1] = r.category().getBytes();
|
||||||
return b;
|
b[2] = (r.received() == null) ? null : yacyCore.universalDateShortString(r.received()).getBytes();
|
||||||
}
|
b[3] = kelondroBase64Order.enhancedCoder.encodeLong(r.distributed(), 2).getBytes();
|
||||||
|
b[4] = attributes.getBytes();
|
||||||
}
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,173 +1,176 @@
|
|||||||
// yacyNewsQueue.java
|
// yacyNewsQueue.java
|
||||||
// -----------------------
|
// -----------------------
|
||||||
// part of YaCy
|
// part of YaCy
|
||||||
// (C) by Michael Peter Christen; mc@anomic.de
|
// (C) by Michael Peter Christen; mc@anomic.de
|
||||||
// first published on http://www.anomic.de
|
// first published on http://www.anomic.de
|
||||||
// Frankfurt, Germany, 2005
|
// Frankfurt, Germany, 2005
|
||||||
// last major change: 13.07.2005
|
//
|
||||||
//
|
// $LastChangedDate$
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// $LastChangedRevision$
|
||||||
// it under the terms of the GNU General Public License as published by
|
// $LastChangedBy$
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
//
|
||||||
// (at your option) any later version.
|
// 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
|
||||||
// This program is distributed in the hope that it will be useful,
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// (at your option) any later version.
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
//
|
||||||
// GNU General Public License for more details.
|
// This program is distributed in the hope that it will be useful,
|
||||||
//
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// You should have received a copy of the GNU General Public License
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// along with this program; if not, write to the Free Software
|
// GNU General Public License for more details.
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
//
|
||||||
//
|
// You should have received a copy of the GNU General Public License
|
||||||
// Using this software in any meaning (reading, learning, copying, compiling,
|
// along with this program; if not, write to the Free Software
|
||||||
// running) means that you agree that the Author(s) is (are) not responsible
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
// for cost, loss of data or any harm that may be caused directly or indirectly
|
//
|
||||||
// by usage of this softare or this documentation. The usage of this software
|
// Using this software in any meaning (reading, learning, copying, compiling,
|
||||||
// is on your own risk. The installation and usage (starting/running) of this
|
// running) means that you agree that the Author(s) is (are) not responsible
|
||||||
// software may allow other people or application to access your computer and
|
// for cost, loss of data or any harm that may be caused directly or indirectly
|
||||||
// any attached devices and is highly dependent on the configuration of the
|
// by usage of this softare or this documentation. The usage of this software
|
||||||
// software which must be done by the user of the software; the author(s) is
|
// is on your own risk. The installation and usage (starting/running) of this
|
||||||
// (are) also not responsible for proper configuration and usage of the
|
// software may allow other people or application to access your computer and
|
||||||
// software, even if provoked by documentation provided together with
|
// any attached devices and is highly dependent on the configuration of the
|
||||||
// the software.
|
// software which must be done by the user of the software; the author(s) is
|
||||||
//
|
// (are) also not responsible for proper configuration and usage of the
|
||||||
// Any changes to this file according to the GPL as documented in the file
|
// software, even if provoked by documentation provided together with
|
||||||
// gpl.txt aside this file in the shipment you received can be done to the
|
// the software.
|
||||||
// lines that follows this copyright notice here, but changes must not be
|
//
|
||||||
// done inside the copyright notice above. A re-distribution must contain
|
// Any changes to this file according to the GPL as documented in the file
|
||||||
// the intact and unchanged copyright notice.
|
// gpl.txt aside this file in the shipment you received can be done to the
|
||||||
// Contributions and changes to the program code must be marked as such.
|
// lines that follows this copyright notice here, but changes must not be
|
||||||
|
// done inside the copyright notice above. A re-distribution must contain
|
||||||
package de.anomic.yacy;
|
// the intact and unchanged copyright notice.
|
||||||
|
// Contributions and changes to the program code must be marked as such.
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
package de.anomic.yacy;
|
||||||
import java.util.Date;
|
|
||||||
|
import java.io.File;
|
||||||
import de.anomic.kelondro.kelondroStack;
|
import java.io.IOException;
|
||||||
import de.anomic.kelondro.kelondroException;
|
import java.util.Date;
|
||||||
|
|
||||||
public class yacyNewsQueue {
|
import de.anomic.kelondro.kelondroStack;
|
||||||
|
import de.anomic.kelondro.kelondroException;
|
||||||
private File path;
|
|
||||||
private kelondroStack queueStack;
|
public class yacyNewsQueue {
|
||||||
private yacyNewsDB newsDB;
|
|
||||||
|
private File path;
|
||||||
public yacyNewsQueue(File path, yacyNewsDB newsDB) {
|
private kelondroStack queueStack;
|
||||||
this.path = path;
|
private yacyNewsDB newsDB;
|
||||||
this.newsDB = newsDB;
|
|
||||||
|
public yacyNewsQueue(File path, yacyNewsDB newsDB) {
|
||||||
if (path.exists()) try {
|
this.path = path;
|
||||||
queueStack = new kelondroStack(path, 0);
|
this.newsDB = newsDB;
|
||||||
} catch (kelondroException e) {
|
|
||||||
path.delete();
|
if (path.exists()) try {
|
||||||
queueStack = createStack(path);
|
queueStack = new kelondroStack(path, 0);
|
||||||
} catch (IOException e) {
|
} catch (kelondroException e) {
|
||||||
path.delete();
|
path.delete();
|
||||||
queueStack = createStack(path);
|
queueStack = createStack(path);
|
||||||
} else {
|
} catch (IOException e) {
|
||||||
queueStack = createStack(path);
|
path.delete();
|
||||||
}
|
queueStack = createStack(path);
|
||||||
}
|
} else {
|
||||||
|
queueStack = createStack(path);
|
||||||
private static kelondroStack createStack(File path) {
|
}
|
||||||
return new kelondroStack(path, 0, new int[] {
|
}
|
||||||
yacyNewsRecord.idLength(), // id = created + originator
|
|
||||||
yacyCore.universalDateShortPattern.length() // last touched
|
private static kelondroStack createStack(File path) {
|
||||||
}, true);
|
return new kelondroStack(path, 0, new int[] {
|
||||||
}
|
yacyNewsRecord.idLength(), // id = created + originator
|
||||||
|
yacyCore.universalDateShortPattern.length() // last touched
|
||||||
private void resetDB() {
|
}, true);
|
||||||
try {close();} catch (Exception e) {}
|
}
|
||||||
if (path.exists()) path.delete();
|
|
||||||
queueStack = createStack(path);
|
private void resetDB() {
|
||||||
}
|
try {close();} catch (Exception e) {}
|
||||||
|
if (path.exists()) path.delete();
|
||||||
public void clear() {
|
queueStack = createStack(path);
|
||||||
resetDB();
|
}
|
||||||
}
|
|
||||||
|
public void clear() {
|
||||||
public void close() {
|
resetDB();
|
||||||
if (queueStack != null) try {queueStack.close();} catch (IOException e) {}
|
}
|
||||||
queueStack = null;
|
|
||||||
}
|
public void close() {
|
||||||
|
if (queueStack != null) try {queueStack.close();} catch (IOException e) {}
|
||||||
public void finalize() {
|
queueStack = null;
|
||||||
close();
|
}
|
||||||
}
|
|
||||||
|
public void finalize() {
|
||||||
public int size() {
|
close();
|
||||||
return queueStack.size();
|
}
|
||||||
}
|
|
||||||
|
public int size() {
|
||||||
public synchronized void push(yacyNewsRecord entry) throws IOException {
|
return queueStack.size();
|
||||||
queueStack.push(r2b(entry, true));
|
}
|
||||||
}
|
|
||||||
|
public synchronized void push(yacyNewsRecord entry) throws IOException {
|
||||||
public synchronized yacyNewsRecord pop(int dist) throws IOException {
|
queueStack.push(r2b(entry, true));
|
||||||
if (queueStack.size() == 0) return null;
|
}
|
||||||
return b2r(queueStack.pop(dist));
|
|
||||||
}
|
public synchronized yacyNewsRecord pop(int dist) throws IOException {
|
||||||
|
if (queueStack.size() == 0) return null;
|
||||||
public synchronized yacyNewsRecord top(int dist) throws IOException {
|
return b2r(queueStack.pop(dist));
|
||||||
if (queueStack.size() == 0) return null;
|
}
|
||||||
return b2r(queueStack.top(dist));
|
|
||||||
}
|
public synchronized yacyNewsRecord top(int dist) throws IOException {
|
||||||
|
if (queueStack.size() == 0) return null;
|
||||||
public synchronized yacyNewsRecord topInc() throws IOException {
|
return b2r(queueStack.top(dist));
|
||||||
if (queueStack.size() == 0) return null;
|
}
|
||||||
yacyNewsRecord entry = pop(0);
|
|
||||||
if (entry != null) {
|
public synchronized yacyNewsRecord topInc() throws IOException {
|
||||||
entry.incDistribution();
|
if (queueStack.size() == 0) return null;
|
||||||
push(entry);
|
yacyNewsRecord entry = pop(0);
|
||||||
}
|
if (entry != null) {
|
||||||
return entry;
|
entry.incDistribution();
|
||||||
}
|
push(entry);
|
||||||
|
}
|
||||||
public synchronized yacyNewsRecord remove(String id) throws IOException {
|
return entry;
|
||||||
yacyNewsRecord record;
|
}
|
||||||
for (int i = 0; i < size(); i++) {
|
|
||||||
record = top(i);
|
public synchronized yacyNewsRecord remove(String id) throws IOException {
|
||||||
if ((record != null) && (record.id().equals(id))) {
|
yacyNewsRecord record;
|
||||||
pop(i);
|
for (int i = 0; i < size(); i++) {
|
||||||
return record;
|
record = top(i);
|
||||||
}
|
if ((record != null) && (record.id().equals(id))) {
|
||||||
}
|
pop(i);
|
||||||
return null;
|
return record;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
/*
|
}
|
||||||
public synchronized void incDistributedCounter(yacyNewsRecord entry) throws IOException {
|
|
||||||
// this works only if the entry element lies ontop of the stack
|
|
||||||
yacyNewsRecord topEntry = top();
|
/*
|
||||||
if (!(topEntry.id().equals(entry.id()))) throw new IllegalArgumentException("entry is not ontop of the stack");
|
public synchronized void incDistributedCounter(yacyNewsRecord entry) throws IOException {
|
||||||
pop();
|
// this works only if the entry element lies ontop of the stack
|
||||||
entry.incDistribution();
|
yacyNewsRecord topEntry = top();
|
||||||
push(entry);
|
if (!(topEntry.id().equals(entry.id()))) throw new IllegalArgumentException("entry is not ontop of the stack");
|
||||||
}
|
pop();
|
||||||
*/
|
entry.incDistribution();
|
||||||
|
push(entry);
|
||||||
private yacyNewsRecord b2r(byte[][] b) throws IOException {
|
}
|
||||||
if (b == null) return null;
|
*/
|
||||||
String id = new String(b[0]);
|
|
||||||
//Date touched = yacyCore.parseUniversalDate(new String(b[1]));
|
private yacyNewsRecord b2r(byte[][] b) throws IOException {
|
||||||
return newsDB.get(id);
|
if (b == null) return null;
|
||||||
}
|
String id = new String(b[0]);
|
||||||
|
//Date touched = yacyCore.parseUniversalDate(new String(b[1]));
|
||||||
private byte[][] r2b(yacyNewsRecord r, boolean updateDB) throws IOException {
|
return newsDB.get(id);
|
||||||
if (r == null) return null;
|
}
|
||||||
if (updateDB) {
|
|
||||||
newsDB.put(r);
|
private byte[][] r2b(yacyNewsRecord r, boolean updateDB) throws IOException {
|
||||||
} else {
|
if (r == null) return null;
|
||||||
yacyNewsRecord r1 = newsDB.get(r.id());
|
if (updateDB) {
|
||||||
if (r1 == null) newsDB.put(r);
|
newsDB.put(r);
|
||||||
}
|
} else {
|
||||||
byte[][] b = new byte[2][];
|
yacyNewsRecord r1 = newsDB.get(r.id());
|
||||||
b[0] = r.id().getBytes();
|
if (r1 == null) newsDB.put(r);
|
||||||
b[1] = yacyCore.universalDateShortString(new Date()).getBytes();
|
}
|
||||||
return b;
|
byte[][] b = new byte[2][];
|
||||||
}
|
b[0] = r.id().getBytes();
|
||||||
|
b[1] = yacyCore.universalDateShortString(new Date()).getBytes();
|
||||||
}
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,153 +1,156 @@
|
|||||||
// yacyNewsRecord.java
|
// yacyNewsRecord.java
|
||||||
// -----------------------
|
// -----------------------
|
||||||
// part of YaCy
|
// part of YaCy
|
||||||
// (C) by Michael Peter Christen; mc@anomic.de
|
// (C) by Michael Peter Christen; mc@anomic.de
|
||||||
// first published on http://www.anomic.de
|
// first published on http://www.anomic.de
|
||||||
// Frankfurt, Germany, 2005
|
// Frankfurt, Germany, 2005
|
||||||
// last major change: 13.07.2005
|
//
|
||||||
//
|
// $LastChangedDate$
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// $LastChangedRevision$
|
||||||
// it under the terms of the GNU General Public License as published by
|
// $LastChangedBy$
|
||||||
// the Free Software Foundation; either version 2 of the License, or
|
//
|
||||||
// (at your option) any later version.
|
// 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
|
||||||
// This program is distributed in the hope that it will be useful,
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// (at your option) any later version.
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
//
|
||||||
// GNU General Public License for more details.
|
// This program is distributed in the hope that it will be useful,
|
||||||
//
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// You should have received a copy of the GNU General Public License
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// along with this program; if not, write to the Free Software
|
// GNU General Public License for more details.
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
//
|
||||||
//
|
// You should have received a copy of the GNU General Public License
|
||||||
// Using this software in any meaning (reading, learning, copying, compiling,
|
// along with this program; if not, write to the Free Software
|
||||||
// running) means that you agree that the Author(s) is (are) not responsible
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
// for cost, loss of data or any harm that may be caused directly or indirectly
|
//
|
||||||
// by usage of this softare or this documentation. The usage of this software
|
// Using this software in any meaning (reading, learning, copying, compiling,
|
||||||
// is on your own risk. The installation and usage (starting/running) of this
|
// running) means that you agree that the Author(s) is (are) not responsible
|
||||||
// software may allow other people or application to access your computer and
|
// for cost, loss of data or any harm that may be caused directly or indirectly
|
||||||
// any attached devices and is highly dependent on the configuration of the
|
// by usage of this softare or this documentation. The usage of this software
|
||||||
// software which must be done by the user of the software; the author(s) is
|
// is on your own risk. The installation and usage (starting/running) of this
|
||||||
// (are) also not responsible for proper configuration and usage of the
|
// software may allow other people or application to access your computer and
|
||||||
// software, even if provoked by documentation provided together with
|
// any attached devices and is highly dependent on the configuration of the
|
||||||
// the software.
|
// software which must be done by the user of the software; the author(s) is
|
||||||
//
|
// (are) also not responsible for proper configuration and usage of the
|
||||||
// Any changes to this file according to the GPL as documented in the file
|
// software, even if provoked by documentation provided together with
|
||||||
// gpl.txt aside this file in the shipment you received can be done to the
|
// the software.
|
||||||
// lines that follows this copyright notice here, but changes must not be
|
//
|
||||||
// done inside the copyright notice above. A re-distribution must contain
|
// Any changes to this file according to the GPL as documented in the file
|
||||||
// the intact and unchanged copyright notice.
|
// gpl.txt aside this file in the shipment you received can be done to the
|
||||||
// Contributions and changes to the program code must be marked as such.
|
// lines that follows this copyright notice here, but changes must not be
|
||||||
|
// done inside the copyright notice above. A re-distribution must contain
|
||||||
package de.anomic.yacy;
|
// the intact and unchanged copyright notice.
|
||||||
|
// Contributions and changes to the program code must be marked as such.
|
||||||
import de.anomic.server.serverCodings;
|
|
||||||
import de.anomic.server.serverDate;
|
package de.anomic.yacy;
|
||||||
|
|
||||||
import java.util.Date;
|
import de.anomic.server.serverCodings;
|
||||||
import java.util.Map;
|
import de.anomic.server.serverDate;
|
||||||
|
|
||||||
public class yacyNewsRecord {
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
public static final int maxNewsRecordLength = 512;
|
|
||||||
public static final int categoryStringLength = 8;
|
public class yacyNewsRecord {
|
||||||
|
|
||||||
private String originator; // hash of originating peer
|
public static final int maxNewsRecordLength = 512;
|
||||||
private Date created; // Date when news was created by originator
|
public static final int categoryStringLength = 8;
|
||||||
private Date received; // Date when news was received here at this peer
|
|
||||||
private String category; // keyword that adresses possible actions
|
private String originator; // hash of originating peer
|
||||||
private int distributed; // counter that counts number of distributions of this news record
|
private Date created; // Date when news was created by originator
|
||||||
private Map attributes; // elemets of the news for a special category
|
private Date received; // Date when news was received here at this peer
|
||||||
|
private String category; // keyword that adresses possible actions
|
||||||
public yacyNewsRecord(String newsString) {
|
private int distributed; // counter that counts number of distributions of this news record
|
||||||
this.attributes = serverCodings.string2map(newsString);
|
private Map attributes; // elemets of the news for a special category
|
||||||
this.received = (attributes.containsKey("rec")) ? yacyCore.parseUniversalDate((String) attributes.get("rec"), serverDate.UTCDiffString()) : new Date();
|
|
||||||
this.created = (attributes.containsKey("cre")) ? yacyCore.parseUniversalDate((String) attributes.get("cre"), serverDate.UTCDiffString()) : new Date();
|
public yacyNewsRecord(String newsString) {
|
||||||
this.category = (attributes.containsKey("cat")) ? (String) attributes.get("cat") : null;
|
this.attributes = serverCodings.string2map(newsString);
|
||||||
this.distributed = (attributes.containsKey("dis")) ? Integer.parseInt((String) attributes.get("dis")) : 0;
|
this.received = (attributes.containsKey("rec")) ? yacyCore.parseUniversalDate((String) attributes.get("rec"), serverDate.UTCDiffString()) : new Date();
|
||||||
this.originator = (attributes.containsKey("ori")) ? (String) attributes.get("ori") : null;
|
this.created = (attributes.containsKey("cre")) ? yacyCore.parseUniversalDate((String) attributes.get("cre"), serverDate.UTCDiffString()) : new Date();
|
||||||
removeStandards();
|
this.category = (attributes.containsKey("cat")) ? (String) attributes.get("cat") : null;
|
||||||
}
|
this.distributed = (attributes.containsKey("dis")) ? Integer.parseInt((String) attributes.get("dis")) : 0;
|
||||||
|
this.originator = (attributes.containsKey("ori")) ? (String) attributes.get("ori") : null;
|
||||||
public yacyNewsRecord(String category, Map attributes) {
|
removeStandards();
|
||||||
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length exceeds maximum");
|
}
|
||||||
this.attributes = attributes;
|
|
||||||
this.received = null;
|
public yacyNewsRecord(String category, Map attributes) {
|
||||||
this.created = new Date();
|
if (category.length() > categoryStringLength) throw new IllegalArgumentException("category length exceeds maximum");
|
||||||
this.category = category;
|
this.attributes = attributes;
|
||||||
this.distributed = 0;
|
this.received = null;
|
||||||
this.originator = yacyCore.seedDB.mySeed.hash;
|
this.created = new Date();
|
||||||
removeStandards();
|
this.category = category;
|
||||||
}
|
this.distributed = 0;
|
||||||
|
this.originator = yacyCore.seedDB.mySeed.hash;
|
||||||
protected yacyNewsRecord(String id, String category, Date received, int distributed, Map attributes) {
|
removeStandards();
|
||||||
this.attributes = attributes;
|
}
|
||||||
this.received = received;
|
|
||||||
this.created = yacyCore.parseUniversalDate(id.substring(0, yacyCore.universalDateShortPattern.length()), serverDate.UTCDiffString());
|
protected yacyNewsRecord(String id, String category, Date received, int distributed, Map attributes) {
|
||||||
this.category = category;
|
this.attributes = attributes;
|
||||||
this.distributed = distributed;
|
this.received = received;
|
||||||
this.originator = id.substring(yacyCore.universalDateShortPattern.length());
|
this.created = yacyCore.parseUniversalDate(id.substring(0, yacyCore.universalDateShortPattern.length()), serverDate.UTCDiffString());
|
||||||
removeStandards();
|
this.category = category;
|
||||||
}
|
this.distributed = distributed;
|
||||||
|
this.originator = id.substring(yacyCore.universalDateShortPattern.length());
|
||||||
private void removeStandards() {
|
removeStandards();
|
||||||
attributes.remove("ori");
|
}
|
||||||
attributes.remove("cat");
|
|
||||||
attributes.remove("cre");
|
private void removeStandards() {
|
||||||
attributes.remove("rec");
|
attributes.remove("ori");
|
||||||
attributes.remove("dis");
|
attributes.remove("cat");
|
||||||
}
|
attributes.remove("cre");
|
||||||
|
attributes.remove("rec");
|
||||||
public String toString() {
|
attributes.remove("dis");
|
||||||
// this creates the string that shall be distributed
|
}
|
||||||
// attention: this has no additional encoding
|
|
||||||
if (this.originator != null) attributes.put("ori", this.originator);
|
public String toString() {
|
||||||
if (this.category != null) attributes.put("cat", this.category);
|
// this creates the string that shall be distributed
|
||||||
if (this.created != null) attributes.put("cre", yacyCore.universalDateShortString(this.created));
|
// attention: this has no additional encoding
|
||||||
if (this.received != null) attributes.put("rec", yacyCore.universalDateShortString(this.received));
|
if (this.originator != null) attributes.put("ori", this.originator);
|
||||||
attributes.put("dis", Integer.toString(this.distributed));
|
if (this.category != null) attributes.put("cat", this.category);
|
||||||
String theString = attributes.toString();
|
if (this.created != null) attributes.put("cre", yacyCore.universalDateShortString(this.created));
|
||||||
removeStandards();
|
if (this.received != null) attributes.put("rec", yacyCore.universalDateShortString(this.received));
|
||||||
return theString;
|
attributes.put("dis", Integer.toString(this.distributed));
|
||||||
}
|
String theString = attributes.toString();
|
||||||
|
removeStandards();
|
||||||
public String id() {
|
return theString;
|
||||||
return yacyCore.universalDateShortString(created) + originator;
|
}
|
||||||
}
|
|
||||||
|
public String id() {
|
||||||
public static int idLength() {
|
return yacyCore.universalDateShortString(created) + originator;
|
||||||
return yacyCore.universalDateShortPattern.length() + yacySeedDB.commonHashLength;
|
}
|
||||||
}
|
|
||||||
|
public static int idLength() {
|
||||||
public String originator() {
|
return yacyCore.universalDateShortPattern.length() + yacySeedDB.commonHashLength;
|
||||||
return originator;
|
}
|
||||||
}
|
|
||||||
|
public String originator() {
|
||||||
public Date created() {
|
return originator;
|
||||||
return created;
|
}
|
||||||
}
|
|
||||||
|
public Date created() {
|
||||||
public Date received() {
|
return created;
|
||||||
return received;
|
}
|
||||||
}
|
|
||||||
|
public Date received() {
|
||||||
public String category() {
|
return received;
|
||||||
return category;
|
}
|
||||||
}
|
|
||||||
|
public String category() {
|
||||||
public int distributed() {
|
return category;
|
||||||
return distributed;
|
}
|
||||||
}
|
|
||||||
|
public int distributed() {
|
||||||
public void incDistribution() {
|
return distributed;
|
||||||
distributed++;
|
}
|
||||||
}
|
|
||||||
|
public void incDistribution() {
|
||||||
public Map attributes() {
|
distributed++;
|
||||||
return attributes;
|
}
|
||||||
}
|
|
||||||
|
public Map attributes() {
|
||||||
public static void main(String[] args) {
|
return attributes;
|
||||||
System.out.println((new yacyNewsRecord(args[0])).toString());
|
}
|
||||||
}
|
|
||||||
}
|
public static void main(String[] args) {
|
||||||
|
System.out.println((new yacyNewsRecord(args[0])).toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue