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.tcspring;
05:
06: import org.springframework.beans.factory.config.Scope;
07:
08: /**
09: * Destruction callback for distributed scoped beans
10: *
11: * @see Scope#registerDestructionCallback(String, Runnable)
12: *
13: * @author Eugene Kuleshov
14: */
15: public class ScopedBeanDestructionCallBack implements Runnable {
16: private ComplexBeanId beanId;
17: private transient DistributableBeanFactory beanFactory;
18: private transient Runnable callback;
19:
20: public ScopedBeanDestructionCallBack(ComplexBeanId beanId,
21: DistributableBeanFactory factory, Runnable callback) {
22: this .beanId = beanId;
23: this .beanFactory = factory;
24: this .callback = callback;
25: }
26:
27: public ComplexBeanId getBeanId() {
28: return beanId;
29: }
30:
31: public void setCallback(Runnable callback) {
32: this .callback = callback;
33: }
34:
35: public Runnable getCallback() {
36: return callback;
37: }
38:
39: public void setBeanFactory(DistributableBeanFactory beanFactory) {
40: this .beanFactory = beanFactory;
41: }
42:
43: public DistributableBeanFactory getBeanFactory() {
44: return beanFactory;
45: }
46:
47: public void run() {
48: try {
49: if (callback != null) {
50: callback.run();
51: }
52: } finally {
53: if (beanFactory != null) {
54: beanFactory.removeBeanContainer(beanId);
55: }
56: }
57: }
58: }
|