[jboss-user] [JBossCache] - Re: PojoCache: java.lang.NoSuchMethodException: addObserver

chencao0524 do-not-reply at jboss.com
Wed Jan 10 07:05:14 EST 2007


Yes, I tried it outside of the AS and it work fine.
Test class

  | public class StudentMaintTest {
  | 
  | 	private Student joe_;
  | 
  | 	private Student mary_;
  | 
  | 	private Course foo_;
  | 
  | 	private Course bar_;
  | 
  | 	private Course c1;
  | 
  | 	private Course c2;
  | 
  | 	private Course c3;
  | 
  | 	private List<Course> couses = new ArrayList<Course>();
  | 
  | 	private List<String> ss = new ArrayList<String>();
  | 
  | 	// cache1 and cache2 are in the same clustering group.
  | 	private PojoCache cache1_;
  | 
  | 	private PojoCache cache2_;
  | 
  | 	public StudentMaintTest() {
  | 
  | 	}
  | 	
  | 	public void setUp() throws Exception {
  | 	      cache1_ = createCache("Messi2");
  | 	      cache2_ = createCache("Messi2");
  | 	      init();
  | 	   }
  | 
  | 	   public void tearDown() throws Exception {
  | 	      cache1_.remove("/");
  | 	      cache1_.stop();
  | 	      cache2_.stop();
  | 	   }
  | 
  | 	private PojoCache createCache(String name) {
  | 		try {
  | 			PojoCache tree = new PojoCache();
  | 			PropertyConfigurator config = new PropertyConfigurator(); 
  | 			config.configure(tree, "replSync-in-service.xml");
  | 			tree.setClusterName(name); // We can set a different cluster group.
  | 			tree.start(); // kick start the cache
  | 			return tree;
  | 		} catch (Exception ex) {
  | 			ex.printStackTrace();
  | 			return null;
  | 		}
  | 
  | 	}
  | 
  | 	protected void init() {
  | 
  | 		mary_ = new Student();
  | 		mary_.setName("Mary Smith");
  | 
  | 		Address address = new Address();
  | 		address.setStreet("456 Oak Drive");
  | 		address.setCity("Pleasantville, CA");
  | 		address.setZip(94555);
  | 
  | 		mary_.setAddress(address);
  | 
  | 		joe_ = new Student();
  | 		joe_.setName("Joe Smith");
  | 		joe_.setSchool("Engineering");
  | 
  | 		// Mary and Joe have the same address
  | 		joe_.setAddress(address);
  | 
  | 		foo_ = new Course();
  | 		foo_.setTitle("Intro to Foo");
  | 		foo_.setInstructor("Jones");
  | 
  | 		joe_.addCourse(foo_);
  | 		mary_.addCourse(foo_);
  | 
  | 		bar_ = new Course();
  | 		bar_.setTitle("Advanced Bar");
  | 		bar_.setInstructor("Woods");
  | 		bar_.setRoom("104 Encina");
  | 
  | 		c1 = new Course();
  | 		c1.setTitle("tttt 1");
  | 		c1.setInstructor("WWW 1");
  | 		c1.setRoom("rrrr 1");
  | 
  | 		c2 = new Course();
  | 		c2.setTitle("tttt 2");
  | 		c2.setInstructor("WWW 2");
  | 		c2.setRoom("rrrr 2");
  | 
  | 		c3 = new Course();
  | 		c3.setTitle("tttt 3");
  | 		c3.setInstructor("WWW 3");
  | 		c3.setRoom("rrrr 3");
  | 
  | 		couses.add(c1);
  | 		couses.add(c2);
  | 		couses.add(c3);
  | 
  | 		ss.add("11111111");
  | 		ss.add("222222222");
  | 		ss.add("333333333");
  | 	}
  | 
  | 	public void testPropagation() {
  | 		try {
  | 			// Here we ask the pojo cache to manage mary_ and joe_
  | 			cache1_.putObject("/students/54321", mary_);
  | 			cache1_.putObject("/students/65432", joe_);
  | 			cache1_.putObject("/courses/101", foo_);
  | 			cache1_.putObject("/courses/401", bar_);
  | 			cache1_.putObject("/courses/c1", c1);
  | 			cache1_.putObject("/courses/c2", c2);
  | 			cache1_.putObject("/courses/c3", c3);
  | 
  | 			cache1_.putObject("/string/ss", ss);
  | 			cache1_.putObject("/messi/0524", couses);
  | 
  | 			ss.add("44444444");
  | 			printStrings(ss);
  | 
  | 			couses.add(bar_);
  | 			printMessi(couses);
  | 			List<Course> cc = (List<Course>) cache2_.getObject("/messi/0524");
  | 			// printMessi(cc);
  | 
  | 			List<String> s2 = (List<String>) cache2_.getObject("/string/ss");
  | 			printStrings(s2);
  | 
  | 			// Output
  | 			printStatus("Initial state for Mary", mary_);
  | 			printStatus("Initial state for Joe", joe_);
  | 
  | 			// Retrieve the pojos from the Server #2
  | 			Student mary2 = (Student) cache2_.getObject("/students/54321");
  | 			Student joe2 = (Student) cache2_.getObject("/students/65432");
  | 			Course foo2 = (Course) cache2_.getObject("/courses/101");
  | 
  | 			System.out.println("---------------------------------------------");
  | 			System.out.println("Modified on Server #1");
  | 			// Change state in one of the items. This will be fine-grained
  | 			// replicated
  | 			foo_.setRoom("101 Alvarez"); // Modified state on cache #2
  | 			printStatus(
  | 					"Course Update: id: 401  room: null->101 Alvarez (retrieved from cache #2)",
  | 					foo2);
  | 
  | 			System.out.println("---------------------------------------------");
  | 			System.out.println("Modified on Server #2");
  | 			// Change state in one of the items. This will be fine-grained
  | 			// replicated
  | 			joe2.addCourse(bar_); // Modified state on cache #2
  | 			printStatus(
  | 					"Student Update: id: 65432  addCourse: Advanced Bar (retrieved from cache #1)",
  | 					joe_);
  | 
  | 			System.out.println("---------------------------------------------");
  | 			System.out.println("Modified on Server #1");
  | 			// Change state in one of the items. This will be fine-grained
  | 			// replicated.
  | 			mary_.setSchool("Engineering");
  | 			printStatus(
  | 					"Student Update: id: 65432  school: null->Engineering (retrieved from cache #2)",
  | 					mary2);
  | 
  | 			if (!mary_.getSchool().equals(mary2.getSchool())) {
  | 				throw new RuntimeException(
  | 						"School field is not replicated correctly. on cache1: "
  | 								+ mary_.getSchool() + " on cache2: "
  | 								+ mary2.getSchool());
  | 			}
  | 		} catch (Exception ex) {
  | 			ex.printStackTrace();
  | 		}
  | 
  | 	}
  | 
  | 	private void printStatus(String msg, Object obj) {
  | 		System.out.println("---------------------------------------------");
  | 		System.out.println(msg);
  | 		System.out.println("---------------------------------------------");
  | 		System.out.println(obj.toString());
  | 	}
  | 
  | 	private void printMessi(List<Course> cs) {
  | 		if (cs != null && !cs.isEmpty()) {
  | 			System.out.println("????????????size:" + cs.size());
  | 			for (Course c : cs) {
  | 				System.out.println(c);
  | 			}
  | 		}
  | 	}
  | 
  | 	private void printStrings(List<String> cs) {
  | 		if (cs != null && !cs.isEmpty()) {
  | 			System.out.println("????????????size:" + cs.size());
  | 			for (String c : cs) {
  | 				System.out.println(c);
  | 			}
  | 		}
  | 	}
  | 	
  | 	
  | 	public static void main(String[] args) throws Exception {
  | 	      StudentMaintTest smTest = new StudentMaintTest();
  | 	      smTest.setUp();
  | 	      smTest.testPropagation();
  | 	      smTest.tearDown();
  | 	   }
  | 
  | }
  | 
 
