I recently visited a Package Delivery Company Customer (SxxR) who needed to implement a logic consisting in a background thread scanning continuously a shared directory containing acknowledgement of receipts of shipments files that must be processed and then passed to another stage.
How can we make this logic HA?
The answer is SingletonService: runs only in one of the managed servers of a cluster but it is migrated automatically if the server fails or is stopped.
INSTRUCCTIONS
Create a java Class like this:
package miapp;
import weblogic.cluster.singleton.SingletonService;
public class MyUniqueWorker implements SingletonService{
public void activate() {
System.out.println(“***************** activate called *************”);
}
public void deactivate() {
System.out.println(“***************** de-activate called *************”);
}
}
Put the Class in a jar file, singleton.jar for instance
Put the following in weblogic-application.xml:
<singleton-service>
<class-name>miapp.MyUniqueWorker</class-name>
<name>mySingleTown ;-)</name>
<singleton-uri>singleton.jar</singleton-uri>
</singleton-service>
Package the jar in an ear app:
Deploy the ear to the cluster.
Create the managed servers, machine and cluster and configure it as follows:
TEST IT
The logic runs in one mnaged server, but if the server where it is running fails or is stopped the execution jupms to other managed server in the cluster.
####<Jun 24, 2015 1:04:20 AM CEST> <Notice> <Stdout> <JMUGUETA-ES> <server1> <[STANDBY] ExecuteThread: ‘2’ for queue: ‘weblogic.kernel.Default (self-tuning)’> <<WLS Kernel>> <> <> <1435100660323> <BEA-000000> <***************** de-activate called *************>
####<Jun 24, 2015 1:04:28 AM CEST> <Notice> <Stdout> <JMUGUETA-ES> <server2> <[STANDBY] ExecuteThread: ‘4’ for queue: ‘weblogic.kernel.Default (self-tuning)’> <<WLS Kernel>> <> <> <1435100668652> <BEA-000000> <***************** activate called *************>
####<Jun 24, 2015 1:04:28 AM CEST> <Info> <Cluster> <JMUGUETA-ES> <server2> <[STANDBY] ExecuteThread: ‘4’ for queue: ‘weblogic.kernel.Default (self-tuning)’> <<WLS Kernel>> <> <> <1435100668653> <BEA-000189> <The Singleton Service mySingleTown 😉 is now active on this server.>
Enjoy 😉