Source Code Cross Referenced for RDStore.java in  » Portal » Open-Portal » com » sun » portal » search » autoclassify » 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 » Portal » Open Portal » com.sun.portal.search.autoclassify 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.search.autoclassify;
002:
003:        import java.util.*;
004:        import java.io.*;
005:        import com.sun.portal.search.soif.*;
006:        import com.sun.portal.search.db.Datum;
007:        import com.sleepycat.db.*;
008:
009:        /** <p>Title: RDStore</p>
010:         * <p>Description: Used for storing temporary RDs for modification. The object
011:         * combine a hashtable in memory and Berkeley database for storage. Only when the
012:         * number of RDs exceed given hashtable size, it will only used hashtable for
013:         * performance.</p>
014:         * <p>Copyright: Copyright (c) 2002</p>
015:         * <p>Company: Sun Microsystems</p>
016:         * @author Allen Chiang
017:         * @version 1.0
018:         */
019:
020:        public class RDStore {
021:
022:            HashMap store = new HashMap();
023:            Db table = null;
024:            String dbFileName = null;
025:            private int cacheSize = 10000;
026:
027:            /** Construct a instance with hashtable size and database file path
028:             * @param cacheSize memory hashtable size
029:             * @param dbFilename database file path
030:             * @throws Exception Any cause to create the store.
031:             */
032:            public RDStore(int cacheSize, String dbPath) throws Exception {
033:                this .cacheSize = cacheSize;
034:                dbFileName = dbPath;
035:                table = new Db(null, 0);
036:                table.set_error_stream(System.err);
037:                table.set_errpfx("RDStore:");
038:                table.open(dbFileName, null, Db.DB_BTREE, Db.DB_CREATE
039:                        | Db.DB_TRUNCATE, 0644);
040:
041:            }
042:
043:            /** Perform housekeeping before the object was discarded. Such as delete database
044:             * file.
045:             */
046:            public void close() {
047:                try {
048:                    if (table != null) {
049:                        table.close(0);
050:                    }
051:                    File f = new File(dbFileName);
052:                    f.delete();
053:                } catch (Exception e) {
054:                    //ignore
055:                }
056:            }
057:
058:            /** Getting a RD by its url.
059:             * @param urlStr URL string for the RD
060:             * @return Return the rd by given url string. Return null if the url doesn't exist.
061:             */
062:            synchronized public SOIF getRD(String urlStr) {
063:                Datum key = null;
064:                Datum data = null;
065:
066:                SOIF s = (SOIF) store.get(urlStr);
067:                if (s == null) {
068:                    key = new Datum(urlStr);
069:                    data = new Datum();
070:                    try {
071:                        int rcode = table.get(null, key, data, 0);
072:                        if (rcode == 0) {
073:                            s = new SOIF(data.get_data(), "UTF-8");
074:                            store.put(urlStr, s);
075:                        }
076:                    } catch (Exception e) {
077:                        System.out
078:                                .println("table.get() throws exception with message: "
079:                                        + e.getMessage());
080:                    }
081:                }
082:                return s;
083:            }
084:
085:            private void pushToDB() throws Exception {
086:                Datum key = null;
087:                Datum data = null;
088:                Iterator keyIt = store.keySet().iterator();
089:                while (keyIt.hasNext()) {
090:                    String url = (String) keyIt.next();
091:                    SOIF rd = (SOIF) store.get(url);
092:                    key = new Datum(url);
093:                    data = new Datum(rd.toByteArray());
094:                    table.put(null, key, data, 0);
095:                }
096:                store.clear();
097:            }
098:
099:            /** Putting a rd into store
100:             * @param s A RD in soif object
101:             */
102:            synchronized public void putRD(SOIF s) {
103:                store.put(s.getURL(), s);
104:                if (store.size() > cacheSize) {
105:                    try {
106:                        pushToDB();
107:                    } catch (Exception e) {
108:                        System.out
109:                                .println("Exception throws at pushToDB() with message:"
110:                                        + e.getMessage());
111:                    }
112:                }
113:            }
114:
115:            /** Dumping all RDs into a SOIF format file
116:             * @param fileName The file name for the SOIF file
117:             * @throws Exception Fail to dump the RD.
118:             * @return Number of RDs was dumped. If it is 0, then the SOIF file won't be created.
119:             */
120:            public int CreateSOIF(String fileName) throws Exception {
121:                Iterator keyIt = store.keySet().iterator();
122:                SOIFOutputStream sOut = null;
123:                int rdCount = 0;
124:                while (keyIt.hasNext()) {
125:                    String url = (String) keyIt.next();
126:                    SOIF rd = (SOIF) store.get(url);
127:                    if (sOut == null) {
128:                        sOut = new SOIFOutputStream(fileName);
129:                    }
130:                    sOut.write(rd);
131:                    rdCount++;
132:                }
133:                if (table != null) {
134:                    Dbc cursor = table.cursor(null, 0);
135:                    Datum key = new Datum();
136:                    Datum data = new Datum();
137:
138:                    while (cursor.get(key, data, Db.DB_NEXT) == 0) {
139:                        SOIF rd = new SOIF(data.get_data(), "UTF-8");
140:                        if (store.get(rd.getURL()) == null) {
141:                            if (sOut == null) {
142:                                sOut = new SOIFOutputStream(fileName);
143:                            }
144:                            sOut.write(rd);
145:                            rdCount++;
146:                        }
147:                    }
148:                    ;
149:                }
150:                if (sOut != null) {
151:                    sOut.close();
152:                }
153:                return rdCount;
154:            }
155:
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.