FileDocCategorySizeDatePackage
ReferenceCounter.javaAPI DocApache Lucene 2.1.02132Wed Feb 14 10:46:04 GMT 2007org.apache.lucene.gdata.utils

ReferenceCounter

public abstract class ReferenceCounter extends Object
A reference counting utility. This is use to keep track of released objects of Type.
author
Simon Willnauer
param
- the type of the object

Fields Summary
protected final Type
resource
private AtomicInteger
refcounter
Constructors Summary
public ReferenceCounter(Type resource)

param
resource - the resource to track

 
 
                                 
        
        this.resource = resource; 
    
Methods Summary
protected abstract voidclose()
A custom implementation. Performs an action if no reference remaining

public final voiddecrementRef()
Decrements the reference. If no references remain the {@link ReferenceCounter#close()} method will be invoked;

 
        /*
         * close if less or equals 0
         */
        if (this.refcounter.decrementAndGet() <= 0) 
            close(); 
    
public final Typeget()

return
- the resource to keep track of

 
        return this.resource; 
    
public final org.apache.lucene.gdata.utils.ReferenceCounterincreamentReference()
Increments the reference

return
the reference object

 
        this.refcounter.incrementAndGet(); 
        return this;