[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]
Terracotta for Standalone Spring Applications..  XML
Forum Index -> Terracotta for Spring
Author Message
kumars

neo

Joined: 12/01/2006 07:34:08
Messages: 6
Offline

Hi,

All the samples that comes with Terracotta Spring uses Tomcat . I am trying to Cluster a Standalone Spring App..

When i start the Terracotta Spring server it reads the context info from tc-config.xml file.. Is there a way to pass this file at run time as an argument ? Or i have to use the tc-config.xml ??

And Does Terracotta takes care of load balancing ??

Thanks
kumar
grose

journeyman

Joined: 08/04/2006 07:58:08
Messages: 17
Location: Terracotta, Inc.
Offline

Hi kumars,

Please take a look at

http://www.terracottatech.com/forums/posts/list/79.page

It describes how what you are describing would work. Essentially, the answer to loading the context at runtime is yes, but there are some caveats.

With regards to load balancing, out of the box, Terracotta does not do load balancing per se. However, we open-sourced a grid using Terracotta that can easily be implemented in Spring and designed to do load balancing -- by which in this scenario, I would mean parition the processing logically so each node has a roughly equivalent amount of work to do. The grid and other tutorials are located at:

http://www.terracottatech.com/tutorials.shtml

Regards,

Gordon

Gordon Rose
Sr. Systems Engineer
Terracotta, Inc.
kumars

neo

Joined: 12/01/2006 07:34:08
Messages: 6
Offline

Hi,

I tried running a sample standalone app using Terracotta and i am not sure the Bean that i have declared in the config is shared..

My TC Server config File is:

Code:
     <tc:tc-config
     xmlns:tc="http://www.terracottatech.com/config-v1">
     <system>
      <jdbc-enabled>false</jdbc-enabled>
      <dso-enabled>true</dso-enabled>
    </system>
     <application>
       		<spring>
      			<jee-application name="*">
      				<application-contexts>
      					<application-context>
      						<paths>
 	<path>conf/applicationContext.xml</path>
 	</paths>
 	<beans>
 	<bean name="MyBean" />
 	</beans>
      					</application-context>
      				</application-contexts>
      			</jee-application>
      		</spring>
      	</application>
 
 </tc:tc-config>
 


And my Spring Config File :
Code:
 
   <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
  
    <bean id="MyBean" class="com.clusterTest.MyBean"/>
  
  </beans>
 


Source Code in Simple Bean:
Code:
 package com.lmco.clusterTest;
 
 public class MyBean {
 	
 	
 	private String message="DEFAULT MESSAGE";
 	
 	public String getMessage() {
 		return message;
 	}
 	public void setMessage(String message) {
 		this.message = message;
 	}
 }
 


And i am using the script start-demo-server.bat that comes with spring samples (The above modified tc-config.xml is located in the same directory)

Now i am running a JUnit Test
Code:
 
  public class LaunchContainer extends  AbstractDependencyInjectionSpringContextTests{
 
 	protected String[] getConfigLocations() {
 		// TODO Auto-generated method stub
 		return new String[]{"conf/applicationContext.xml"};
 	}
 	public void testContainer(){
 		assertNotNull(applicationContext);
 		assertNotNull(applicationContext.getBean("MyBean"));
 		System.out.println(((MyBean)applicationContext.getBean("MyBean")).getMessage());
 		MyBean myBean =(MyBean)applicationContext.getBean("MyBean");
 		myBean.setMessage("NEW_MESSAGE @"+new Date().getTime());
 		System.out.println(((MyBean)applicationContext.getBean("MyBean")).getMessage());		
 	}
 }
 


And when i run the above code twice i am getting the same output (except that the timestamp changes)..

Code:
 log4j:WARN No appenders could be found for logger (LaunchContainer).
 log4j:WARN Please initialize the log4j system properly.
 DEFAULT MESSAGE
 NEW_MESSAGE @1164999190124
 


When i run the above test for the first time SpringContainer gets instantiated it creates the Bean (MyBean which is shared across the cluster)
And when i run the above test second time am i supposed to get the Bean from the Cluster ?? (If thats the case How does the Spring Container knows not to create this Bean and get it from the Cluster instead ??)

Am i supposed to run the Test Case in a Special way ?? ( providing some jar in the class path etc ??)

