Source Code Cross Referenced for TechnoratiRankingsTask.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » planet » tasks » 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 » Blogger System » apache roller 3.1 » org.apache.roller.planet.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  The ASF licenses this file to You
004:         * under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.  For additional information regarding
015:         * copyright in this work, please see the NOTICE file in the top level
016:         * directory of this distribution.
017:         */
018:
019:        package org.apache.roller.planet.tasks;
020:
021:        import java.io.IOException;
022:        import java.util.Calendar;
023:        import java.util.Date;
024:        import java.util.Iterator;
025:        import java.util.Properties;
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:        import org.apache.roller.RollerException;
029:        import org.apache.roller.business.runnable.RollerTask;
030:        import org.apache.roller.config.RollerConfig;
031:        import org.apache.roller.planet.business.PlanetManager;
032:        import org.apache.roller.business.RollerFactory;
033:        import org.apache.roller.business.UserManager;
034:        import org.apache.roller.planet.pojos.PlanetConfigData;
035:        import org.apache.roller.planet.pojos.PlanetSubscriptionData;
036:        import org.apache.roller.util.Technorati;
037:
038:        /**
039:         * Rank each subscription by populating Technorati inbound blog and link counts.
040:         */
041:        public class TechnoratiRankingsTask extends RollerTask {
042:
043:            private static Log log = LogFactory
044:                    .getLog(TechnoratiRankingsTask.class);
045:
046:            // a String description of when to start this task
047:            private String startTimeDesc = "startOfDay";
048:
049:            // interval at which the task is run, default is 5 minutes
050:            private int interval = 1440;
051:
052:            // lease time given to task lock, default is 30 minutes
053:            private int leaseTime = 30;
054:
055:            public String getName() {
056:                return "TechnoratiRankingsTask";
057:            }
058:
059:            public Date getStartTime(Date currentTime) {
060:                return getAdjustedTime(currentTime, startTimeDesc);
061:            }
062:
063:            public int getInterval() {
064:                return this .interval;
065:            }
066:
067:            public int getLeaseTime() {
068:                return this .leaseTime;
069:            }
070:
071:            public void init() throws RollerException {
072:
073:                // get relevant props
074:                Properties props = this .getTaskProperties();
075:
076:                // extract start time
077:                String startTimeStr = props.getProperty("startTime");
078:                if (startTimeStr != null) {
079:                    this .startTimeDesc = startTimeStr;
080:                }
081:
082:                // extract interval
083:                String intervalStr = props.getProperty("interval");
084:                if (intervalStr != null) {
085:                    try {
086:                        this .interval = Integer.parseInt(intervalStr);
087:                    } catch (NumberFormatException ex) {
088:                        log.warn("Invalid interval: " + intervalStr);
089:                    }
090:                }
091:
092:                // extract lease time
093:                String leaseTimeStr = props.getProperty("leaseTime");
094:                if (leaseTimeStr != null) {
095:                    try {
096:                        this .leaseTime = Integer.parseInt(leaseTimeStr);
097:                    } catch (NumberFormatException ex) {
098:                        log.warn("Invalid leaseTime: " + leaseTimeStr);
099:                    }
100:                }
101:            }
102:
103:            /**
104:             * Loop through all subscriptions get get Technorati rankings for each
105:             */
106:            public void runTask() {
107:
108:                int count = 0;
109:                int errorCount = 0;
110:                try {
111:                    PlanetManager planet = RollerFactory.getRoller()
112:                            .getPlanetManager();
113:                    PlanetConfigData config = planet.getConfiguration();
114:                    Technorati technorati = null;
115:                    try {
116:                        if (config.getProxyHost() != null
117:                                && config.getProxyPort() != -1) {
118:                            technorati = new Technorati(config.getProxyHost(),
119:                                    config.getProxyPort());
120:                        } else {
121:                            technorati = new Technorati();
122:                        }
123:                    } catch (IOException e) {
124:                        log
125:                                .error("Aborting collection of Technorati rankings.\n"
126:                                        + "technorati.license not found at root of classpath.\n"
127:                                        + "Get license at http://technorati.com/developers/apikey.html\n"
128:                                        + "Put the license string in a file called technorati.license.\n"
129:                                        + "And place that file at the root of Roller's classpath.\n"
130:                                        + "For example, in the /WEB-INF/classes directory.");
131:                        return;
132:                    }
133:
134:                    UserManager userManager = RollerFactory.getRoller()
135:                            .getUserManager();
136:                    try {
137:                        int limit = RollerConfig.getIntProperty(
138:                                "planet.aggregator.technorati.limit", 500);
139:                        int userCount = planet.getSubscriptionCount();
140:                        int mod = (userCount / limit) + 1;
141:
142:                        Calendar cal = Calendar.getInstance();
143:                        cal.setTime(new Date());
144:                        int day = cal.get(Calendar.DAY_OF_YEAR);
145:
146:                        int start = (day % mod) * limit;
147:                        int end = start + limit;
148:                        end = end > userCount ? userCount : end;
149:                        log.info("Updating subscriptions [" + start + ":" + end
150:                                + "]");
151:
152:                        Iterator subs = planet.getAllSubscriptions();
153:                        while (subs.hasNext()) {
154:                            PlanetSubscriptionData sub = (PlanetSubscriptionData) subs
155:                                    .next();
156:                            if (count >= start && count < end) {
157:                                try {
158:                                    Technorati.Result result = technorati
159:                                            .getBloginfo(sub.getSiteURL());
160:                                    if (result != null
161:                                            && result.getWeblog() != null) {
162:                                        sub.setInboundblogs(result.getWeblog()
163:                                                .getInboundblogs());
164:                                        sub.setInboundlinks(result.getWeblog()
165:                                                .getInboundlinks());
166:                                        log.debug("Adding rank for "
167:                                                + sub.getFeedURL() + " ["
168:                                                + count + "|"
169:                                                + sub.getInboundblogs() + "|"
170:                                                + sub.getInboundlinks() + "]");
171:                                    } else {
172:                                        log.debug("No ranking available for "
173:                                                + sub.getFeedURL() + " ["
174:                                                + count + "]");
175:                                        sub.setInboundlinks(0);
176:                                        sub.setInboundblogs(0);
177:                                    }
178:                                    planet.saveSubscription(sub);
179:                                } catch (Exception e) {
180:                                    log.warn("WARN ranking subscription ["
181:                                            + count + "]: " + e.getMessage());
182:                                    if (errorCount++ > 5) {
183:                                        log
184:                                                .warn("   Stopping ranking, too many errors");
185:                                        break;
186:                                    }
187:                                }
188:                            }
189:                            count++;
190:                        }
191:
192:                        // all done, flush results to db
193:                        RollerFactory.getRoller().flush();
194:
195:                    } finally {
196:                        RollerFactory.getRoller().release();
197:                    }
198:
199:                } catch (Exception e) {
200:                    log.error("ERROR ranking subscriptions", e);
201:                }
202:            }
203:
204:            /** 
205:             * Task may be run from the command line 
206:             */
207:            public static void main(String[] args) {
208:                try {
209:                    TechnoratiRankingsTask task = new TechnoratiRankingsTask();
210:                    task.init();
211:                    task.run();
212:                    System.exit(0);
213:                } catch (Throwable t) {
214:                    t.printStackTrace();
215:                    System.exit(-1);
216:                }
217:            }
218:
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.