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


001:        // serverProfiling.java
002:        // (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
003:        // first published 17.11.2007 on http://yacy.net
004:        //
005:        // This is a part of YaCy, a peer-to-peer based web search engine
006:        //
007:        // $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
008:        // $LastChangedRevision: 1986 $
009:        // $LastChangedBy: orbiter $
010:        //
011:        // LICENSE
012:        //
013:        // This program is free software; you can redistribute it and/or modify
014:        // it under the terms of the GNU General Public License as published by
015:        // the Free Software Foundation; either version 2 of the License, or
016:        // (at your option) any later version.
017:        //
018:        // This program is distributed in the hope that it will be useful,
019:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
020:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021:        // GNU General Public License for more details.
022:        //
023:        // You should have received a copy of the GNU General Public License
024:        // along with this program; if not, write to the Free Software
025:        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026:
027:        package de.anomic.server;
028:
029:        import java.util.Collections;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:        import java.util.Map;
033:        import java.util.TreeMap;
034:
035:        public class serverProfiling extends Thread {
036:
037:            private static Map<String, TreeMap<Long, Event>> historyMaps; // key=name of history, value=TreeMap of Long/Event
038:            private static Map<String, Integer> eventCounter; // key=name of history, value=Integer of event counter
039:            private static long lastCompleteCleanup;
040:            private static serverProfiling systemProfiler;
041:
042:            static {
043:                // initialize profiling
044:                historyMaps = Collections
045:                        .synchronizedMap(new HashMap<String, TreeMap<Long, Event>>());
046:                eventCounter = Collections
047:                        .synchronizedMap(new HashMap<String, Integer>());
048:                lastCompleteCleanup = System.currentTimeMillis();
049:                systemProfiler = null;
050:            }
051:
052:            public static void startSystemProfiling() {
053:                systemProfiler = new serverProfiling(1000);
054:                systemProfiler.start();
055:            }
056:
057:            public static void stopSystemProfiling() {
058:                systemProfiler.running = false;
059:            }
060:
061:            private long delaytime;
062:            private boolean running;
063:
064:            public serverProfiling(long time) {
065:                this .delaytime = time;
066:                running = true;
067:            }
068:
069:            public void run() {
070:                while (running) {
071:                    update("memory", new Long(serverMemory.used()));
072:                    try {
073:                        Thread.sleep(this .delaytime);
074:                    } catch (InterruptedException e) {
075:                        this .running = false;
076:                    }
077:                }
078:            }
079:
080:            public static void update(String eventName, Object eventPayload) {
081:                // get event history container
082:                int counter = eventCounter.containsKey(eventName) ? ((Integer) eventCounter
083:                        .get(eventName)).intValue()
084:                        : 0;
085:                TreeMap<Long, Event> history = historyMaps
086:                        .containsKey(eventName) ? (historyMaps.get(eventName))
087:                        : new TreeMap<Long, Event>();
088:
089:                // update entry
090:                Long time = new Long(System.currentTimeMillis());
091:                history.put(time, new Event(counter, eventPayload));
092:                counter++;
093:                eventCounter.put(eventName, new Integer(counter));
094:
095:                // clean up too old entries
096:                cleanup(history);
097:                cleanup();
098:
099:                // store map
100:                historyMaps.put(eventName, history);
101:            }
102:
103:            private static void cleanup() {
104:                if (System.currentTimeMillis() - lastCompleteCleanup < 600000)
105:                    return;
106:                Object[] historyNames = historyMaps.keySet().toArray();
107:                for (int i = 0; i < historyNames.length; i++) {
108:                    cleanup((String) historyNames[i]);
109:                }
110:                lastCompleteCleanup = System.currentTimeMillis();
111:            }
112:
113:            private static void cleanup(String eventName) {
114:                if (historyMaps.containsKey(eventName)) {
115:                    TreeMap<Long, Event> history = historyMaps.get(eventName);
116:                    cleanup(history);
117:                    if (history.size() > 0) {
118:                        historyMaps.put(eventName, history);
119:                    } else {
120:                        historyMaps.remove(eventName);
121:                    }
122:                }
123:            }
124:
125:            private static void cleanup(TreeMap<Long, Event> history) {
126:                // clean up too old entries
127:                while (history.size() > 0) {
128:                    Long time = history.firstKey();
129:                    if (System.currentTimeMillis() - time.longValue() < 600000)
130:                        break;
131:                    history.remove(time);
132:                }
133:
134:            }
135:
136:            public static Iterator<Event> history(String eventName) {
137:                return (historyMaps.containsKey(eventName) ? (historyMaps
138:                        .get(eventName)) : new TreeMap<Long, Event>()).values()
139:                        .iterator();
140:            }
141:
142:            public static class Event {
143:                public int count;
144:                public Object payload;
145:                public long time;
146:
147:                public Event(int count, Object payload) {
148:                    this.count = count;
149:                    this.payload = payload;
150:                    this.time = System.currentTimeMillis();
151:                }
152:            }
153:
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.