Source Code Cross Referenced for yacyNewsQueue.java in  » Search-Engine » yacy » de » anomic » yacy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » yacy » de.anomic.yacy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // yacyNewsQueue.java
002:        // -----------------------
003:        // part of YaCy
004:        // (C) by Michael Peter Christen; mc@anomic.de
005:        // first published on http://www.anomic.de
006:        // Frankfurt, Germany, 2005
007:        //
008:        // $LastChangedDate: 2008-01-23 23:08:32 +0000 (Mi, 23 Jan 2008) $
009:        // $LastChangedRevision: 4382 $
010:        // $LastChangedBy: orbiter $
011:        //
012:        // This program is free software; you can redistribute it and/or modify
013:        // it under the terms of the GNU General Public License as published by
014:        // the Free Software Foundation; either version 2 of the License, or
015:        // (at your option) any later version.
016:        //
017:        // This program is distributed in the hope that it will be useful,
018:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
019:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020:        // GNU General Public License for more details.
021:        //
022:        // You should have received a copy of the GNU General Public License
023:        // along with this program; if not, write to the Free Software
024:        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
025:        //
026:        // Using this software in any meaning (reading, learning, copying, compiling,
027:        // running) means that you agree that the Author(s) is (are) not responsible
028:        // for cost, loss of data or any harm that may be caused directly or indirectly
029:        // by usage of this softare or this documentation. The usage of this software
030:        // is on your own risk. The installation and usage (starting/running) of this
031:        // software may allow other people or application to access your computer and
032:        // any attached devices and is highly dependent on the configuration of the
033:        // software which must be done by the user of the software; the author(s) is
034:        // (are) also not responsible for proper configuration and usage of the
035:        // software, even if provoked by documentation provided together with
036:        // the software.
037:        //
038:        // Any changes to this file according to the GPL as documented in the file
039:        // gpl.txt aside this file in the shipment you received can be done to the
040:        // lines that follows this copyright notice here, but changes must not be
041:        // done inside the copyright notice above. A re-distribution must contain
042:        // the intact and unchanged copyright notice.
043:        // Contributions and changes to the program code must be marked as such.
044:
045:        package de.anomic.yacy;
046:
047:        import java.io.File;
048:        import java.io.IOException;
049:        import java.util.Date;
050:        import java.util.Iterator;
051:
052:        import de.anomic.kelondro.kelondroColumn;
053:        import de.anomic.kelondro.kelondroNaturalOrder;
054:        import de.anomic.kelondro.kelondroRow;
055:        import de.anomic.kelondro.kelondroStack;
056:        import de.anomic.server.serverDate;
057:
058:        public class yacyNewsQueue {
059:
060:            private File path;
061:            private kelondroStack queueStack;
062:            private yacyNewsDB newsDB;
063:
064:            public static final kelondroRow rowdef = new kelondroRow(
065:                    new kelondroColumn[] {
066:                            new kelondroColumn("newsid",
067:                                    kelondroColumn.celltype_string,
068:                                    kelondroColumn.encoder_bytes,
069:                                    yacyNewsRecord.idLength,
070:                                    "id = created + originator"),
071:                            new kelondroColumn("last touched",
072:                                    kelondroColumn.celltype_string,
073:                                    kelondroColumn.encoder_bytes,
074:                                    serverDate.PATTERN_SHORT_SECOND.length(),
075:                                    "") }, kelondroNaturalOrder.naturalOrder, 0);
076:
077:            public yacyNewsQueue(File path, yacyNewsDB newsDB) {
078:                this .path = path;
079:                this .newsDB = newsDB;
080:                this .queueStack = kelondroStack.open(path, rowdef);
081:            }
082:
083:            private void resetDB() {
084:                try {
085:                    close();
086:                } catch (Exception e) {
087:                }
088:                if (path.exists())
089:                    path.delete();
090:                queueStack = kelondroStack.open(path, rowdef);
091:            }
092:
093:            public void clear() {
094:                resetDB();
095:            }
096:
097:            public void close() {
098:                if (queueStack != null)
099:                    queueStack.close();
100:                queueStack = null;
101:            }
102:
103:            public void finalize() {
104:                close();
105:            }
106:
107:            public int size() {
108:                return queueStack.size();
109:            }
110:
111:            public synchronized void push(yacyNewsRecord entry)
112:                    throws IOException {
113:                queueStack.push(r2b(entry, true));
114:            }
115:
116:            public synchronized yacyNewsRecord pop() throws IOException {
117:                if (queueStack.size() == 0)
118:                    return null;
119:                return b2r(queueStack.pop());
120:            }
121:
122:            public synchronized yacyNewsRecord top() throws IOException {
123:                if (queueStack.size() == 0)
124:                    return null;
125:                return b2r(queueStack.top());
126:            }
127:
128:            public synchronized yacyNewsRecord topInc() throws IOException {
129:                if (queueStack.size() == 0)
130:                    return null;
131:                yacyNewsRecord entry = pop();
132:                if (entry != null) {
133:                    entry.incDistribution();
134:                    push(entry);
135:                }
136:                return entry;
137:            }
138:
139:            public synchronized yacyNewsRecord get(String id) {
140:                yacyNewsRecord record;
141:                Iterator<yacyNewsRecord> i = records(true);
142:                while (i.hasNext()) {
143:                    record = i.next();
144:                    if ((record != null) && (record.id().equals(id)))
145:                        return record;
146:                }
147:                return null;
148:            }
149:
150:            public synchronized yacyNewsRecord remove(String id) {
151:                yacyNewsRecord record;
152:                Iterator<yacyNewsRecord> i = records(true);
153:                while (i.hasNext()) {
154:                    record = i.next();
155:                    if ((record != null) && (record.id().equals(id))) {
156:                        i.remove();
157:                        return record;
158:                    }
159:                }
160:                return null;
161:            }
162:
163:            private yacyNewsRecord b2r(kelondroRow.Entry b) throws IOException {
164:                if (b == null)
165:                    return null;
166:                String id = b.getColString(0, null);
167:                //Date touched = yacyCore.parseUniversalDate(new String(b[1]));
168:                return newsDB.get(id);
169:            }
170:
171:            private kelondroRow.Entry r2b(yacyNewsRecord r, boolean updateDB)
172:                    throws IOException {
173:                if (r == null)
174:                    return null;
175:                if (updateDB) {
176:                    newsDB.put(r);
177:                } else {
178:                    yacyNewsRecord r1 = newsDB.get(r.id());
179:                    if (r1 == null)
180:                        newsDB.put(r);
181:                }
182:                kelondroRow.Entry b = queueStack.row().newEntry(
183:                        new byte[][] {
184:                                r.id().getBytes(),
185:                                serverDate.formatShortSecond(new Date())
186:                                        .getBytes() });
187:                return b;
188:            }
189:
190:            public Iterator<yacyNewsRecord> records(boolean up) {
191:                // iterates yacyNewsRecord-type objects
192:                return new newsIterator(up);
193:            }
194:
195:            public class newsIterator implements  Iterator<yacyNewsRecord> {
196:                // iterates yacyNewsRecord-type objects
197:
198:                Iterator<kelondroRow.Entry> stackNodeIterator;
199:
200:                public newsIterator(boolean up) {
201:                    stackNodeIterator = queueStack.stackIterator(up);
202:                }
203:
204:                public boolean hasNext() {
205:                    return stackNodeIterator.hasNext();
206:                }
207:
208:                public yacyNewsRecord next() {
209:                    kelondroRow.Entry row = (kelondroRow.Entry) stackNodeIterator
210:                            .next();
211:                    try {
212:                        return b2r(row);
213:                    } catch (IOException e) {
214:                        return null;
215:                    }
216:                }
217:
218:                public void remove() {
219:                    stackNodeIterator.remove();
220:                }
221:
222:            }
223:
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.