Source Code Cross Referenced for dbImportManager.java in  » Search-Engine » yacy » de » anomic » plasma » dbImport » 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.plasma.dbImport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package de.anomic.plasma.dbImport;
002:
003:        import java.util.Vector;
004:
005:        import de.anomic.plasma.plasmaSwitchboard;
006:        import de.anomic.server.logging.serverLog;
007:
008:        public class dbImportManager {
009:
010:            public final Vector<dbImporter> finishedJobs = new Vector<dbImporter>();
011:            public final ThreadGroup runningJobs = new ThreadGroup(
012:                    "ImporterThreads");
013:            public int currMaxJobNr = 0;
014:            private plasmaSwitchboard sb;
015:
016:            public dbImportManager(plasmaSwitchboard theSb) {
017:                this .sb = theSb;
018:            }
019:
020:            private int generateUniqueJobID() {
021:                int jobID;
022:                synchronized (this .runningJobs) {
023:                    jobID = this .currMaxJobNr;
024:                    this .currMaxJobNr++;
025:                }
026:                return jobID;
027:            }
028:
029:            public dbImporter[] getRunningImporter() {
030:                Thread[] importThreads = new Thread[this .runningJobs
031:                        .activeCount() * 2];
032:                int activeCount = this .runningJobs.enumerate(importThreads);
033:                dbImporter[] importers = new dbImporter[activeCount];
034:                for (int i = 0; i < activeCount; i++) {
035:                    importers[i] = (dbImporter) importThreads[i];
036:                }
037:                return importers;
038:            }
039:
040:            public dbImporter[] getFinishedImporter() {
041:                return (dbImporter[]) this .finishedJobs
042:                        .toArray(new dbImporter[this .finishedJobs.size()]);
043:            }
044:
045:            public dbImporter getImporterByID(int jobID) {
046:
047:                Thread[] importThreads = new Thread[this .runningJobs
048:                        .activeCount() * 2];
049:                int activeCount = this .runningJobs.enumerate(importThreads);
050:
051:                for (int i = 0; i < activeCount; i++) {
052:                    dbImporter currThread = (dbImporter) importThreads[i];
053:                    if (currThread.getJobID() == jobID) {
054:                        return currThread;
055:                    }
056:                }
057:                return null;
058:            }
059:
060:            public dbImporter getNewImporter(String type) {
061:                if (type == null)
062:                    return null;
063:                if (type.length() == 0)
064:                    return null;
065:
066:                // create a new importer thread
067:                dbImporter newImporter = null;
068:                if (type.equalsIgnoreCase("NURL")) {
069:                    newImporter = new plasmaCrawlNURLImporter(this .sb);
070:                } else if (type.equalsIgnoreCase("sitemap")) {
071:                    newImporter = new SitemapImporter(this .sb);
072:                }
073:
074:                // assign a job ID to it
075:                newImporter.setJobID(this .generateUniqueJobID());
076:
077:                // return the newly created importer
078:                return newImporter;
079:            }
080:
081:            /**
082:             * Can be used to close all still running importer threads
083:             * e.g. on server shutdown
084:             */
085:            public void close() {
086:                /* clear the finished thread list */
087:                this .finishedJobs.clear();
088:
089:                /* waiting for all threads to finish */
090:                int threadCount = this .runningJobs.activeCount();
091:                Thread[] threadList = new Thread[threadCount];
092:                threadCount = this .runningJobs.enumerate(threadList);
093:
094:                if (threadCount == 0)
095:                    return;
096:
097:                serverLog log = new serverLog("DB-IMPORT");
098:                try {
099:                    // trying to gracefull stop all still running sessions ...
100:                    log.logInfo("Signaling shutdown to " + threadCount
101:                            + " remaining dbImporter threads ...");
102:                    for (int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++) {
103:                        Thread currentThread = threadList[currentThreadIdx];
104:                        if (currentThread.isAlive()) {
105:                            ((dbImporter) currentThread).stopIt();
106:                        }
107:                    }
108:
109:                    // waiting a few ms for the session objects to continue processing
110:                    try {
111:                        Thread.sleep(500);
112:                    } catch (InterruptedException ex) {
113:                    }
114:
115:                    // interrupting all still running or pooled threads ...
116:                    log.logInfo("Sending interruption signal to "
117:                            + runningJobs.activeCount()
118:                            + " remaining dbImporter threads ...");
119:                    runningJobs.interrupt();
120:
121:                    // we need to use a timeout here because of missing interruptable session threads ...
122:                    log
123:                            .logFine("Waiting for "
124:                                    + runningJobs.activeCount()
125:                                    + " remaining dbImporter threads to finish shutdown ...");
126:                    for (int currentThreadIdx = 0; currentThreadIdx < threadCount; currentThreadIdx++) {
127:                        Thread currentThread = threadList[currentThreadIdx];
128:                        if (currentThread.isAlive()) {
129:                            log.logFine("Waiting for dbImporter thread '"
130:                                    + currentThread.getName() + "' ["
131:                                    + currentThreadIdx
132:                                    + "] to finish shutdown.");
133:                            try {
134:                                currentThread.join(500);
135:                            } catch (InterruptedException ex) {
136:                            }
137:                        }
138:                    }
139:
140:                    log
141:                            .logInfo("Shutdown of remaining dbImporter threads finished.");
142:                } catch (Exception e) {
143:                    log
144:                            .logSevere(
145:                                    "Unexpected error while trying to shutdown all remaining dbImporter threads.",
146:                                    e);
147:                }
148:            }
149:
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.