persistent disk storage in ehcache

Requirement – To have persistent storage in ehcahce

Solution-
cacheManagerPeerProviderFactory –It is used for saying “Hello, I’m here!” and allows to discover the other CacheManager in the cluster and be discovered by other nodes.

It accepts only two arguments (class and properties).

cacheEventListenerFactory — It is used for receiving notification about cache update by other nodes in cache cluster.

bootstrapCacheLoaderFactory —It is used for starting cache system and synchronize the cached elements in the cluster.

package com.techartifact.caching;

import java.util.ArrayList;
import java.util.List;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

// this is main class.
public class MainClass {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MainClass mainClass = new MainClass();
		mainClass.runMainClass();
	}

	private void runMainClass() {
		// TODO Auto-generated method stub
		int TOTAL=3;
	         CacheManager cacheManager = new CacheManager();
		Cache myCache = cacheManager.getCache("persistentEhcacheNew");

		System.out.println("the size of my cache at startup is: "+myCache.getSize());
		System.out.println("disk store size: "+myCache.getDiskStoreSize());
		System.out.println("memory store size: "+myCache.getMemoryStoreSize());
	        System.out.println("memory DiskStoreSize size: "+myCache.getDiskStoreSize());
	        System.out.println("boot strapCacheLoader is Asynchronous: "+myCache.getBootstrapCacheLoader().isAsynchronous());
                System.out.println("cache status: "+myCache.getStatus());
	        System.out.println("cache name: "+myCache.getName());
                List listOfKeys= myCache.getKeys();
                //myCache.removeAll();
                if(myCache.getDiskStoreSize()>0){
               for (Object temp : listOfKeys) {
                        System.out.println((String)temp.toString());
	                Element element = myCache.get(temp);  
	                     
	                      if (element != null) {  
	                       System.out.println(temp + " is in the cache!!!"); 
	                       String val = (String)element.getValue().toString();
                               System.out.println(val + " value is in the cache!!!");
                              }
	            }
                }else{
              
		System.out.println("now add 3 elements to cache");
                    for (int i = 0; i < TOTAL; i++) {
                            DataObject dataObject = new DataObject();
                           dataObject.setRandomFloat(Randomizer.returnRandomFloat());
                            dataObject.setRandomString(Randomizer.returnRandomString());			
                            Element element = new Element(i,  dataObject.getRandomFloat());
                            myCache.put(element);
                   }
                }

		cacheManager.shutdown();
		
	}

}


BootstrapCacheLoaderFactory – An abstract factory for creating BootstrapCacheLoader instances. Implementers should provide their own concrete factory extending this factory. It can then be configured in ehcache.xml.

Create a MyBootstrapCacheLoaderFactory that extends BootStrapCacheLoaderFactory, and override method load(EhCache ehcacheparam)to bring the cache up on server startup

package com.techartifact.caching;

import java.util.List;
import java.util.Properties;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.bootstrap.BootstrapCacheLoader;
import net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory;

// 
public class MyBootstrapCacheLoaderFactory extends BootstrapCacheLoaderFactory implements BootstrapCacheLoader{
	

	@Override
	public BootstrapCacheLoader createBootstrapCacheLoader(Properties properties) {
		// TODO Auto-generated method stub
		return new MyBootstrapCacheLoaderFactory();
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return super.clone();
	}
	public boolean isAsynchronous() {
		// TODO Auto-generated method stub
		return false;
	}
	public void load(Ehcache myCache) throws CacheException {
		// TODO Auto-generated method stub
		System.out.println("load your cache with whatever you want....");
		List keys = myCache.getKeys();
		for (int i = 0; i < keys.size(); i++) {
			Element element = myCache.get((keys.get(i).toString()));
		}
		System.out.println("load complete!");
	}



}

Uploading static file (image) in webcenter portal for template

Requirement – I have seen many people asking in OTN forum regarding, how to upload with page template or with skin in webcenter. Today sharing with you all.

In wcp 11.1.1.8 normally you don’t have check box to upload content directory with images, javascript or some static file in portal. If you export some asset in WCP from jdeveloper,
Normally template is uploaded but not image.I will take an example of images in this. I created an custom template with some image for mobile.I want to upload back in WCP using round trip
development.

Normally in old wcp version in shared folder , we have all static files or images.Oracle says about this

Legacy directory in MDS for images and content used by assets, such as, icons, images, and so on.Oracle recommends that you relocate all such artifacts to
your content server and that you use a folder structure on your content server specifically for asset artifacts so that content is easy to identify and move, if required.
If you choose not to move artifacts stored in MDS, your administrator can use the MDS WLST commands exportMetadata/importMetadata to migrate content to and from MDS.

So there are two option

1) – Upload in WCC (Webcenter content) – You can upload these document in wcc with some marking and use in webcenter portal. You can use images in WCP as by my previous article.
Display UCM files in ADF/Webcenter application as images or link

– I uploaded techartifact logo in wcc

WCCCheckIn

– I created custom template and added image in that. Source of image is like below

#{WCAppContext.applicationURL}/content/conn/ucmserver/uuid/dDocName%3aAPPLOGO1

imgeSource

APPLOGO1 – content id of document. Read my previous article

That’s it. In this way you can use images in template or skin.

2) – Upload manually in MDS using exportMetadata/importMetadata command – These command is very helpful in working metadata in weblogic. Read my previous article

While creating assest for WCP in jdeveloper, if you put images in shared folder and in below structure

jdeveloperStructure

Then you can use importMetadata command to import image in MDS. for exmaple

importMetadata(application=’webcenter’, server=’WC_Spaces’,fromLocation=’/home/oracle/temp’,docs=’/**’)

– /home/oracle/temp= On this location there is same folder structure like ‘oracle\webcenter\siteresources\scopedMD\shared\images’ . inside image folder , you can put your all images.
and run it

Steps

– run wlst.sh or wlst.cmd under webcenter installtion location
– connect(‘weblogic’,’pwd’,’t3://:7001′)
– importMetadata(application=’webcenter’, server=’WC_Spaces’,fromLocation=’/home/oracle/temp’,docs=’/**’)

Note:In this case, image source in jdeveloper will point to oracle\webcenter\siteresources\scopedMD\shared\images folder and so on..

Final output of template is as below

phone template

That’s it.. By this way you can upload your images.

Happy Learning with Vinay in techartifact…..