smartfox - terracotta - (appserver|console)

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
fmachado
Posts: 3
Joined: 26 May 2010, 18:16

smartfox - terracotta - (appserver|console)

Post by fmachado »

Hi guys,

I'm having an issue sharing objects between different JVMs and I would like to know if I'm doing something wrong.

Scenario
(serverA) Smartfox
(ServerB) Smartfox
(ServerC) GeronimoAppserver (or Tomcat, JBoss, Jetty, ...)
(ServerD) consoleApp
All servers are Terracotta clients.

How they work
The first server to connect to the cluster will fill a shared ROOT (e.g. a Map). For example, let's share a

Code: Select all

Map<String, Car> carMap = ConcurrentHashMap<String, Car>();
(serverC) is the first one, so it will carMap.put("key1", new Car()). Let's connect the remaining Terracotta clients (serverA, serverB and serverD). As they can perfectly connect to the cluster and "see" the ROOT object, you can do from any client System.out.println(carMap.size()) and it'll print 1.

Welcome to my classloader hell
It seems to be impossible to retrieve an item from a collection using serverA or serverB because their classloaders (both from Smartfox) are different than serverC (appServer):

SmartFoxServer ClassLoader: sun.misc.Launcher$AppClassLoader
Geronimo ClassLoader: org.apache.geronimo.kernel.config.MultiParentClassLoader

If I'm not wrong, Terracotta uses the entire object signature (i.e. namespace + Full Qualified Name) to store and share objects between different JVMs. And about that Map, guess what happens when I execute the following code on serverC:

Code: Select all

// model.Car
Car obj1 = new Car(); // line 1
Car obj2 = carMap.get("key1"); // line 2
It throws an exception when I try to get an item from carMap (line 2). If I'm not wrong, the object stored has a signature like SmartFoxClassLoader.model.Car and when I'm trying to get it from Map, the appServer JVM is trying to access an object with a signature MultiParentClassLoader.model.Car.

Code: Select all

...
Caused by: com.tc.exception.TCClassNotFoundException: java.lang.ClassNotFoundException: model.Car
        at com.tc.object.ClientObjectManagerImpl.lookupOrCreateRoot(ClientObjectManagerImpl.java:651)
        at com.tc.object.bytecode.ManagerImpl.lookupOrCreateRoot(ManagerImpl.java:370)
        at com.tc.object.bytecode.ManagerImpl.lookupOrCreateRoot(ManagerImpl.java:349)
        at com.tc.object.bytecode.ManagerUtil.lookupOrCreateRoot(ManagerUtil.java:151)
...
Quoted from Terracotta docs:
ClassCastException or ClassNotFoundException
These errors can be caused when differing clustered applications share object graphs but use different classloaders.
These errors can also be caused when a running web application is redeployed, such as when its container detects a change to a context file. Terracotta does not support "hot" redeployment of web applications.
Smartfox using a custom ClassLoader
We tried to adapt and use the MultiParentClassLoader, booting all classes (e.g. model.Car) shared between JVMs. The remaining classes (smartfox and libs) would be loaded by the parent classloader (sun.misc.Launcher$AppClassLoader). It didn't work. :cry:

So, the big question is: what I'm doing wrong? Any help will be greatly appreciated. :-)

Cheers,

Fernando
Post Reply