KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tcspring > ScopedBeanDestructionCallBack


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.tcspring;
5
6 import org.springframework.beans.factory.config.Scope;
7
8 /**
9  * 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 JavaDoc {
16   private ComplexBeanId beanId;
17   private transient DistributableBeanFactory beanFactory;
18   private transient Runnable JavaDoc callback;
19   
20   public ScopedBeanDestructionCallBack(ComplexBeanId beanId, DistributableBeanFactory factory, Runnable JavaDoc callback) {
21     this.beanId = beanId;
22     this.beanFactory = factory;
23     this.callback = callback;
24   }
25
26   public ComplexBeanId getBeanId() {
27     return beanId;
28   }
29   
30   public void setCallback(Runnable JavaDoc callback) {
31     this.callback = callback;
32   }
33
34   public Runnable JavaDoc getCallback() {
35     return callback;
36   }
37   
38   public void setBeanFactory(DistributableBeanFactory beanFactory) {
39     this.beanFactory = beanFactory;
40   }
41   
42   public DistributableBeanFactory getBeanFactory() {
43     return beanFactory;
44   }
45   
46   public void run() {
47     try {
48       if(callback!=null) {
49         callback.run();
50       }
51     } finally {
52       if(beanFactory!=null) {
53         beanFactory.removeBeanContainer(beanId);
54       }
55     }
56   }
57 }
Popular Tags