build.xml

  | <path id="build.classpath">
  | 		<pathelement location="${basedir}"/>
  | 		<fileset dir="${jboss.home}/lib">
  | 			<include name="**/*.jar"/>
  | 		</fileset>
  | 		<fileset dir="${jboss.home}/server/${jboss.server.config}/lib">
  | 			<include name="**/*.jar"/>
  | 		</fileset>
  | 		<fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/ejb3.deployer">
  | 			<include name="*.jar"/>
  | 		</fileset>
  | 		<fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/jboss-aop-jdk50.deployer">
  | 			<include name="*.jar"/>
  | 		</fileset>
  | 		<fileset dir="${lib.dir}">
  | 			<include name="**/*.jar"/>
  | 		</fileset>
  | 		<!--fileset dir="${cache.lib.50.dir}">
  | 			<include name="**/*.jar"/>
  | 		</fileset-->
  | 		<pathelement location="${classes.dao.dir}"/>
  | 		<pathelement location="${classes.web.dir}"/>
  | 		<pathelement location="${classes.test.dir}"/>
  | 		<pathelement location="${conf.hivemind.dir}"/>
  | 	</path>
  | 
  | <target name="run.pojo" depends="ejb3" description="run standalone server replicator.">
  |       <java classname="cn.net.ce.web.cache.pojo.StudentMaintTest" fork="yes">
  |          <classpath refid="build.classpath"/>
  |          <classpath path="${build.dir}"/>
  |          <classpath path="resources/sar/META-INF"/>
  |       </java>
  |    </target>
  | 

Thanks for your help, I will prepare the smallest application for you. Pls wait a moment. :-)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3999887#3999887

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3999887



More information about the jboss-user mailing list