KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > aop > AOPInstance


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.aop;
8
9 import java.io.Serializable JavaDoc;
10
11 /**
12  * Wrapper type for cached AOP instances.
13  * When an object is looked up or put in TreeCacheAOP, this object will be advised with a CacheInterceptor.
14  * The tree cache stores a reference to this object (for example to update the instance variables, etc.).
15  * Since this reference need to be transactional but never replicated (the reference is only valid within the VM)
16  * this reference is wrapped into an AOPInstance.
17  * In addition, this instance also serves as a metadata for TreeCacheAop. E.g., it has a reference count for
18  * multiple references and reference FQN.
19  *
20  * @author Harald Gliebe
21  * @author Ben Wang
22  */

23 public class AOPInstance implements Serializable JavaDoc
24 {
25 // protected static Logger logger_ = Logger.getLogger(AOPInstance.class.getName());
26
/**
27     * Key under which the AOPInstance is stored in a Node's map.
28     */

29    // Use the class as key to avoid name clashes
30
// public static final Object KEY = AOPInstance.class;
31
public static final Object JavaDoc KEY = "AOPInstance";
32
33    // The instance is transient to avoid reflecation outside the VM
34
protected transient Object JavaDoc instance_;
35
36    // If not null, it signifies that this is a reference that points to this fqn.
37
// Note that this will get replicated.
38
protected String JavaDoc refFqn_ = null;
39
40    protected int refCount_ = 0; // reference counting. THis will get replicated as well.
41

42    public AOPInstance()
43    {
44    }
45
46    public AOPInstance(Object JavaDoc instance)
47    {
48       set(instance);
49    }
50
51    Object JavaDoc get()
52    {
53       return instance_;
54    }
55
56    void set(Object JavaDoc instance)
57    {
58       instance_ = instance;
59    }
60
61    String JavaDoc getRefFqn()
62    {
63       return refFqn_;
64    }
65
66    void setRefFqn(String JavaDoc refFqn)
67    {
68       refFqn_ = refFqn;
69    }
70
71    void removeRefFqn()
72    {
73       refFqn_ = null;
74    }
75
76    int incrementRefCount()
77    {
78       refCount_ += 1;
79 //logger_.info("incrementRefCount(): current ref count " +refCount_);
80
return refCount_;
81    }
82
83    int decrementRefCount()
84    {
85       refCount_ -= 1;
86 //logger_.info("decrementRefCount(): current ref count " +refCount_);
87
return refCount_;
88    }
89
90    int getRefCount()
91    {
92       return refCount_;
93    }
94 }
95
Popular Tags