It has been really long time i haven't posted any articles on my blog. somehow was busy with couple of projects.
Finally today i got some time and thought of immediately write a post before it's too late again... anyways..
So friends, here in one of my assignment we are using dynacache to share object across application.
I posted my query on IBM developer works asking for how DynaCache works in cluster environment and i got one reply, so just thought of sharing on my blog.
DynaCache behaviour in clustered environment is somewhat different and need to take special attention.
Fist, if you don't have data replication domain setup in cluster environment each node has its own copy of the dynacache and which may cause issues in case of fail over or in case when objects are shared between diff application.
To use the your dynacache as global object across the cluster , you need create one data replication domain for the all nodes in the cluster and enable the data replication service.
To enable data replication service of dynacache, please refer to Configuring cache replication article in infocenter
Showing posts with label DynaCache. Show all posts
Showing posts with label DynaCache. Show all posts
DynaCache scenarios and implementation
I have seen so many queries where people are looking for solution to share object between different portlet applicataions.I just thought of writing this post for detailed solution for these kind of use cases.
So friends, If you have custom object and you want to share that object across any portlet application deployed on your portal environment,
DynaCache is the place where you can store your object and get the object where ever required back from DynaCache.
DynaCache Scenarios
scenarios i have worked with was
In my custom login portlet, i was required to store custom object at the time lo login and the same object should be available to all portlet applications deployed on portal.
For this, In my login portlet i stored the object into DynaCache and get the object from DynaCache where ever required.
There could be other scenarios as well, where you want to Cache data in JSR 168 portlets, Share information between IBM portlets and JSR 168 portlets
Technically, WebSphere Application Server provides the DistributedMap interface as a simple interface for the dynacache.
DynaCache implementation
First, you need to enable global dynacache service in the WebSphere Application Server administrative console.
By default, this service is enabled but in case if it's disabled, follow the steps below to enable it
1. Open the administrative console.
2. Select Servers => Application Servers in the administrative console navigation tree.
3. Click the WebSphere Portal server.
4. Select Additional Properties => Dynamic Cache Service.
5. In the Startup state field, select Enable service at server startup.
6. Click Apply or OK.
7. Restart WebSphere Application Server and WebSphere Portal Server.
Registering and configuring a new dynacache
Next, you need to register and configure a new dynacache instance for use by the portlet service
1. Open the administrative console.
2. Select Resources => Cache instance = > Object cache instances.
3. click New.
4. provide values to mandatory fields.
(I am giving JNDI values as services/cache/MyCustomObjectCache )
5. Click Ok and then Save.
Accessing/lookup of DynaCache service
Next, we will access/lookup DyanaCache Service. In portlets, where ever you are storing or getting the object to/from dyanacahe, you will have to lookup the service first and then you can store or get the object to/from dynacache.
Best paractice would be to lookup this service at the time of initialization.(init method of portlet)
//declare a class level variable
private DistributedMap distributedDynaCacheMap = null;
public void init(PortletConfig portletConfig) throws PortletException {
super.init(portletConfig);
Context context;
try {
context = new InitialContext();
distributedDynaCacheMap = (DistributedMap)context.lookup("services/cache/MyCustomObjectCache");
} catch (NamingException e) {
throw new PortletException();
}
Now, you have got your dynacache service lookedup...
To store object into dynacahe, simply call put method.
distributedDynaCacheMap.put(Object arg0, Object arg1);
To get object from dynacache in any of portlet, first you need to access/lookup the service and just call get method on distributedDynaCacheMap.
distributedDynaCacheMap.get(object argo);
So friends, If you have custom object and you want to share that object across any portlet application deployed on your portal environment,
DynaCache is the place where you can store your object and get the object where ever required back from DynaCache.
DynaCache Scenarios
scenarios i have worked with was
In my custom login portlet, i was required to store custom object at the time lo login and the same object should be available to all portlet applications deployed on portal.
For this, In my login portlet i stored the object into DynaCache and get the object from DynaCache where ever required.
There could be other scenarios as well, where you want to Cache data in JSR 168 portlets, Share information between IBM portlets and JSR 168 portlets
Technically, WebSphere Application Server provides the DistributedMap interface as a simple interface for the dynacache.
DynaCache implementation
First, you need to enable global dynacache service in the WebSphere Application Server administrative console.
By default, this service is enabled but in case if it's disabled, follow the steps below to enable it
1. Open the administrative console.
2. Select Servers => Application Servers in the administrative console navigation tree.
3. Click the WebSphere Portal server.
4. Select Additional Properties => Dynamic Cache Service.
5. In the Startup state field, select Enable service at server startup.
6. Click Apply or OK.
7. Restart WebSphere Application Server and WebSphere Portal Server.
Registering and configuring a new dynacache
Next, you need to register and configure a new dynacache instance for use by the portlet service
1. Open the administrative console.
2. Select Resources => Cache instance = > Object cache instances.
3. click New.
4. provide values to mandatory fields.
(I am giving JNDI values as services/cache/MyCustomObjectCache )
5. Click Ok and then Save.
Accessing/lookup of DynaCache service
Next, we will access/lookup DyanaCache Service. In portlets, where ever you are storing or getting the object to/from dyanacahe, you will have to lookup the service first and then you can store or get the object to/from dynacache.
Best paractice would be to lookup this service at the time of initialization.(init method of portlet)
//declare a class level variable
private DistributedMap distributedDynaCacheMap = null;
public void init(PortletConfig portletConfig) throws PortletException {
super.init(portletConfig);
Context context;
try {
context = new InitialContext();
distributedDynaCacheMap = (DistributedMap)context.lookup("services/cache/MyCustomObjectCache");
} catch (NamingException e) {
throw new PortletException();
}
Now, you have got your dynacache service lookedup...
To store object into dynacahe, simply call put method.
distributedDynaCacheMap.put(Object arg0, Object arg1);
To get object from dynacache in any of portlet, first you need to access/lookup the service and just call get method on distributedDynaCacheMap.
distributedDynaCacheMap.get(object argo);
Subscribe to:
Posts (Atom)