Browse Source

refactoring of WeakishReference, as discussed.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@453274 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 18 years ago
parent
commit
8ed820fa86
2 changed files with 41 additions and 34 deletions
  1. +35
    -21
      src/main/org/apache/tools/ant/util/WeakishReference.java
  2. +6
    -13
      src/main/org/apache/tools/ant/util/optional/WeakishReference12.java

+ 35
- 21
src/main/org/apache/tools/ant/util/WeakishReference.java View File

@@ -18,24 +18,34 @@

package org.apache.tools.ant.util;

import org.apache.tools.ant.util.optional.WeakishReference12;

import java.lang.ref.WeakReference;

/**
* This is a weak reference on java1.2 and up, that is all
* platforms Ant1.6 supports.
* These classes are part of some code to reduce memory leaks by only retaining weak references to things
* on Java1.2+, and yet still work (with leaky hard references) on Java1.1. Now that Ant is 1.2+ only,
* life is simpler and none of the classes are needed any more.
*
* They are only retained in case a third-party task uses them
* @since ant1.6
* @deprecated since 1.7.
* @see org.apache.tools.ant.util.optional.WeakishReference12
* @deprecated deprecated 1.7; will be removed in Ant1.8
* Just use {@link java.lang.ref.WeakReference} directly.
*/
public abstract class WeakishReference {
public class WeakishReference {


private WeakReference weakref;

/**
* create the appropriate type of reference for the java version
* @param object the object that the reference will refer to.
* @return reference to the Object.
* create a new soft reference, which is bound to a
* Weak reference inside
*
* @param reference
* @see java.lang.ref.WeakReference
*/
public static WeakishReference createReference(Object object) {
return new WeakishReference12(object);
WeakishReference(Object reference) {
this.weakref = new WeakReference(reference);
}

/**
@@ -45,31 +55,35 @@ public abstract class WeakishReference {
* @return The object to which this reference refers, or
* <code>null</code> if this reference object has been cleared.
*/
public abstract Object get();
public Object get() {
return weakref.get();
}

/**
* create the appropriate type of reference for the java version
* @param object the object that the reference will refer to.
* @return reference to the Object.
*/
public static WeakishReference createReference(Object object) {
return new WeakishReference(object);
}


/**
* A hard reference for Java 1.1.
* This was a hard reference for Java 1.1. Since Ant1.7,
* @deprecated since 1.7.
* Hopefully nobody is using this.
*/
public static class HardReference extends WeakishReference {
private Object object;

/**
* constructor.
* @param object the object that the reference will refer to.
*/
public HardReference(Object object) {
this.object = object;
super(object);
}

/**
* Returns this reference object's referent.
* @return the object to which this reference refers.
*/
public Object get() {
return object;
}
}

}

+ 6
- 13
src/main/org/apache/tools/ant/util/optional/WeakishReference12.java View File

@@ -27,10 +27,13 @@ import java.lang.ref.WeakReference;
* appropriate java.lang.ref class.
* @deprecated since 1.7.
* Just use {@link WeakReference} directly.
* Note that in ant1.7 is parent was changed to extend HardReference.
* This is because the latter has access to the (package scoped)
* WeakishReference(Object) constructor, and both that and this are thin
* facades on the underlying no-longer-abstract base class.
*/
public class WeakishReference12 extends WeakishReference {
public class WeakishReference12 extends WeakishReference.HardReference {

private WeakReference weakref;

/**
* create a new soft reference, which is bound to a
@@ -39,16 +42,6 @@ public class WeakishReference12 extends WeakishReference {
* @see java.lang.ref.WeakReference
*/
public WeakishReference12(Object reference) {
this.weakref = new WeakReference(reference);
super(reference);
}

/**
* Returns this reference object's referent.
*
* @return referent.
*/
public Object get() {
return weakref.get();
}

}

Loading…
Cancel
Save