All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.flowcomputing.commons.resgc.Holder Maven / Gradle / Ivy

There is a newer version: 0.8.17
Show newest version
package org.flowcomputing.commons.resgc;

import java.lang.ref.Reference;

/**
 * A interface that defines a holder. it is used to hold any kind of resource
 * and provide way to access its holden resource. In addition, it should allow
 * its resource to be destroyed manually ahead of GC.
 * 
 * @author wg
 *
 * @param  a resource type for its holder 
 */
public interface Holder> {
	
	/**
	 * get its holden resource. Note that it should not be used for assignment.
	 * 
	 * @return its holden resource
	 */
	public T get();

	/**
	 * set its holden resource.
	 * 
	 * @param mres
	 *            the holder will be set to a specified resource.
	 *
	 * Note: must unregister this holder before changing its managed 
	 *       resource.
	 */
	public void set(T mres);

	/**
	 * clear its managed resource
	 */
	public void clear();

	/**
	 * return whether it has managed resource
	 *
	 * @return if hold its managed resource
	 */
	public boolean hasResource();
		
	/**
	 * set collector.
	 * 
	 * @param collector
	 *            the collector to manage this holder.
	 */
	public void setCollector(Collector collector);
	
	/**
	 * set reference id.
	 * 
	 * @param rid
	 *            the reference id to be managed.
	 */
	public void setRefId(Reference rid);
	
	/**
	 * get its managed reference id.
	 * 
	 * @return its managed reference id
	 */
	public Reference getRefId();

	/**
	 * prevent resource from being reclaimed.
	 * 
	 */
	public void cancelAutoReclaim();
	
	/**
	 * destroy its holden resource and unregister from its collector.
	 * 
	 */
	public void destroy();
		
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy