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.DisposableBean;
07: import org.springframework.beans.factory.InitializingBean;
08: import org.springframework.context.ApplicationContext;
09: import org.springframework.context.ApplicationContextAware;
10: import org.springframework.beans.factory.BeanNameAware;
11: import org.springframework.context.support.AbstractApplicationContext;
12:
13: import com.tc.aspectwerkz.proxy.Uuid;
14:
15: import java.util.ArrayList;
16: import java.util.List;
17:
18: public class LifeCycleBean implements InitializingBean,
19: ApplicationContextAware, BeanNameAware, DisposableBean,
20: ILifeCycle {
21: private transient long mSystemId;
22:
23: private List mProp;
24:
25: private List mInvocationRecords = new ArrayList();
26: private transient ApplicationContext mAppCtx = null;
27: private transient String mBeanName = null;
28:
29: public LifeCycleBean() {
30: mSystemId = System.identityHashCode(this ) + Uuid.newUuid();
31: }
32:
33: public long getSystemId() {
34: return mSystemId;
35: }
36:
37: synchronized public List getInvocationRecords() {
38: return mInvocationRecords;
39: }
40:
41: /**
42: * Is this method within a synchronization block ????
43: */
44: public void afterPropertiesSet() {
45: // this property will be initialized and shared
46: mProp.add("" + mSystemId);
47: this .mInvocationRecords.add("afterPropertiesSet-" + mSystemId);
48: System.err.println("afterPropertiesSet-" + mSystemId);
49: }
50:
51: /**
52: * Is this method within a synchronization block ????
53: */
54: public void setApplicationContext(
55: ApplicationContext applicationContext) {
56: mAppCtx = applicationContext;
57: this .mInvocationRecords.add("setBeanName-" + mSystemId);
58: System.err.println("setBeanName-" + mSystemId);
59: }
60:
61: /**
62: * Is this method within a synchronization block ????
63: */
64: public void setBeanName(String beanName) {
65: mBeanName = beanName;
66: mInvocationRecords.add("setApplicationContext-" + mSystemId);
67: System.err.println("setApplicationContext-" + mSystemId);
68: }
69:
70: public void destroy() {
71: synchronized (this ) { // to avoid UnlockedSharedObjectException, this method is not in a synchronization block ???
72: mInvocationRecords.add("destroy-" + mSystemId);
73: }
74: }
75:
76: public void closeAppCtx() {
77: ((AbstractApplicationContext) mAppCtx).close();
78: }
79:
80: public List getProp() {
81: return mProp;
82: }
83:
84: public void setProp(List prop) {
85: mProp = prop;
86: }
87: }
|