Archive for the ‘Uncategorized’ Category
Sublime Text 2 JSHint Plugin issue on windows
Sublime Text 2 is my favorite editor now a days. It has nice look and feel and great features.
I was trying to use its Plugin for integration of JSHint. I read Pre requistes and followed every steps but I was getting following error every time I do build (to run JSHint) .
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'PATH\AppData\Roaming\Sublime Text 2\Packages\JSHint\scripts\run.js'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
[Finished]
I googled it to see if anyone has workaround,but I could not find one. Finally I am able to solve it with following steps:
- Go to directory of JShint under packages for example …’PATH\AppData\Roaming\Sublime Text 2\Packages\JSHint
- Get both the js files from https://github.com/victorporof/Sublime-JSHint/tree/master/scripts to scripts directory
- Restart Sublime and run JSHint it will work
Liferay Cache
Leveraging Liferay Cache to Improve performance :
Liferay provides out of box Cache MultiVMPool, which can be used by portlets to cache results of heavy network calls i.e. web services.
MultiVMPool Cache is very easy to use and yet powerful enough to work in clustered environment. Unfortunately there is no official documentation for MultiVMPool, which describes how it works and how it can be leverage by portlets.
What is MultiVMPool Cache ?
-
- Out of Box Cache from Liferay : No additional configuration infrastructure needed.
- Wrapper around EHCache : As powerful as EHCache
- Clustered Cache
- JVM Level Cache: Object cached by one WAR will be available to other WARs on same JVM.
How to Use :-
-
- MutliVMPoolUtil : Utility class provides methods to access MultiVMPool
http://docs.liferay.com/portal/5.1/javadocs/portal-kernel/com/liferay/portal/kernel/cache/MultiVMPoolUtil.html - Common Usage :
Using MultiVMPoolUtil : new cache will be dynamically created if not exits.
Following methods shows basic usage :
name= Cache Name
key=Key of Cache Entry
obj=Object to be Cached.
Put Obeject in Cache
put(java.lang.String name, java.lang.String key, java.io.Serializable obj)
Get Object from Cache
get(java.lang.String name, java.lang.String key)
Clear Cache
clear(java.lang.String name)Remove Object from Cache
remove(java.lang.String name, java.lang.String key) Please note here that Liferay MutliVMPoolUtil provides overloaded method to put Normal object (i.e non serialized) also. But in Clustered environment make sure to use Serialized object which can be copied to other caches over wire.
Clustered Cache needs to enable from portal.properties
ehcache.multi.vm.config.location=/ehcache/liferay-multi-vm-clustered.xml
- MutliVMPoolUtil : Utility class provides methods to access MultiVMPool
Pros:
-
- Easy to Use
- No configuration required from portlet
- Clustered Cache
Cons:
-
- Use Default settings for Cache created. No API to set different timeToLive,timeToIdle
settings for the cache. - To change default Cache settings only done using EXT environment.
- Use Default settings for Cache created. No API to set different timeToLive,timeToIdle
Liferay Session Sharing : Made Easy
- What I mean by ACTION-to-VIEW is on “action phase” of one portlet information is shared and made available to specific/all portlet’s “view phase”.
- There are use cases where we need a IPC mechanism to share information between portlets of different WARs in VIEW-to-VIEW .It means One portlet will share information from its VIEW phase and will be available to other Portlet in VIEW phase.
1.liferay-portlet.xml
<portlet>... <private-session-attributes>false</private-session-attributes> </portlet>
2. Use Namespace prefix to Share/Get shared session attribute:
portletSession.setAttribute( "LIFERAY_SHARED_mySpecialVar",value,PortletSession.APPLICATION_SCOPE);
portletSession.getAttribute( "LIFERAY_SHARED_mySpecialVar",PortletSession.APPLICATION_SCOPE);
How to Share with Servlet of Other WAR :-
portletSession.setAttribute( "LIFERAY_SHARED_mySpecialVar",value, PortletSession.APPLICATION_SCOPE);
Object value= portletSession.getAttribute ( "LIFERAY_SHARED_mySpecialVar",PortletSession.APPLICATION_SCOPE);//getting shared value portletSession.setAttribute ( "mySpecialVar",value,PortletSession.APPLICATION_SCOPE);//setting to 'local' session
request.getSession().getAttribute("mySpecialVar");
/***** <pre>* RUTVIJ SHAH MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. RUTVIJ SHAH SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. * THIS SOFTWARE IS IN AS-IS FORM, YOU ARE FREE TO RE-DISTRIBUTE/CHANGE WITHOUT ANY NOTIFICATION TO AUTHOR. ******/ package myapp.liferayImpl.session.util; import com.liferay.portal.kernel.util.PropsUtil; import java.util.logging.Level; import java.util.logging.Logger; import javax.portlet.PortletRequest; import javax.portlet.PortletSession; /** * @author Rutvij Shah ( rutvij.shah@yahoo.com ) * LiferaySessionUtil provides helper methods to share your Session attributes * across WARs. * */ public class LiferaySessionUtil { /*** * This prefix is used by Liferay Portal to detect Session Attributes * for sharing betweeen WARs. */ private static final String LIFERAY_SHARED_SESSION_PREFIX=getSharedSessionPrefix(); private static final String LIFERAY_SHARED_SESSION_PREFIX_DEFAULT="LIFERAY_SHARED_"; /**** * It stores attribute as 'Shared' Attribute and will be available to other * portlets in different WARs. * * Attributes shared by this method will be available to only Portlets, * not other Web components i.e Servlet. * * @param key session Key to store value * @param value * @param request PortletRequest */ public static final void setGlobalSessionAttribute(String key,Object value,PortletRequest request){ if(key!=null){ String globalKey=getGlobalKey(key); PortletSession portletSession=request.getPortletSession(); portletSession.setAttribute(globalKey,value,PortletSession.APPLICATION_SCOPE); } } /**** * * It provides access to get shared session attributes from other portles * from diffrent WARs. * * @param key * @param request * @return */ public static final Object getGlobalSessionAttribute(String key,PortletRequest request){ Object value=null; if(key!=null){ String globalKey=getGlobalKey(key); PortletSession portletSession=request.getPortletSession(); value=portletSession.getAttribute(globalKey,PortletSession.APPLICATION_SCOPE); } return value; } /****** * * It provides a way to further share 'Shared'Session Attributes from * Portlet to other Web Components i.e Servlets . * * @param key * @param request */ public static final void shareGlobalSessionAttribute(String key,PortletRequest request){ if(key!=null){ Object value=getGlobalSessionAttribute(key, request); PortletSession portletSession=request.getPortletSession(); portletSession.setAttribute(key,value,PortletSession.APPLICATION_SCOPE); } } /*** * Helper method to generate Global key using Liferay shared prefix * @param key * @return */ private static final String getGlobalKey(String key){ return LIFERAY_SHARED_SESSION_PREFIX+key; } /******** * Helper method to get Liferay's Session Sharing prefix * Useful when Liferay is customized to use different prefix other than Default * * @return */ private static final String getSharedSessionPrefix(){ String value=null; try { /** * Getting value from portal.properties */ value = PropsUtil.get("session.shared.attributes"); } catch (Exception ex) { Logger.getLogger(LiferaySessionUtil.class.getName()).log(Level.SEVERE, null, ex); } if(value !=null){ if(value.contains(LIFERAY_SHARED_SESSION_PREFIX_DEFAULT)){ //if default prefix is configured use it value=LIFERAY_SHARED_SESSION_PREFIX_DEFAULT; }else{ //use first one from the list of prefix configured value=value.split(",")[0]; } }else{ /** * If none of the value configured use default one * Note: Session Sharing may not work as none of the value configured. */ value=LIFERAY_SHARED_SESSION_PREFIX_DEFAULT; } return value; } }
LiferaySessionUtil.setGlobalSessionAttribute ("mySpecialVar",value, portletRequest); //adding 'proper' prefix will be taken care by Utility
Object value= LiferaySessionUtil.getGlobalSessionAttribute ("mySpecialVar", portletRequest); //to get value for portlet LiferaySessionUtil.shareGlobalSessionAttribute ("mySpecialVar", portletRequest);//to share value to servlets
As you can see if Portlet Two only need to share it with servlet no need of first line.
request.getSession().getAttribute("mySpecialVar");
Feel free to share your comments on this. You can download LiferaySessionUtil.java from here : LiferaySessionUtil
Hello world!
Hello world !!! I will use this blog medium to share my thoughts and ideas about Technologies and my life as a Developer.
I am passionate about Java and Java related technologies, working as Software Consultant.