Inter Gadget Communication with PubSub

Technical Blogs September 1, 2016 By Kailash Yadav

        In my previous blog, I wrote about Gadget/Widget and how we can use it in Liferay. Liferay provide great support of Gadgets. Liferay has out of box features like share portlet as widget and OpenSocial Gadget Editor where you can write gadget XML and publish in your portal. Liferay also provide OpenSocial Gadget plugin where admin can add third party gadgets in Liferay portal like portlets.

Inter Gadget Communication with PubSub:

        Like Inter Portlet Communication(IPC), communication between two gadgets or between gadget and portlet is also very important. OpenSocial provide mechanism to establish communication between gadget to gadget or gadget to portlet or vice versa using pubsub.

        Pubsub works like event fire/listen in AUI. There is one publisher gadget which publishes to the topic and There may be multiple consumer gadgets which has subscribed the topic. Publishers don’t send messages to subscribers directly because publisher have no knowledge about subscribers. Publisher broadcast the messages over a channel(topic). Subscriber need to subscribe channels(topics) to receive message.

Publisher Gadget

        To publish a message publisher gadget need to add topic details in Require tag like :

        Here com.example.opensocial.testgadget is topic name which subscribers need to subscribe to receive message. And publishing can be done by the Javascript method call :

        Here first parameter is topic name and second is a variable which need to publish.

Subscriber Gadget

        To receive a message from publisher, receiver gadget need to subscribe topic. Following the example to subscribe a topic:

        Here first parameter in subscribe function is topic name which need to subscribe and the second parameter is call back function name that will be called when a message is published by publisher gadget. The published message can be used in callback function:

 

        You can find publisher / subscriber gadget example on @dejuknow's github.

Gadget/Widget in Liferay

Technical Blogs May 23, 2016 By Kailash Yadav

    We hear about widget/gadget in daily life like we can add gadgets on Windows-7's desktop. Widget is an application or icon which performs a specific functions on desktop or website. For example, if you want to add counter or social site icons, you can add a script in your page and that widget available on your page. So a widget is a piece of reusable code that you can plug into virtually any website. A gadget is same like widget but it only works on a certain website or a specific set of websites. Gadgets are simple and easy to deploy.
 
OpenSocial Gadget
    OpenSocial is a public specification for creating web applications using standard technologies like HTML, CSS, and JavaScript. OpenSocial applications called gadgets which are similar to portlets because gadgets can be added to portal’s pages like portlets.
Figure 1 - OpenSocial Gadget
 
Share your portlet as widget
    Liferay has feature which convert your portlet as standalone widget. You can share your portlet as a widget to any web site or Facebook or OpenSocial gadget.
To share your portlet, go to portlet configuration and click on Sharing tab there. Sharing tab has following options:
Figure 2 - Portlet Share Configuration
  1. Any Website: It has JavaScript code. You can copy and paste on your website where you want to show portlet. You can also allow your users to add this widget on their websites.
  2. Facebook: It provide ability to add your portlet as an application on Facebook page.
  3. OpenSocial Gadget: Liferay portlet can be used as Open Social Gadgets on any OpenSocial-compatible pages like iGoogle. You can also allow your users to use this OpenSocial Gadget.
  4. Netvibes: You can also share your portlet on Netvibes portal. You can also allow your users to use this Netvibes widget.
  5. Friends: It allows you to give your friends permission to add the application as a widget to another web site.

Figure 3 - User's Share Options

Using OpenSocial Gadget in Liferay

    You can add any Gadget on Liferay page. Liferay Marketplace has OpenSocial Gadget plugin. This plugin can be used in two ways to add gadgets in Liferay pages.

Adhoc Gadget: It is quick way to add Gadget on page. You need to add OpenSocial Widget portlet from Gadget category. Now open portlet configuration and set gadget URL which you want to add on page.

Figure 4 - OpenSocial Gadget Plugin

Portal-wide Gadgets: In this way, you can configure gadget at one place and use that as a portlet on liferay pages. To add gadget, you need to go Control Panel -> Apps -> OpenSocial Admin. There you need to provide Gadget URL and category in which your Gadget will available as portlet. Now a portal admin can add that Gadget on page like we add portlets on page.

Figure 5 - OpenSocial Admin

