Source Code Cross Referenced for ActivityService.java in  » Database-JDBC-Connection-Pool » sequoia-2.10.9 » org » continuent » sequoia » controller » virtualdatabase » activity » 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 » Database JDBC Connection Pool » sequoia 2.10.9 » org.continuent.sequoia.controller.virtualdatabase.activity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Sequoia: Database clustering technology.
003:         * Copyright (C) 2006 Continuent, Inc.
004:         * Contact: sequoia@continuent.org
005:         * 
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License. 
017:         */package org.continuent.sequoia.controller.virtualdatabase.activity;
018:
019:        import java.util.HashMap;
020:        import java.util.Iterator;
021:        import java.util.Map;
022:        import java.util.Map.Entry;
023:
024:        /**
025:         * An ActivityService is responsible to centralize "activities" information related
026:         * to virtual databases
027:         */
028:        public final class ActivityService {
029:            private static final ActivityService instance = new ActivityService();
030:
031:            /*
032:             * vdbs is a Map<String,Map> where:
033:             * - the key is a String representing the name of a virtual database
034:             * - the value is a Map<Object,Boolean> where
035:             *     - the key is an Object representing a vdb member (likely a Member)
036:             *     - the value is a Boolean used to flag if the vdb has had activity since the given
037:             *       member was flagged as unreachable:
038:             *         * TRUE means *some* activity since the member was flagged as unreachable
039:             *         * FALSE means *no* activity since the member was flagged as unreachable
040:             */
041:            private final Map/*<String, Map>*/vdbs = new HashMap();
042:
043:            private ActivityService() {
044:            }
045:
046:            /**
047:             * Returns the instance of the ActivityService.
048:             * This instance is global to the Controller.
049:             * 
050:             * @return the instance of the ActivityService
051:             */
052:            public static final ActivityService getInstance() {
053:                return instance;
054:            }
055:
056:            /**
057:             * Stops the activity service
058:             */
059:            public synchronized void stop() {
060:                vdbs.clear();
061:            }
062:
063:            /**
064:             * Resets the activity information related to the given virtual database.
065:             *
066:             * @param vdb the name of a virtual database
067:             */
068:            public synchronized void reset(String vdb) {
069:                vdbs.remove(vdb);
070:            }
071:
072:            /**
073:             * Notifies that there has been activity related to the given virtual database
074:             * 
075:             * @param vdb the name of the virtual database
076:             */
077:            public void notifyActivityFor(String vdb) {
078:                Map unreachableMembers = (Map) vdbs.get(vdb);
079:                if (unreachableMembers != null) {
080:                    Iterator iter = unreachableMembers.entrySet().iterator();
081:                    while (iter.hasNext()) {
082:                        Entry entry = (Entry) iter.next();
083:                        // This is only writing an object reference, which is guaranteed to be
084:                        // an atomic operation by the JLS (beginning of chapter 17. Threads and
085:                        // locks). No need to synchronize here.
086:                        entry.setValue(Boolean.TRUE);
087:                    }
088:                }
089:            }
090:
091:            /**
092:             * Flags the given member as unreachable for the given virtual database.
093:             * 
094:             * @param vdb the name of a virtual database
095:             * @param member an Object representing the member of a virtual database
096:             */
097:            public synchronized void addUnreachableMember(String vdb,
098:                    Object member) {
099:                Map unreachableMembers = (Map) vdbs.get(vdb);
100:                if (unreachableMembers == null) {
101:                    // 1st unreachable member for the vdb -> lazy creation of the unreachableMembers Map
102:                    unreachableMembers = new HashMap();
103:                    vdbs.put(vdb, unreachableMembers);
104:                }
105:                // set the boolean to false only if the member is not already flagged as unreachable
106:                if (!unreachableMembers.containsKey(member)) {
107:                    unreachableMembers.put(member, Boolean.FALSE);
108:                }
109:            }
110:
111:            /**
112:             * Checks if there has been some activities for the given virtual database 
113:             * since the member was flagged as unreachable.
114:             * 
115:             * @param vdb  the name of a virtual database
116:             * @param member an Object representing the member of a virtual database
117:             * @return <code>true</code> if there has been some activities for the vdb 
118:             *   since the member was flagged as unreachable, <code>false</code> in any
119:             *   other cases
120:             */
121:            public boolean hasActivitySinceUnreachable(String vdb, Object member) {
122:                Map unreachableMembers = (Map) vdbs.get(vdb);
123:                if (unreachableMembers == null) {
124:                    return false;
125:                }
126:                Boolean activity = (Boolean) unreachableMembers.get(member);
127:                if (activity == null) {
128:                    return false;
129:                }
130:                return activity.booleanValue();
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.