Source Code Cross Referenced for ManualRMICacheManagerPeerProvider.java in  » Cache » ehcache » net » sf » ehcache » distribution » 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 » Cache » ehcache » net.sf.ehcache.distribution 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Copyright 2003-2007 Luck Consulting Pty Ltd
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not 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.
015:         */package net.sf.ehcache.distribution;
016:
017:        import net.sf.ehcache.CacheException;
018:        import net.sf.ehcache.Ehcache;
019:        import org.apache.commons.logging.Log;
020:        import org.apache.commons.logging.LogFactory;
021:
022:        import java.util.ArrayList;
023:        import java.util.Date;
024:        import java.util.Iterator;
025:        import java.util.List;
026:
027:        /**
028:         * A provider of Peer RMI addresses based off manual configuration.
029:         * <p/>
030:         * Because there is no monitoring of whether a peer is actually there, the list of peers is dynamically
031:         * looked up and verified each time a lookup request is made.
032:         * <p/>
033:         *
034:         * @author Greg Luck
035:         * @version $Id: ManualRMICacheManagerPeerProvider.java 552 2007-08-26 04:20:49Z gregluck $
036:         */
037:        public final class ManualRMICacheManagerPeerProvider extends
038:                RMICacheManagerPeerProvider {
039:
040:            private static final Log LOG = LogFactory
041:                    .getLog(ManualRMICacheManagerPeerProvider.class.getName());
042:
043:            /**
044:             * Empty constructor.
045:             */
046:            public ManualRMICacheManagerPeerProvider() {
047:                super ();
048:            }
049:
050:            /**
051:             * {@inheritDoc}
052:             */
053:            public final void init() {
054:                //nothing to do here
055:            }
056:
057:            /**
058:             * Time for a cluster to form. This varies considerably, depending on the implementation.
059:             *
060:             * @return the time in ms, for a cluster to form
061:             */
062:            public long getTimeForClusterToForm() {
063:                return 0;
064:            }
065:
066:            /**
067:             * Register a new peer.
068:             *
069:             * @param rmiUrl
070:             */
071:            public final synchronized void registerPeer(String rmiUrl) {
072:                peerUrls.put(rmiUrl, new Date());
073:            }
074:
075:            /**
076:             * @return a list of {@link CachePeer} peers, excluding the local peer.
077:             */
078:            public final synchronized List listRemoteCachePeers(Ehcache cache)
079:                    throws CacheException {
080:                List remoteCachePeers = new ArrayList();
081:                List staleList = new ArrayList();
082:                for (Iterator iterator = peerUrls.keySet().iterator(); iterator
083:                        .hasNext();) {
084:                    String rmiUrl = (String) iterator.next();
085:                    String rmiUrlCacheName = extractCacheName(rmiUrl);
086:
087:                    if (!rmiUrlCacheName.equals(cache.getName())) {
088:                        continue;
089:                    }
090:                    Date date = (Date) peerUrls.get(rmiUrl);
091:                    if (!stale(date)) {
092:                        CachePeer cachePeer = null;
093:                        try {
094:                            cachePeer = lookupRemoteCachePeer(rmiUrl);
095:                            remoteCachePeers.add(cachePeer);
096:                        } catch (Exception e) {
097:                            if (LOG.isDebugEnabled()) {
098:                                LOG
099:                                        .debug(
100:                                                "Looking up rmiUrl "
101:                                                        + rmiUrl
102:                                                        + " through exception "
103:                                                        + e.getMessage()
104:                                                        + ". This may be normal if a node has gone offline. Or it may indicate network connectivity"
105:                                                        + " difficulties", e);
106:                            }
107:                        }
108:                    } else {
109:                        if (LOG.isDebugEnabled()) {
110:                            LOG
111:                                    .debug("rmiUrl "
112:                                            + rmiUrl
113:                                            + " should never be stale for a manually configured cluster.");
114:                        }
115:                        staleList.add(rmiUrl);
116:                    }
117:
118:                }
119:
120:                //Remove any stale remote peers. Must be done here to avoid concurrent modification exception.
121:                for (int i = 0; i < staleList.size(); i++) {
122:                    String rmiUrl = (String) staleList.get(i);
123:                    peerUrls.remove(rmiUrl);
124:                }
125:                return remoteCachePeers;
126:            }
127:
128:            /**
129:             * Whether the entry should be considered stale.
130:             * <p/>
131:             * Manual RMICacheManagerProviders use a static list of urls and are therefore never stale.
132:             *
133:             * @param date the date the entry was created
134:             * @return true if stale
135:             */
136:            protected final boolean stale(Date date) {
137:                return false;
138:            }
139:
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.