Thanks
Kumar
kumars

neo

Joined: 12/01/2006 07:34:08
Messages: 6
Offline

Hi,

I realized that i need to run using dso-java or pass few arguments while running using java..Now everything seems to be running fine except that the Bean is not shared in the cluster..

Now the code i am running from the client is



Code:
 
 public class MyBeanTest {
 
 
 	public static void main(String[] s){
 		
 		ClassPathXmlApplicationContext appContext= new ClassPathXmlApplicationContext("conf/applicationContext.xml");
 		
 		MyBean bean =(MyBean)appContext.getBean("MyBean");
 		System.out.print(bean.getMessage());
 		bean.setMessage("NEW_MESSAGE");
 		System.out.print(bean.getMessage());
 		
 		
 	}
 }
   


When i ran it couple of times i got the following out put

Code:
C:\core-spring\software\eclipse-workspace\SpringTest>dso-java -Dtc.config=d:\tc-config.xml MyBeanTest
 
 C:\core-spring\software\eclipse-workspace\SpringTest>echo off
 Using the Terracotta home path specified in the
 TC_INSTALL_DIR environment variable, 'D:\Program Files\Terracotta\terracotta-2.1.3\spring\bin\..\..'.
 Using the built-in Terracotta JRE at D:\Program Files\Terracotta\terracotta-2.1.3\spring\bin\..\..\jre\bin\java.exe.
 2006-12-01 15:55:22,619 INFO - This is Terracotta, version 2.1.3 as of 20061012-151035.
 2006-12-01 15:55:23,338 INFO - Configuration successfully found and loaded from the file at 'd:\tc-config.xml'.
 2006-12-01 15:55:23,369 INFO - Log file is now: 'C:\core-spring\software\eclipse-workspace\SpringTest\logs-158.187.142.1
 98\terracotta-client.log'.
 Dec 1, 2006 3:55:25 PM org.springframework.core.CollectionFactory <clinit>
 INFO: JDK 1.4+ collections available
 Dec 1, 2006 3:55:26 PM com.tcspring.ApplicationHelper <init>
 INFO: Application name Standard.system
 Dec 1, 2006 3:55:26 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
 INFO: Loading XML bean definitions from class path resource [conf/applicationContext.xml]
 Dec 1, 2006 3:55:26 PM com.tcspring.DistributableBeanFactoryMixin determineIfClustered
 INFO: 05000C00060B090F090D040B0D0D0501 found matching configuration for [conf/applicationContext.xml]
 Dec 1, 2006 3:55:26 PM com.tcspring.DistributableBeanFactoryMixin determineIfClustered
 INFO: 05000C00060B090F090D040B0D0D0501 Context is distributed
 Dec 1, 2006 3:55:26 PM org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
 INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=
 2825055]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [MyBean]; root of BeanFact
 ory hierarchy
 Dec 1, 2006 3:55:26 PM org.springframework.context.support.AbstractApplicationContext refresh
 INFO: 1 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCod
 e=2825055]
 Dec 1, 2006 3:55:26 PM org.springframework.context.support.AbstractApplicationContext initMessageSource
 INFO: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.Deleg
 atingMessageSource@15f43d]
 Dec 1, 2006 3:55:26 PM org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
 INFO: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springfra
 mework.context.event.SimpleApplicationEventMulticaster@3ff528]
 Dec 1, 2006 3:55:26 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
 INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defi
 ning beans [MyBean]; root of BeanFactory hierarchy]
 DEFAULT MESSAGENEW_MESSAGE


And the output when i ran it second time..

