Updates from June, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • Subinkrishna Gopi 4:51 pm on June 23, 2010 Permalink |
    Tags: cache, , distributed cache, ehcache,   

    Distributed Ehcache – RMI replication (configuration) 

    I am having some fun with Ehcache esp. in distributed caching. Distributed caching is really important in a clustered environment. Read more about distributed caching here – http://ehcache.org/documentation/distributed_caching.html.

    I have downloaded Ehcache 2.1 from http://sourceforge.net/projects/ehcache/files/ (ehcache-2.1.0-distribution.tar.gz, 48 mb approx.) which contains Ehcache core and the Terracotta libraries. Once if we have these libraries, we can configure the caches, peers and listeners. I have created a basic cache – MyCache – and my configuration file looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="ehcache.xsd"
             updateCheck="true" monitoring="autodetect"
             dynamicConfig="true" >
    
        <diskStore path="java.io.tmpdir"/>
        <cacheManagerEventListenerFactory class="" properties=""/>
    
        <defaultCache
               maxElementsInMemory="0"
               eternal="false"
               timeToIdleSeconds="1200"
               timeToLiveSeconds="1200">
        </defaultCache>
    
            <!-- For RMI replication (Setting the peer provider factory) -->
    	<cacheManagerPeerProviderFactory
    		class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
    		properties="peerDiscovery=manual, rmiUrls=//remoteHostIpAddress:40000/MyCache"
    		propertySeparator="," />
    
    	<!-- For RMI replication (Setting the peer listener factory) -->
    	<cacheManagerPeerListenerFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
                properties="hostName=localMachineIpAddress, port=40000, socketTimeoutMillis=120000"
                propertySeparator=","/>
    
    	<cache name="MyCache"
    		maxElementsInMemory="1000"
    		eternal="false"
    		overflowToDisk="true"
    		diskSpoolBufferSizeMB="20"
    		timeToLiveSeconds="3000"
    		timeToIdleSeconds="3000"
    		memoryStoreEvictionPolicy="LFU">
    
    		<!-- Cache event listener -->
    		<cacheEventListenerFactory
    			class="subin.cache.listener.factory.CacheEventListenerFactoryImpl"
    			properties="" />
    
    		<!-- RMI replication listener -->
    		<cacheEventListenerFactory
            	class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            	properties="replicateAsynchronously=true,
    		         replicatePuts=true,
    		         replicatePutsViaCopy=true,
    		         replicateUpdates=true,
    		         replicateUpdatesViaCopy=true,
    		         replicateRemovals=true" />
    
    		<!-- RMI Cache bootstrap -->
    		<bootstrapCacheLoaderFactory
    			class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
    			properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
    			propertySeparator="," />
    
    	</cache>
    
    </ehcache>
    

    Initializing the CacheManager & Accessing the cache

    // Testing the cache creation in ver 2.1
    CacheManager manager = new CacheManager("/path/to/config/file.xml");
    
    // Get the instance of "MyCache"
    Cache myCache = manager.getCache("MyCache");
    
    // Add an element to "MyCache". Its preferred to have both key and value
    // serializable
    Element aCacheElement = new Element(key, value);
    myCache.put(aCacheElement);
    

    Useful Links

    RMI replication: http://ehcache.org/documentation/distributed_caching_with_rmi.html
    Configuration: http://ehcache.org/documentation/configuration.html

     
  • Subinkrishna Gopi 4:19 pm on June 14, 2010 Permalink |
    Tags: facebook, , , , , , , user,   

    Today’s read: How To Permanently Delete Your Account on Popular Websites 

    How To Permanently Delete Your Account on Popular Websites via Smashing Magazine.

    I had to struggle a lot to get rid of my orkut account! It was not very easy. When I was doing that I really wished to have some FAQs and guidelines which I read and understand. But tough luck, I didn’t find anything then. But I found this article in Smashing Magazine today, and I think this is really useful.

    We all have an increasing number of sites and online services we’re members of, and sometimes it all gets a little overwhelming. At times, we just need to delete our memberships to some sites, either in an effort to simplify our lives or just because we’ve grown tired of a particular site or service.

    What we often don’t realize when signing up for all these accounts, though, is how difficult it can be to permanently delete our accounts when we’ve had enough. Some require complicated, multi-step processes that can stretch over the course of days (or weeks). Others take less time, but still require multiple steps by the user.

    Read the article

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel