From: Martin D. <des...@us...> - 2002-07-31 10:19:32
|
Update of /cvsroot/geotools/geotools2/geotools-src/cts-coordtrans/src/org/geotools/ct In directory usw-pr-cvs1:/tmp/cvs-serv18827/geotools-src/cts-coordtrans/src/org/geotools/ct Modified Files: CoordinateTransformationFactory.java MathTransformFactory.java Log Message: Improved caching Index: CoordinateTransformationFactory.java =================================================================== RCS file: /cvsroot/geotools/geotools2/geotools-src/cts-coordtrans/src/org/geotools/ct/CoordinateTransformationFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -w -C2 -d -r1.2 -r1.3 *** CoordinateTransformationFactory.java 12 Jul 2002 16:39:32 -0000 1.2 --- CoordinateTransformationFactory.java 31 Jul 2002 10:19:29 -0000 1.3 *************** *** 36,39 **** --- 36,52 ---- package org.geotools.ct; + // J2SE dependencies + import java.util.Arrays; + import java.rmi.RemoteException; + import java.rmi.ServerException; + import java.rmi.server.RemoteObject; + import java.awt.geom.AffineTransform; + import java.lang.ref.WeakReference; + import java.lang.ref.Reference; + + // JAI dependencies + import javax.media.jai.ParameterList; + import javax.vecmath.SingularMatrixException; + // OpenGIS dependencies import org.opengis.cs.CS_CoordinateSystem; *************** *** 68,86 **** import org.geotools.resources.cts.ResourceKeys; - // J2SE and JAI dependencies - import java.util.Arrays; - import java.rmi.RemoteException; - import java.rmi.ServerException; - import java.rmi.server.RemoteObject; - import java.awt.geom.AffineTransform; - import javax.media.jai.ParameterList; - import javax.vecmath.SingularMatrixException; - /** * Creates coordinate transformations. * ! * @version 1.0 ! * @author OpenGIS (www.opengis.org) * @author Martin Desruisseaux * --- 81,90 ---- import org.geotools.resources.cts.ResourceKeys; /** * Creates coordinate transformations. * ! * @version $Id$ ! * @author <A HREF="http://www.opengis.org">OpenGIS</A> * @author Martin Desruisseaux * *************** *** 107,110 **** --- 111,120 ---- /** + * OpenGIS object returned by {@link #toOpenGIS}. + * It may be a hard or a weak reference. + */ + private transient Object proxy; + + /** * Construct a coordinate transformation factory. * *************** *** 1041,1052 **** /** ! * Returns an OpenGIS interface for this transform factory. ! * The returned object is suitable for RMI use. * * Note: The returned type is a generic {@link Object} in order ! * to avoid too early class loading of OpenGIS interface. */ ! final Object toOpenGIS(final Object adapters) { ! return new Export(adapters); } --- 1051,1079 ---- /** ! * Returns an OpenGIS interface for this info. ! * This method first looks in the cache. If no ! * interface was previously cached, then this ! * method creates a new adapter and caches the ! * result. * * Note: The returned type is a generic {@link Object} in order ! * to avoid premature class loading of OpenGIS interface. ! * ! * @param adapters The originating {@link Adapters}. */ ! final synchronized Object toOpenGIS(final Object adapters) { ! if (proxy != null) { ! if (proxy instanceof Reference) { ! final Object ref = ((Reference) proxy).get(); ! if (ref != null) { ! return ref; ! } ! } else { ! return proxy; ! } ! } ! final Object opengis = new Export(adapters); ! proxy = new WeakReference(opengis); ! return opengis; } Index: MathTransformFactory.java =================================================================== RCS file: /cvsroot/geotools/geotools2/geotools-src/cts-coordtrans/src/org/geotools/ct/MathTransformFactory.java,v retrieving revision 1.8 retrieving revision 1.9 diff -w -C2 -d -r1.8 -r1.9 *** MathTransformFactory.java 24 Jul 2002 17:14:21 -0000 1.8 --- MathTransformFactory.java 31 Jul 2002 10:19:29 -0000 1.9 *************** *** 36,39 **** --- 36,53 ---- package org.geotools.ct; + // J2SE dependencies + import java.util.Locale; + import java.util.NoSuchElementException; + import java.awt.geom.AffineTransform; + import java.awt.geom.Point2D; + import java.rmi.RemoteException; + import java.rmi.server.RemoteObject; + import java.lang.ref.WeakReference; + import java.lang.ref.Reference; + + // JAI and Java3D dependencies + import javax.media.jai.ParameterList; + import javax.vecmath.GMatrix; + // OpenGIS dependencies import org.opengis.pt.PT_Matrix; *************** *** 53,66 **** import org.geotools.resources.DescriptorNaming; - // J2SE, JAI and vecmath dependencies - import java.util.Locale; - import java.util.NoSuchElementException; - import java.awt.geom.AffineTransform; - import java.awt.geom.Point2D; - import java.rmi.RemoteException; - import java.rmi.server.RemoteObject; - import javax.media.jai.ParameterList; - import javax.vecmath.GMatrix; - /** --- 67,70 ---- *************** *** 126,129 **** --- 130,139 ---- /** + * OpenGIS object returned by {@link #toOpenGIS}. + * It may be a hard or a weak reference. + */ + private transient Object proxy; + + /** * Construct a factory using the specified providers. */ *************** *** 569,580 **** /** ! * Returns an OpenGIS interface for this transform factory. ! * The returned object is suitable for RMI use. * * Note: The returned type is a generic {@link Object} in order ! * to avoid too early class loading of OpenGIS interface. */ ! final Object toOpenGIS(final Object adapters) { ! return new Export(adapters); } --- 579,607 ---- /** ! * Returns an OpenGIS interface for this info. ! * This method first looks in the cache. If no ! * interface was previously cached, then this ! * method creates a new adapter and caches the ! * result. * * Note: The returned type is a generic {@link Object} in order ! * to avoid premature class loading of OpenGIS interface. ! * ! * @param adapters The originating {@link Adapters}. */ ! final synchronized Object toOpenGIS(final Object adapters) { ! if (proxy != null) { ! if (proxy instanceof Reference) { ! final Object ref = ((Reference) proxy).get(); ! if (ref != null) { ! return ref; ! } ! } else { ! return proxy; ! } ! } ! final Object opengis = new Export(adapters); ! proxy = new WeakReference(opengis); ! return opengis; } |