Code:
C:\core-spring\software\eclipse-workspace\SpringTest>echo off
 Using the Terracotta home path specified in the
 TC_INSTALL_DIR environment variable, 'D:\Program Files\Terracotta\terracotta-2.1.3\spring\bin\..\..'.
 Using the built-in Terracotta JRE at D:\Program Files\Terracotta\terracotta-2.1.3\spring\bin\..\..\jre\bin\java.exe.
 2006-12-01 15:55:42,119 INFO - This is Terracotta, version 2.1.3 as of 20061012-151035.
 2006-12-01 15:55:42,837 INFO - Configuration successfully found and loaded from the file at 'd:\tc-config.xml'.
 2006-12-01 15:55:42,884 INFO - Log file is now: 'C:\core-spring\software\eclipse-workspace\SpringTest\logs-158.187.142.
 98\terracotta-client.log'.
 Dec 1, 2006 3:55:45 PM org.springframework.core.CollectionFactory <clinit>
 INFO: JDK 1.4+ collections available
 Dec 1, 2006 3:55:45 PM com.tcspring.ApplicationHelper <init>
 INFO: Application name Standard.system
 Dec 1, 2006 3:55:45 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
 INFO: Loading XML bean definitions from class path resource [conf/applicationContext.xml]
 Dec 1, 2006 3:55:46 PM com.tcspring.DistributableBeanFactoryMixin determineIfClustered
 INFO: 05000C00060B090F090D040B0D0D0501 found matching configuration for [conf/applicationContext.xml]
 Dec 1, 2006 3:55:46 PM com.tcspring.DistributableBeanFactoryMixin determineIfClustered
 INFO: 05000C00060B090F090D040B0D0D0501 Context is distributed
 Dec 1, 2006 3:55:46 PM org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
 INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode
 16856002]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [MyBean]; root of BeanFa
 tory hierarchy
 Dec 1, 2006 3:55:46 PM org.springframework.context.support.AbstractApplicationContext refresh
 INFO: 1 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCo
 e=16856002]
 Dec 1, 2006 3:55:46 PM org.springframework.context.support.AbstractApplicationContext initMessageSource
 INFO: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.Dele
 atingMessageSource@11c2c15]
 Dec 1, 2006 3:55:46 PM org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
 INFO: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springfr
 mework.context.event.SimpleApplicationEventMulticaster@126c1c6]
 Dec 1, 2006 3:55:46 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
 INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory def
 ning beans [MyBean]; root of BeanFactory hierarchy]
 DEFAULT MESSAGENEW_MESSAGE


Why the Bean State is not peristed when i invoked the second time..As i have set the Message to NEW_MESSAGE in my first invocation i should get this message when i ran it second time !!

Thanks
Kumar
kumars

neo

Joined: 12/01/2006 07:34:08
Messages: 6
Offline

Hi all,

Is it mandatory that at least one instance of the Cluster has to be up and running inorder to have the shared objects maintained by the TC Server ??

Thanks
Kumar
ekulesho

master

Joined: 12/04/2006 08:49:08
Messages: 57
Offline

As long as coordination server keep running you can bring down all client nodes.

What is happening in your test that you are resetting your message with the default one on application startup. You should be able to see the difference if you change your bean like this:

Code:
public class MyBean {	
   private String message;
 
   public String getMessage() {
     return message==null ? "DEFAULT MESSAGE" : message;
   }
   public void setMessage(String message) {
     this.message = message;
   }
 }


[WWW]
ekulesho

master

Joined: 12/04/2006 08:49:08
Messages: 57
Offline

One more thing you can try. After running your test, run an admin GUI (spring\bin\tc-admin.bat|sh). There you can check if your MyBean is under one of the roots, and should be able to see message value there.
[WWW]
kumars

neo

Joined: 12/01/2006 07:34:08
Messages: 6
Offline

Hi,

Thanks for your reply..

I modife the Code as you suggested
Code:
 
 public class MyBean {
 	
 	
 	private String message;
 	
 	public String getMessage() {
 		return message==null ? "DEFAULT MESSAGE .." : message;
 	}
 	public void setMessage(String message) {
 		this.message = message;
 	}
 	
 	public MyBean(){
 		
 		System.out.println(" Here in MyBean() .");
 	}
 }
 


Ran the Sample Test Case twice using
> dso-java -Dtc.config=d:\tc-config.xml MyBeanTest

Code:
 C:\core-spring\software\eclipse-workspace\SpringTest>echo off
 Using the Terracotta home path specified in the
 TC_INSTALL_DIR environment variable, 'D:\Program Files\Terracotta\terracotta-2.1.3\spring\bin\..\..'.
 Using the built-in Terracotta JRE at D:\Program Files\Terracotta\terracotta-2.1.3\spring\bin\..\..\jre\bin\java.exe.
 2006-12-04 12:09:52,271 INFO - This is Terracotta, version 2.1.3 as of 20061012-151035.
 2006-12-04 12:09:53,006 INFO - Configuration successfully found and loaded from the file at 'd:\tc-config.xml'.
 2006-12-04 12:09:53,037 INFO - Log file is now: 'C:\core-spring\software\eclipse-workspace\SpringTest\logs-158.187.142.1
 98\terracotta-client.log'.
 Dec 4, 2006 12:09:55 PM org.springframework.core.CollectionFactory <clinit>
 INFO: JDK 1.4+ collections available
 Dec 4, 2006 12:09:55 PM com.tcspring.ApplicationHelper <init>
 INFO: Application name Standard.system
 Dec 4, 2006 12:09:55 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
 INFO: Loading XML bean definitions from class path resource [conf/applicationContext.xml]
 Dec 4, 2006 12:09:56 PM com.tcspring.DistributableBeanFactoryMixin determineIfClustered
 INFO: 05000C00060B090F090D040B0D0D0501 found matching configuration for [conf/applicationContext.xml]
 Dec 4, 2006 12:09:56 PM com.tcspring.DistributableBeanFactoryMixin determineIfClustered
 INFO: 05000C00060B090F090D040B0D0D0501 Context is distributed
 Dec 4, 2006 12:09:56 PM org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
 INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=
 31084616]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [MyBean]; root of BeanFac
 tory hierarchy
 Dec 4, 2006 12:09:56 PM org.springframework.context.support.AbstractApplicationContext refresh
 INFO: 1 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCod
 e=31084616]
 Dec 4, 2006 12:09:56 PM org.springframework.context.support.AbstractApplicationContext initMessageSource
 INFO: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.Deleg
 atingMessageSource@14f895c]
 Dec 4, 2006 12:09:56 PM org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
 INFO: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springfra
 mework.context.event.SimpleApplicationEventMulticaster@1ac9e07]
 Dec 4, 2006 12:09:56 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
 INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defi
 ning beans [MyBean]; root of BeanFactory hierarchy]
  Here in MyBean() .
 DEFAULT MESSAGE ..
 NEW_MESSAGE
 


Output when i ran second time..

Code:
 
 C:\core-spring\software\eclipse-workspace\SpringTest>dso-java -Dtc.config=d:\tc-config.xml MyBeanTest
 
 C:\core-spring\software\eclipse-workspace\SpringTest>echo off
 Using the Terracotta home path specified in the
 TC_INSTALL_DIR environment variable, 'D:\Program Files\Terracotta\terracotta-2.1.3\spring\bin\..\..'.
 Using the built-in Terracotta JRE at D:\Program Files\Terracotta\terracotta-2.1.3\spring\bin\..\..\jre\bin\java.exe.
 2006-12-04 12:10:01,271 INFO - This is Terracotta, version 2.1.3 as of 20061012-151035.
 2006-12-04 12:10:02,006 INFO - Configuration successfully found and loaded from the file at 'd:\tc-config.xml'.
 2006-12-04 12:10:02,037 INFO - Log file is now: 'C:\core-spring\software\eclipse-workspace\SpringTest\logs-158.187.142.1
 98\terracotta-client.log'.
 Dec 4, 2006 12:10:04 PM org.springframework.core.CollectionFactory <clinit>
 INFO: JDK 1.4+ collections available
 Dec 4, 2006 12:10:04 PM com.tcspring.ApplicationHelper <init>
 INFO: Application name Standard.system
 Dec 4, 2006 12:10:04 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
 INFO: Loading XML bean definitions from class path resource [conf/applicationContext.xml]
 Dec 4, 2006 12:10:05 PM com.tcspring.DistributableBeanFactoryMixin determineIfClustered
 INFO: 05000C00060B090F090D040B0D0D0501 found matching configuration for [conf/applicationContext.xml]
 Dec 4, 2006 12:10:05 PM com.tcspring.DistributableBeanFactoryMixin determineIfClustered
 INFO: 05000C00060B090F090D040B0D0D0501 Context is distributed
 Dec 4, 2006 12:10:05 PM org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
 INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=
 3337915]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [MyBean]; root of BeanFact
 ory hierarchy
 Dec 4, 2006 12:10:05 PM org.springframework.context.support.AbstractApplicationContext refresh
 INFO: 1 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCod
 e=3337915]
 Dec 4, 2006 12:10:05 PM org.springframework.context.support.AbstractApplicationContext initMessageSource
 INFO: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.Deleg
 atingMessageSource@ee7247]
 Dec 4, 2006 12:10:05 PM org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
 INFO: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springfra
 mework.context.event.SimpleApplicationEventMulticaster@154745e]
 Dec 4, 2006 12:10:05 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
 INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defi
 ning beans [MyBean]; root of BeanFactory hierarchy]
  Here in MyBean() .
 DEFAULT MESSAGE ..
 NEW_MESSAGE
 


