Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question

gigaspace failover event callback


I am new to gigaspace. I have gone through the Quick Start Quide, but couldn't find what I need to implement.

Here is the problem that I am trying to solve:

I have two jboss servers. One is primary, the other one is backup. I would like to have embeded spaces in the jboss. I want to listen for failover event (backup becoming primary) in my code. If one server fails, the other server would get a callback and it will start processing. The space will sync up some data as well.

How do I accomplish this? Is there any documentation for this?

Thanks for your help. Jin

Edited by: Jin Chai on Dec 4, 2008 10:23 PM h4. Attachments









{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2750]{quote}

asked 2008-12-04 22:06:24 -0500

chai gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted


Before providing a direct answer , it is important to understand what is GigaSpaces.
GigaSpaces is a scale-out-application server. In includes In-Memory-Data-Grid (IMDG) , web server , messaging , security , high-availability , load-balancing , recovery , persistency and Interoperability services. This means you can host your business logic within GigaSpaces in the same manner you are doing it with JBoss. It is true that GigaSpaces is a not fully J2EE compatible app server (and there is a reason for this), but it includes most of what you will find with J2EE app server and many more capabilities that J2EE do not have that we found very important for the 21st century applications.

So before you will continue with the path you took - I would suggest you to consider the following:
1. Does my application relay on its data in a great manner? Do I need to access my IMDG in the most efficient manner , have the business logic close to the data and make these to act as one unified entity to fail and scale together?
2. My application is not data intensive and I would like to have my IMDG located in a different process(s) (potentially on a different machine(s)) where the application and the IMDG scales and fail in different manner?

If your requirements are closer to the first option , I would suggest you to consider GigaSpaces as your application server to host and mange both the IMDG and the business logic. These will be encapsulated within what we call a processing unit. This is a spring based container hosted within SLA based container that scales , load-balanced and recovers in automatic manner.

If your requirements are closer to the second option , you should deploy the IMDG separately. In this case you might want to have some of the data close to the business logic by having a local cache or local view running at the app server client side. With this case , you can have JBoss as your application server or GigaSpaces as the application server where the business logic accessing a remote GigaSpaces container that host the IMDG.

The benefit of using GigaSpaces as the business logic container would be out of the box failover , scaling and self healing capabilities both for the data and the business logic components. For example: You could instruct GigaSpaces to run 10 instances of your business logic , no matter what will happen and scale these up to 20 instances in case you need more processing capacity - all this in a transparent manner. In case one of them would fail - GigaSpaces will start a new one on the fly.

See this video for a demo that illustrates what you can do with GigaSpaces as an application server:

See here more details about the SLA container I've mentioned:

To answer your specific question - see this:

If your business logic would have been deployed as a processing unit having its space collocated - you would not need to have this manual failover implemented yourself. You will get this out of the box.

A space running in a backup mode cannot be accessed by the business logic (remote or embedded). Once you will get the relevant event that the backup moved into primary mode, the business logic running within the other JBoss instance will be able to access the space.



  1. gigaspacesFailover.vsd
  2. SpaceEventListener.java
  3. CacheHelper.java
  4. gsurls.properties
  5. pu.xml
  6. SpaceEventListener.java
  7. pu.xml
  8. SpaceEventMain.java

answered 2008-12-05 06:31:53 -0500

shay hassidim gravatar image
edit flag offensive delete link more



Your thorough reply is very helpful.

I went through the "Space Component : Primary Backup Notifications" section in the document. It talks about how to implement the bean. But where do we register this bean with the space? Do you have an example or document for that ?

Also, the document says it is a new feature for "6.6". We are currently using 6.5. So we need to upgrade in order to use this feature?

Thanks, Jin

Edited by: Jin Chai on Dec 5, 2008 10:39 AM h4. Attachments









chai gravatar imagechai ( 2008-12-05 10:07:02 -0500 )edit

You will need 6.6 to use this option. I'll try to create an example and post it. Shay h4. Attachments









shay hassidim gravatar imageshay hassidim ( 2008-12-05 12:08:20 -0500 )edit


See attached example illustrating the usage of the space mode events. This will start 2 Processing Unit Containers within the same JVM. In your case you will have each started in different JBoss instance.

The first Processing Unit Container will run a primary space and the other one will run a backup.

Once the primary space will be started you will see: com.test.SpaceEventMain@900e24 ---- onAfterPrimary ----

Once the backup space will be started you will see: com.test.SpaceEventMain@3c7d70 ---- onBeforeBackup ----

Once the primary space Processing Unit Container will be closed you will see: com.test.SpaceEventMain@3c7d70 ---- onAfterPrimary ----

This works for me with XAP 6.2.2.

Shay h4. Attachments









shay hassidim gravatar imageshay hassidim ( 2008-12-06 09:03:41 -0500 )edit


Thanks for the example. I have some follow-up questions.

I am wondering which part does the trick to register the bean as a space Primary Backup Notifications event listener.

<os-core:space id="space" url="/./mySpace" />
<bean id="mybean" class="com.test.SpaceEventMain"/>

Any bean listed in the pu.xml which has implemented the proper interfaces will be automatically registered? I don't see any java code is doing the registration. Is there a way to do this from code (just curious)?

Thanks, Jin

Edited by: Jin Chai on Dec 6, 2008 10:48 PM h4. Attachments







chai gravatar imagechai ( 2008-12-06 22:47:28 -0500 )edit

Any ApplicationContext bean that implements the SpaceBeforeBackupListener , SpaceAfterBackupListener , SpaceBeforePrimaryListener ,SpaceAfterPrimaryListener will be triggered.

You can explicitly register for space mode events via the ISpaceModeListener:

            ISpaceModeListener remoteListener = (ISpaceModeListener) clusterMemberSpace.getStubHandler().exportObject(appContextPrimaryBackupListener);
            currentSpaceMode = ((IInternalRemoteJSpaceAdmin) clusterMemberSpace.getAdmin()).addSpaceModeListener(remoteListener);

See the org.openspaces.core.space.AbstractSpaceFactoryBean source code for details.

Shay h4. Attachments







shay hassidim gravatar imageshay hassidim ( 2008-12-07 06:02:21 -0500 )edit

Hello Jin,

A processing unit automatically inherits the status from it's embedded space. So, if you deploy a processing unit with embedded space in a topology of primary/backup, the processing unit which has the primary space in it will act as the primary and the second one, the one that contains a backup space as in it will act as a stand by, and only when the primary unit fails, it will automatically start to work as the primary.

Cheers, Guy

answered 2008-12-05 01:09:19 -0500

nirpaz gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2008-12-04 22:06:24 -0500

Seen: 69 times

Last updated: Dec 05 '08