[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Is TC4Spring suits my need  XML
Forum Index -> Terracotta for Spring
Author Message
mouadbox

neo

Joined: 09/13/2006 06:58:37
Messages: 8
Location: MGP
Offline

Hi all,

I am definitly new to TC4Spring, so please any help is welcome.

I am working on a mediation platform, let's say a mutlithreaded application. Now we desided to add cluster functionnalities to our platform.

Just to describe the medplat :

There are several threads, each of them responsible for a task, on more to thing to mentione in case the developper want to communicate some of those thread with each he can use different kind of queues (no XA, XA, JMS, ...).

Where Spring stands :
Spring is used to create the application flow (Beans creations), through the use of its IoC.

A need to cluster :
To extend the platform, robustness/availability/speed we came to the importance of clustering it. So we dig searching on the subject

So here is my question :
Can we cluster threads with TC4Spring ?
Some of them should be on hot standby, other cold standby, can TC4Spring provide both options ?

Thank in advance for you help.

Mouad.
[Yahoo!]
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

Hi Mouad.

Thank you for your interest in Terracotta for Spring.

I believe TC for Spring can help you. While you cannot directly cluster threads, you can cluster the datastructures that the threads use to communicate with the rest of the application.

As an example, a very common pattern is to create a thread that takes items from a queue and runs them.

A sample class file would be something like:

Code:
 public class MyExecutor implements Runnable
 {
     private BlockingQueue<Runnable> queue;
 
     public MyExecutor(BlockingQueue<Runnable> queue) 
     {
         this.queue = queue;
     }
 
     public void run()
     {
         while (true) {
             try {
                queue.take().run();
             } catch (InterruptedException e) { 
                // foo
             } 
         }
     }
 }
 


And then, somewhere else in the code, you would start this by:

Code:
 ...
 new Thread(new MyExecutor(myQueue)).start();
 ...
 


Using Terracotta to cluster this application, we would not cluster the Threads because threads are local to the JVM. We can, however, cluster the queue.

Using the queue as a clustered object, we can start as many threads as we like on each JVM in the cluster, and each will read one item and process the work.

A related example was written up in May by one of our architects, Jonas Boner, on the server side.

See his article here: http://www.theserverside.com/tt/articles/article.tss?l=DistCompute

I hope that helps!

Taylor
[WWW]
mouadbox

neo

Joined: 09/13/2006 06:58:37
Messages: 8
Location: MGP
Offline

Hi Taylor,

First of all, thanks for your reply.

In fact the arcticle is exactly the prupose I'd like to achieve.

Having several distributed instances of medplat specific implementation using queues.

The thing that I am not getting is, how can TC4Spring discover the desired datastructures from several machines (otherwise saying several JVM) ?

Let's draw a sample in order to make my ideas clear :

With a single instance of medplat, I'd like to list a folder for a certain file pattern, once matched a send the opened file to a parsing queue, which is the entry point for a parser.

MyTech medplat implementation
[DirectoryScanner --- if matched ----> ParserQueue ---> ParserWorker (onPut)] etc etc

Let's say, that we want to make this implementation as cluster of two or more nodes.

do you have an example of TC config that I can follow to make this impl as cluster ?

How does TC4Spring discover this impl if installed in several physical machines/servers ?

Any help is welcome, thanks in advance.

Mouad.



[Yahoo!]
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

Mouad,

Since you are inquiring about TC for Spring, I will explain how TC for Spring will make this happen.

When you start the VM on the clustered nodes, TC is the first thing that is loaded (before the Java VM loads any other classes, TC starts).

TC requires a configuration file, just as Jonas describes in his paper.

In this configuration file, you can declare that beans which are instantiated via Spring are shared across the cluster. These beans should be declared as singletons.

Terracotta preserves the semantics of the singleton bean across the cluster. Thus in the multi-VM case, just like in the single VM case, a singleton bean is the same for any thread that requests it by name from the application context, no matter which VM or which thread is requesting it.

Given the singleton bean pattern, all you need to do is to instantiate a queue as a bean via Spring, and declare in the Terracotta configuration file that this bean should be shared by Terracotta.

A snippet of the config file would be something like:
Code:
               <application-contexts>
                   <application-context>
                       <paths>
                           <path>MyApplication.xml</path>
                       </paths>
                       <beans>
                           <bean name="queue"/>
                       </beans>
                   </application-context>
               </application-contexts>
 


In the example above, I would write two classes that represent the two sides of the cluster - the writing side (that initiates the work) and the reading (that performs the work).

In the writing side, I would have a main method that starts up, retrieves the application context and the queue bean, and then generates work and places the work on the queue.

On the reading side, I would have a main method that starts up, retrieves the application context and the queue bean, and then begins to read items off of the queue, much as I described in my earlier post.

(Note that this is slightly different from Jonas' paper. In Jonas' version all cluster nodes are equal and each will perform reading and writing.)

Hope that helps,

Taylor
[WWW]
 
Forum Index -> Terracotta for Spring
Go to:   
Powered by JForum 2.1.7 © JForum Team