I am able to see my Bean (MyBean) in the Terracotta Admin Console but not the message..!! This is what i see under the Roots

Code:
 tc:spring_info:05000C00060B090F090D040B0D0D0501 (java.util.ArrayList) [4/4]
 0 (com.tcspring.ApplicationContextEventProtocol)
 com.tcspring.ApplicationContextEventProtocol.appName (java.lang.String)=Standard.system
 com.tcspring.ApplicationContextEventProtocol.beanNames (java.util.ArrayList) [1/1]
 0 (java.lang.String)=MyBean
 com.tcspring.ApplicationContextEventProtocol.configs (java.util.ArrayList) [1/1]
 0 (java.lang.String)=conf/applicationContext.xml
 com.tcspring.ApplicationContextEventProtocol.eventTypes (java.util.ArrayList) [0/0]
 1 (com.tcspring.ApplicationContextEventProtocol)
 com.tcspring.ApplicationContextEventProtocol.appName (java.lang.String)=Standard.system
 com.tcspring.ApplicationContextEventProtocol.beanNames (java.util.ArrayList) [1/1]
 com.tcspring.ApplicationContextEventProtocol.configs (java.util.ArrayList) [1/1]
 com.tcspring.ApplicationContextEventProtocol.eventTypes (java.util.ArrayList) [0/0]
 2 (com.tcspring.ApplicationContextEventProtocol)
 com.tcspring.ApplicationContextEventProtocol.appName (java.lang.String)=Standard.system
 com.tcspring.ApplicationContextEventProtocol.beanNames (java.util.ArrayList) [1/1]
 com.tcspring.ApplicationContextEventProtocol.configs (java.util.ArrayList) [1/1]
 com.tcspring.ApplicationContextEventProtocol.eventTypes (java.util.ArrayList) [0/0]
 3 (com.tcspring.ApplicationContextEventProtocol)
 com.tcspring.ApplicationContextEventProtocol.appName (java.lang.String)=Standard.system
 com.tcspring.ApplicationContextEventProtocol.beanNames (java.util.ArrayList) [1/1]
 0 (java.lang.String)=MyBean
 com.tcspring.ApplicationContextEventProtocol.configs (java.util.ArrayList) [1/1]
 0 (java.lang.String)=conf/applicationContext.xml
 com.tcspring.ApplicationContextEventProtocol.eventTypes (java.util.ArrayList) [0/0]
 


Thanks
Kumar
ekulesho

master

Joined: 12/04/2006 08:49:08
Messages: 57
Offline

kumars wrote:
Thanks for your reply..
I modife the Code as you suggested 
Please disregard my comment about initial field value. It wasn't correct.

Anyways, I've tried to reproduce this and find out that for some reason application context wasn't clustered. That is why you don't see it in admin tool.

However, after I downloaded latest Terracotta release from Open Terracotta (by the way, as of today it is open source) and was able to successfully run your example with couple of changes:

-- namespace in tc-config changed to http://www.terracotta.org/config
-- getMessage() and setMessage() methods should declare locks, other wise you'll get UnlockedSharedObjectException. So, you can do that in tc-config. You can also make these method synchronized (or synchronize on "this" instance), then Terracotta will automatically apply autolock on these methods.

There is one minor glitch. You need to include javax/servlet/http/HttpSession class into your classpath (i.e. servlet-api.jar). I filled a JIRA issue CDV-23 about that.

regards,
Eugene
[WWW]
kumars

neo

Joined: 12/01/2006 07:34:08
Messages: 6
Offline

Hi Eugene,

Thanks so much..I just downloaded the latst version (2.2) and everything is working fine..
Yes you are right i need to have the servlet jar in my classpath ..

Thanks
Kumar
 
Forum Index -> Terracotta for Spring
Go to:   
Powered by JForum 2.1.7 © JForum Team