01: // yacyNewsAction.java
02: // -----------------------
03: // part of YaCy
04: // (C) by Michael Peter Christen; mc@anomic.de
05: // first published on http://www.anomic.de
06: // Frankfurt, Germany, 2005
07: //
08: // $LastChangedDate: 2007-07-13 11:41:55 +0200 (Fr, 13 Jul 2007) $
09: // $LastChangedRevision: 3960 $
10: // $LastChangedBy: orbiter $
11: //
12: // This program is free software; you can redistribute it and/or modify
13: // it under the terms of the GNU General Public License as published by
14: // the Free Software Foundation; either version 2 of the License, or
15: // (at your option) any later version.
16: //
17: // This program is distributed in the hope that it will be useful,
18: // but WITHOUT ANY WARRANTY; without even the implied warranty of
19: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20: // GNU General Public License for more details.
21: //
22: // You should have received a copy of the GNU General Public License
23: // along with this program; if not, write to the Free Software
24: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25: //
26: // Using this software in any meaning (reading, learning, copying, compiling,
27: // running) means that you agree that the Author(s) is (are) not responsible
28: // for cost, loss of data or any harm that may be caused directly or indirectly
29: // by usage of this softare or this documentation. The usage of this software
30: // is on your own risk. The installation and usage (starting/running) of this
31: // software may allow other people or application to access your computer and
32: // any attached devices and is highly dependent on the configuration of the
33: // software which must be done by the user of the software; the author(s) is
34: // (are) also not responsible for proper configuration and usage of the
35: // software, even if provoked by documentation provided together with
36: // the software.
37: //
38: // Any changes to this file according to the GPL as documented in the file
39: // gpl.txt aside this file in the shipment you received can be done to the
40: // lines that follows this copyright notice here, but changes must not be
41: // done inside the copyright notice above. A re-distribution must contain
42: // the intact and unchanged copyright notice.
43: // Contributions and changes to the program code must be marked as such.
44:
45: package de.anomic.yacy;
46:
47: import java.io.IOException;
48:
49: import de.anomic.server.serverCodings;
50: import de.anomic.server.logging.serverLog;
51:
52: public class yacyNewsAction implements yacyPeerAction {
53:
54: yacyNewsPool pool;
55:
56: public yacyNewsAction(yacyNewsPool pool) {
57: this .pool = pool;
58: }
59:
60: public void processPeerArrival(yacySeed peer, boolean direct) {
61: String recordString = peer.get("news", null);
62: //System.out.println("### triggered news arrival from peer " + peer.getName() + ", news " + ((recordString == null) ? "empty" : "attached"));
63: if ((recordString == null) || (recordString.length() == 0))
64: return;
65: String decodedString = de.anomic.tools.crypt.simpleDecode(
66: recordString, "");
67: yacyNewsRecord record = yacyNewsRecord.newRecord(decodedString);
68: if (record != null) {
69: //System.out.println("### news arrival from peer " + peer.getName() + ", decoded=" + decodedString + ", record=" + recordString + ", news=" + record.toString());
70: String cre1 = (String) serverCodings.string2map(
71: decodedString, ",").get("cre");
72: String cre2 = (String) serverCodings.string2map(
73: record.toString(), ",").get("cre");
74: if ((cre1 == null) || (cre2 == null)
75: || (!(cre1.equals(cre2)))) {
76: System.out
77: .println("### ERROR - cre are not equal: cre1="
78: + cre1 + ", cre2=" + cre2);
79: return;
80: }
81: try {
82: synchronized (pool) {
83: this .pool.enqueueIncomingNews(record);
84: }
85: } catch (IOException e) {
86: serverLog.logSevere("YACY", "processPeerArrival", e);
87: }
88: }
89: }
90:
91: public void processPeerDeparture(yacySeed peer) {
92: }
93:
94: public void processPeerPing(yacySeed peer) {
95: processPeerArrival(peer, true);
96: }
97:
98: }
|