Liferay also provide possibility to configure oAuth credentials. When we add Twitter Widget, it also ask Consumer Key and Consumer Secret which you can get from twitter.com

OpenSocial Gadget Editor 

OpenSocial Gadget plugin also provide a gadget editor where you can create your own gadget and publish it. It generate a unique URL which can be used on any OpenSocial-compatible pages to show that gadget. To create new gadget, you need to go Site Administrator  -> Content -> OpenSocial Gadget Editor. It has editor to write OpenSocial Gadget XML. When you publish, it generate public gadget URL.

Figure 6 - OpenSocial Gadget Editor

 
 
 
 

Liferay Caching - Service Level Caching using WebCachePool

Technical Blogs February 21, 2016 By Kailash Yadav

                Caching is important part of any web application. We implement caching for our application on different levels. Generally we cache static resource on web server level and DB level caching on persistence level. Most of web-framework/portal provide some level of caching. Liferay strongly integrated caching in its core part and it also provide mechanism that user can optimize caching according to their requirement.

    Liferay provide many level caching like CacheFilter, MultiVMPool/SingleVMPool, Hibernate caching.

  • Frontend Caching: Liferay cache HTML page in CacheFilter. It check if request is cachable or not. If yes, it cache the HTML data. Liferay can also cache portlet fragment.
  • Service Level Caching: Liferay provide ability to cache data on service level. SingleVMPool cache use for cache data on a single server node. MultiVMPool is used for cache data across multiple nodes.
  • Persistence Caching: Liferay cache data in persistence level like it Hibernate caching, SB finder cache etc.

    You can find more detail on Jorge Ferrer's blog.

                In Service level caching, Liferay provides WebCachePool which internally uses SingleVMPool. It hides the implementation details of getting the data and caching it at same time. WebCachePoolImpl provides get(String key, WebCacheItem wci) method and it check if provided key has already cached data or not. So developer only need to focus on their logic; getting data from cache, adding caching and refresh cache data handle by WebCachePool.

                To use get(String key, WebCacheItem wci) method, developer need to pass two parameter. First param is key. It is unique key for cache. For e.g. Liferay cache RSS feeds in RSS-Portlet. In RSS Portlet, feed URL is key. Second Parameter is object of implementation class of WebCacheItem interface. It fetch actual data from DB or webservice when it required. Like in RSS portlet, convert(key) method of RSSWebCacheItem call when portlet need first time feeds for a key(URL). It is also called when cache is expired.

 

 

 

                WebCachePool is easy to use. Only one class need to write. Developer don't need to know how to cache data against unique key. WebCachePool manage it. We can define refresh time of each WebCacheItem. So if there are two WebCacheItem in your portlet, they may have different refresh time. Liferay use WebCachePool in many portlet like Translator Portlet, Amazon Ranking Portlet, RSS portlet, Currency Converter Portlet etc. In Translator Portlet, Liferay use Microsoft Translator services and it cache translated output against the input key for 90 days (translation doesn't change usually).

 

Using WebCachePool in Custom Portlet:

                First you need to create a class with implement WebCacheItem interface. You need to override convert(String key) and getRefreshTime() method.

 

 

Now use this in you controller or service like this:

 

If you like to remove cached data of any key, you can do like:

 

If you want to clear all cache in WebCachePool, you can do like :

 

Install EE plugin in development machine

General Blogs December 2, 2015 By Kailash Yadav

Liferay marketplace is great tool, you can sell your app, download free apps or purchase EE apps. There are also many great free EE apps. You can download CE apps using your browser. But when you search EE apps in browser, you see EE Only button and there is a message that it Available to EE subscribers. Find out how to get a subscription.

Displaying image.png

Many developers don't know how to download free EE plugin so I thought I should write a blog about it.

Prerequisites: EE portal, valid EE License, Admin credentials of you portal, Liferay.com credentials.

For free EE plugins, you need to login with admin credentials in your portal. Click on Control Panel. Now go to Purchased menu in App section. It will ask you to login on Liferay Market place, use you Liferay.com credentials. After login it may ask for update your marketplace app. So update it first.

Displaying image.png

 

Now you will see two or three tabs, click on EE tab. It will show all free EE plugins. You can install plugin from there.

Enjoy !!!

Showing 4 results.