Tag: Singleton Service

Steps to configure a Singleton Service from Application side

Ravish Mody

Ravish Mody

A singleton service is a service that can only run on a single managed server in a cluster at a time. Weblogic Server lets you automatically monitor and migrate singleton services from one server to another. This can be done by implementing the “weblogic.cluster.singleton.SingletonService” interface and by using activate () and deactivate () methods in a class.

For Application level demo you have download a simple application “MySingletonServiceEar.ear” which has a class in it called “MySingletonService.class” which implements the “weblogic.cluster.singleton.SingletonService” interface and has both activate () and deactivate () methods in it which is under APP-INF -> classes. And in “weblogic-application.xml” has the singleton service name and class name which necessary for this configuration because here we are configuring a singleton services from application side.

Steps To Follow:

1.    Create 2 managed Servers say MS-1 and MS-2 and assign a Machine & a Cluster to these Managed Servers.

clip_image002

2.    We would be using NodeManagers (Consensus) for clustered singleton services migration, hence we have to configure following things.

Console Path: Clusters —> Cluster —> Configuration [tab] —> Migration [sub-tab]

Candidate Machines For Migratable Servers: Machine

Migration Basis: Consensus

clip_image004

3.    Now you just have to deploy “MySingletonServiceEar.ear” targeted on Cluster which we had made.

4.    Start both the managed servers with the help of nodemanager.

5.     If you want to check on which server is Singleton Service might be running then you can confirm this from the managed servers .out file, as from console we did not make any Singleton Services. In my case following was the output.

MS-1.out

MS-1.out file was having the active () method called.

MS-2.out

But MS-2.out file was not having the active () method.

Conclusion:

This states that the service is running only on one server.

6.    Now shutdown MS-1 and then check the managed server’s .out files.

MS-1.out

You will notice that the MS-1.out would have now called deactivate () method and has got shutdown.

MS-2.out

However MS-2.out file will have the active () method as when MS-1 was brought down and during that time our service had migrated to the MS-2.

Conclusion:

This states that the service has got migrated properly and is still running only on one server.

NOTE: Here service can be running on any server for the first time, as we did not mention the Preferred Server for the service anywhere in application level.

Thanks,

Ravish Mody


Steps to configure a Singleton Service from Console

Ravish Mody

A singleton service is a service that can only run on a single managed server in a cluster at a time. Weblogic Server lets you automatically monitor and migrate singleton services from one server to another. This can be done by implementing the “weblogic.cluster.singleton.SingletonService” interface and by using activate () and deactivate () methods in a class.

For console level demo you have to download a simple “MySingletonService.jar” file which contains the “MySingletonService.class” file which implements the “weblogic.cluster.singleton.SingletonService” interface and has activate () and deactivate () methods in the class. As this is a console level configuration we will configure the singleton service name and class name from Console.

Steps to Follow:

1.   Create 2 managed Servers say MS-1 and MS-2 and assign a Machine & a Cluster to these Managed Servers.

clip_image002

2.    We would be using NodeManagers (Consensus) for clustered singleton services migration, hence we have to configure following things.

Console Path: Clusters —> Cluster —> Configuration [tab] —> Migration [sub-tab]

Candidate Machines For Migratable Servers: Machine

Migration Basis: Consensus

clip_image004

3.    Now we will define the new singleton service in the same cluster by going to following path.

Console Path: Clusters —> Cluster —> Configuration [tab] —> Singleton Service [sub-tab]

Create a new Singleton Service by clicking New

4.   Enter the following required information fields and then click Next

Singleton Service Name: MySingletonService

Class Name: my.singleton.service.MySingletonService

clip_image006

Note: Class name should have the fully qualified name of the class which implements the SingletonService interface

5.     In next page you have to select which managed server you like to specify to be the User Preferred Server for this service, select one from the drown down box and then click Finish

clip_image008

6.      Now you can see the following page from which you have to select the Singleton Service which we have just created “MySingletonService”.

clip_image010

7.      Then go the following path to specify a list of Constrained Candidate Servers and save the setting, however you would need to restart all the servers. Start managed servers with the help of nodemanager.

Console Path:

Clusters —> Cluster —> Configuration [tab] —> Singleton Service [sub-tab] —> MySingletonService —> Configuration [tab] —> Migration [sub-tab]

Constrained Candidate Servers: MS-2, MS-1

clip_image012

8.       Before restarting all the servers make sure you keep “MySingletonService.jar” file in the domain –> lib directory which contains the “MySingletonService.class” implementing “weblogic.cluster.singleton.SingletonService” interface and has activate () and deactivate () methods in the class.

9.       You can check it from command prompt if the “MySingletonService.jar” file has been picked up or not.

10.      Once “MySingletonService.jar” file has been picked up properly then you can check on which server is Singleton Service is running from console go to the following path.

Console Path:

Clusters —> Cluster —> Configuration [tab] —> Singleton Service [sub-tab] —> MySingletonService —> Configuration [tab] —> Control [sub-tab]

Current Server: MS-1

clip_image014

From managed servers .out file

MS-1.out

You can also check from the MS-1.out file that it would have called the active () method

MS-2.out

But MS-2.out file would not have called the active () method.

Conclusion:

This states that the service is running only on one server.

11.        Now shutdown MS-1 and then go to the following path and check on which server is your service is running.

Console Path:

Clusters —> Cluster —> Configuration [tab] —> Singleton Service [sub-tab] —> MySingletonService —> Configuration [tab] —> Control [sub-tab]

Current Server: MS-2

clip_image016

This states that our configuration is correct and our service is migrating properly to the second running managed server in the cluster.

And from the managed server’s .out file

MS-1.out

You will notice that in MS-1.out file would have now called deactivate () method and has got shutdown.

MS-2.out

And MS-2.out file would have called the active () method.

Conclusion:

This states that the service is still running only on one server which is obvious in this case as there are only 2 managed servers in Cluster.

Thanks,

Ravish Mody


  • Testimonials

  • RSS Middleware Magic – JBoss

  • Receive FREE Updates


    FREE Email updates of our new posts Enter your email address:



  • Magic Archives

  • Sitemeter Status

  • ClusterMap 7-Nov-2011 till Date

  • ClusterMap 6-Nov-2010 till 7-Nov-2011

  • Copyright © 2010-2012 Middleware Magic. All rights reserved. | Disclaimer