01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest.spring.bean;
05:
06: import org.springframework.beans.factory.InitializingBean;
07:
08: import java.util.ArrayList;
09: import java.util.List;
10:
11: public class MasterBean implements IMasterBean, InitializingBean {
12:
13: private List sharedSingletons = new ArrayList();
14: private ISingleton singleton;
15: private List values = new ArrayList();
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 value) {
30: synchronized (this ) {
31: this .values.add(value);
32: }
33: }
34:
35: public List 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: }
|