Java Doc for RMICacheManagerPeerListener.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 Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.sf.ehcache.distribution.RMICacheManagerPeerListener

RMICacheManagerPeerListener
public class RMICacheManagerPeerListener implements CacheManagerPeerListener(Code)
A cache server which exposes available cache operations remotely through RMI.

It acts as a Decorator to a Cache. It holds an instance of cache, which is a local cache it talks to.

This class could specify a security manager with code like:

 if (System.getSecurityManager() == null) {
 System.setSecurityManager(new RMISecurityManager());
 }
 
Doing so would require the addition of grant statements in the java.policy file.

Per the JDK documentation: "If no security manager is specified no class loading, by RMI clients or servers, is allowed, aside from what can be found in the local CLASSPATH." The classpath of each instance of this class should have all required classes to enable distribution, so no remote classloading is required or desirable. Accordingly, no security manager is set and there are no special JVM configuration requirements.

This class opens a ServerSocket. The dispose method should be called for orderly closure of that socket. This class has a shutdown hook which calls dispose() as a convenience feature for developers.
author:
   Greg Luck
version:
   $Id: RMICacheManagerPeerListener.java 519 2007-07-27 07:11:45Z gregluck $



Field Summary
final protected  MapcachePeers
     The cache peers.
protected  Integerport
    
protected  Statusstatus
     status.

Constructor Summary
public  RMICacheManagerPeerListener(String hostName, Integer port, CacheManager cacheManager, Integer socketTimeoutMillis)
     Constructor with full arguments.
Parameters:
  hostName - may be null, in which case the hostName will be looked up.

Method Summary
 voidaddCachePeer(String name, RMICachePeer peer)
    
protected  voidassignFreePort(boolean forced)
     Assigns a free port to be the listener port.
public  voidattemptResolutionOfUniqueResourceConflict()
     If a conflict is detected in unique resource use, this method signals the listener to attempt automatic resolution of the resource conflict.
protected  voidbind(String peerName, RMICachePeer rmiCachePeer)
    
protected  StringcalculateHostAddress()
    
public  voiddispose()
     Stop the listener.
protected  voiddisposeRMICachePeer(RMICachePeer rmiCachePeer)
     A template method to dispose an individual RMICachePeer.
public  ListgetBoundCachePeers()
     All of the caches which are listening for remote changes. a list of RMICachePeer objects.
protected  intgetFreePort()
     Gets a free server socket port.
public  StatusgetStatus()
     Returns the listener status.
public  StringgetUniqueResourceIdentifier()
     A listener will normally have a resource that only one instance can use at the same time, such as a port.
public  voidinit()
    
protected  booleanisDistributed(Ehcache cache)
     Determine if the given cache is distributed.
protected  String[]listBoundRMICachePeers()
     Returns a list of bound objects.

This should match the list of cachePeers i.e.

protected  RemotelookupPeer(String name)
     Returns a reference to the remote object.
Parameters:
  name - the name of the cache e.g.
public  voidnotifyCacheAdded(String cacheName)
     Called immediately after a cache has been added and activated.

Note that the CacheManager calls this method from a synchronized method.

public  voidnotifyCacheRemoved(String cacheName)
     Called immediately after a cache has been disposed and removed.
protected  voidpopulateListOfRemoteCachePeers()
     Should be called on init because this is one of the last things that should happen on CacheManager startup.
protected  voidstartRegistry()
     Start the rmiregistry.
protected  voidstopRegistry()
     Stop the rmiregistry if it was started by this class.
protected  voidunbind(RMICachePeer rmiCachePeer)
     Unbinds an RMICachePeer and unexports it.

Field Detail
cachePeers
final protected Map cachePeers(Code)
The cache peers. The value is an RMICachePeer.



port
protected Integer port(Code)
The RMI listener port



status
protected Status status(Code)
status.




Constructor Detail
RMICacheManagerPeerListener
public RMICacheManagerPeerListener(String hostName, Integer port, CacheManager cacheManager, Integer socketTimeoutMillis) throws UnknownHostException(Code)
Constructor with full arguments.
Parameters:
  hostName - may be null, in which case the hostName will be looked up. Machines with multipleinterfaces should specify this if they do not want it to be the default NIC.
Parameters:
  port - a port in the range 1025 - 65536
Parameters:
  cacheManager - the CacheManager this listener belongs to
Parameters:
  socketTimeoutMillis - TCP/IP Socket timeout when waiting on response




Method Detail
addCachePeer
void addCachePeer(String name, RMICachePeer peer)(Code)
Package local method for testing



assignFreePort
protected void assignFreePort(boolean forced) throws IllegalStateException(Code)
Assigns a free port to be the listener port.
throws:
  IllegalStateException - if the statis of the listener is not net.sf.ehcache.Status.STATUS_UNINITIALISED



attemptResolutionOfUniqueResourceConflict
public void attemptResolutionOfUniqueResourceConflict() throws IllegalStateException, CacheException(Code)
If a conflict is detected in unique resource use, this method signals the listener to attempt automatic resolution of the resource conflict.
throws:
  IllegalStateException - if the statis of the listener is not net.sf.ehcache.Status.STATUS_UNINITIALISED



bind
protected void bind(String peerName, RMICachePeer rmiCachePeer) throws Exception(Code)
Bind a cache peer
Parameters:
  rmiCachePeer -



calculateHostAddress
protected String calculateHostAddress() throws UnknownHostException(Code)
Calculates the host address as the default NICs IP address
throws:
  UnknownHostException -



dispose
public void dispose() throws CacheException(Code)
Stop the listener. It
  • unbinds the objects from the registry
  • unexports Remote objects



disposeRMICachePeer
protected void disposeRMICachePeer(RMICachePeer rmiCachePeer) throws Exception(Code)
A template method to dispose an individual RMICachePeer. This consists of:
  1. Unbinding the peer from the naming service
  2. Unexporting the peer
Override to specialise behaviour
Parameters:
  rmiCachePeer - the cache peer to dispose of
throws:
  Exception - thrown if something goes wrong



getBoundCachePeers
public List getBoundCachePeers()(Code)
All of the caches which are listening for remote changes. a list of RMICachePeer objects. The list if not live



getFreePort
protected int getFreePort() throws IllegalArgumentException(Code)
Gets a free server socket port. a number in the range 1025 - 65536 that was free at the time this method was executed
throws:
  IllegalArgumentException -



getStatus
public Status getStatus()(Code)
Returns the listener status.



getUniqueResourceIdentifier
public String getUniqueResourceIdentifier()(Code)
A listener will normally have a resource that only one instance can use at the same time, such as a port. This identifier is used to tell if it is unique and will not conflict with an existing instance using the resource. a String identifier for the resource



init
public void init() throws CacheException(Code)



isDistributed
protected boolean isDistributed(Ehcache cache)(Code)
Determine if the given cache is distributed.
Parameters:
  cache - the cache to check true if a CacheReplicator is found in the listeners



listBoundRMICachePeers
protected String[] listBoundRMICachePeers() throws CacheException(Code)
Returns a list of bound objects.

This should match the list of cachePeers i.e. they should always be bound a list of String representations of RMICachePeer objects




lookupPeer
protected Remote lookupPeer(String name) throws CacheException(Code)
Returns a reference to the remote object.
Parameters:
  name - the name of the cache e.g. sampleCache1



notifyCacheAdded
public void notifyCacheAdded(String cacheName) throws CacheException(Code)
Called immediately after a cache has been added and activated.

Note that the CacheManager calls this method from a synchronized method. Any attempt to call a synchronized method on CacheManager from this method will cause a deadlock.

Note that activation will also cause a CacheEventListener status change notification from net.sf.ehcache.Status.STATUS_UNINITIALISED to net.sf.ehcache.Status.STATUS_ALIVE . Care should be taken on processing that notification because:

  • the cache will not yet be accessible from the CacheManager.
  • the addCaches methods whih cause this notification are synchronized on the CacheManager. An attempt to call net.sf.ehcache.CacheManager.getCache(String) will cause a deadlock.
The calling method will block until this method returns.

Repopulates the list of cache peers and rebinds the list. This method should be called if a cache is dynamically added
Parameters:
  cacheName - the name of the Cache the operation relates to
See Also:   net.sf.ehcache.event.CacheEventListener




notifyCacheRemoved
public void notifyCacheRemoved(String cacheName)(Code)
Called immediately after a cache has been disposed and removed. The calling method will block until this method returns.

Note that the CacheManager calls this method from a synchronized method. Any attempt to call a synchronized method on CacheManager from this method will cause a deadlock.

Note that a net.sf.ehcache.event.CacheEventListener status changed will also be triggered. Any attempt from that notification to access CacheManager will also result in a deadlock.
Parameters:
  cacheName - the name of the Cache the operation relates to




populateListOfRemoteCachePeers
protected void populateListOfRemoteCachePeers() throws RemoteException(Code)
Should be called on init because this is one of the last things that should happen on CacheManager startup.



startRegistry
protected void startRegistry() throws RemoteException(Code)
Start the rmiregistry.

The alternative is to use the rmiregistry binary, in which case:

  1. rmiregistry running
  2. -Djava.rmi.server.codebase="file:///Users/gluck/work/ehcache/build/classes/ file:///Users/gluck/work/ehcache/lib/commons-logging-1.0.4.jar"

throws:
  RemoteException -



stopRegistry
protected void stopRegistry() throws RemoteException(Code)
Stop the rmiregistry if it was started by this class.
throws:
  RemoteException -



unbind
protected void unbind(RMICachePeer rmiCachePeer) throws Exception(Code)
Unbinds an RMICachePeer and unexports it.

We unbind from the registry first before unexporting. Unbinding first removes the very small possibility of a client getting the object from the registry while we are trying to unexport it.

This method may take up to 4 seconds to complete, if we are having trouble unexporting the peer.
Parameters:
  rmiCachePeer - the bound and exported cache peer
throws:
  Exception -




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.