KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > bean > MasterBean


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest.spring.bean;
5
6 import org.springframework.beans.factory.InitializingBean;
7
8 import java.util.ArrayList JavaDoc;
9 import java.util.List JavaDoc;
10
11 public class MasterBean implements IMasterBean, InitializingBean {
12
13   private List JavaDoc sharedSingletons = new ArrayList JavaDoc();
14   private ISingleton singleton;
15   private List JavaDoc values = new ArrayList JavaDoc();
16   
17   public void afterPropertiesSet() {
18     sharedSingletons.add(singleton);
19   }
20   
21   public ISingleton getSingleton() {
22     return singleton;
23   }
24   
25   public void setSingleton(ISingleton singleton) {
26     this.singleton = singleton;
27   }
28   
29   public void addValue(String JavaDoc value) {
30     synchronized (this) {
31       this.values.add(value);
32     }
33   }
34
35   public List JavaDoc getValues() {
36     synchronized(this) {
37       return values;
38     }
39   }
40   
41   /**
42    * Verify
43    * 1. If the 2nd Node uses the shared singleton instead of create another copy
44    * 2. If the a roundtrip of the shared object retains the semantics for ==
45    */

46   public boolean isTheSameSingletonReferenceUsed() {
47     // assume 2 nodes; otherwise let them throw exception
48
return sharedSingletons.get(0) == sharedSingletons.get(1);
49   }
50 }
51
52
Popular Tags