/** * Constructs an instance without initial backing store. This constructor is for subclass * constructors only. Subclasses are responsible for creating an appropriate backing store when * the {@link DeferredAuthorityFactory#createBackingStore} method is invoked. * * @param priority The priority for this factory, as a number between {@link #MINIMUM_PRIORITY * MINIMUM_PRIORITY} and {@link #MAXIMUM_PRIORITY MAXIMUM_PRIORITY} inclusive. * @param maxStrongReferences The maximum number of objects to keep by strong reference. * @see DeferredAuthorityFactory#createBackingStore */ ThreadedAuthorityFactory(final int priority, final int maxStrongReferences) { super(priority); this.objectCache = new OldReferencingObjectCache(maxStrongReferences); // completeHints() will be invoked by DeferredAuthorityFactory.getBackingStore() }
/** Returns an ellipsoid from a code. */ @Override public synchronized Ellipsoid createEllipsoid(final String code) throws FactoryException { final Ellipsoid ellipsoid; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof Ellipsoid) { ellipsoid = (Ellipsoid) cached; } else { ellipsoid = getBackingStore().createEllipsoid(code); } objectCache.put(key, ellipsoid); return ellipsoid; }
/** Releases resources immediately instead of waiting for the garbage collector. */ @Override public synchronized void dispose() throws FactoryException { if (backingStore != null) { backingStore.dispose(); backingStore = null; } objectCache.clear(); super.dispose(); } }
/** Returns a derived coordinate reference system from a code. */ @Override public synchronized DerivedCRS createDerivedCRS(final String code) throws FactoryException { final DerivedCRS crs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof DerivedCRS) { crs = (DerivedCRS) cached; } else { crs = getBackingStore().createDerivedCRS(code); } objectCache.put(key, crs); return crs; }
/** * Constructs an instance wrapping the specified factory. The {@code maxStrongReferences} * argument specify the maximum number of objects to keep by strong reference. If a greater * amount of objects are created, then the strong references for the oldest ones are replaced by * weak references. * * <p>This constructor is protected because subclasses must declare which of the {@link * DatumAuthorityFactory}, {@link CSAuthorityFactory}, {@link CRSAuthorityFactory} and {@link * CoordinateOperationAuthorityFactory} interfaces they choose to implement. * * @param factory The factory to cache. Can not be {@code null}. * @param maxStrongReferences The maximum number of objects to keep by strong reference. */ protected ThreadedAuthorityFactory( AbstractAuthorityFactory factory, final int maxStrongReferences) { super(factory.getPriority()); while (factory instanceof ThreadedAuthorityFactory) { factory = ((ThreadedAuthorityFactory) factory).backingStore; } this.backingStore = factory; this.objectCache = new OldReferencingObjectCache(maxStrongReferences); completeHints(); }
/** Returns an image datum from a code. */ @Override public synchronized ImageDatum createImageDatum(final String code) throws FactoryException { final ImageDatum datum; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof ImageDatum) { datum = (ImageDatum) cached; } else { datum = getBackingStore().createImageDatum(code); } objectCache.put(key, datum); return datum; }
/** Returns a cartesian coordinate system from a code. */ @Override public synchronized CartesianCS createCartesianCS(final String code) throws FactoryException { final CartesianCS cs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof CartesianCS) { cs = (CartesianCS) cached; } else { cs = getBackingStore().createCartesianCS(code); } objectCache.put(key, cs); return cs; }
/** Returns a polar coordinate system from a code. */ @Override public synchronized PolarCS createPolarCS(final String code) throws FactoryException { final PolarCS cs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof PolarCS) { cs = (PolarCS) cached; } else { cs = getBackingStore().createPolarCS(code); } objectCache.put(key, cs); return cs; }
/** Returns an unit from a code. */ @Override public synchronized Unit<?> createUnit(final String code) throws FactoryException { final Unit<?> unit; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof Unit) { unit = (Unit) cached; } else { unit = getBackingStore().createUnit(code); } objectCache.put(key, unit); return unit; }
/** Returns an image coordinate reference system from a code. */ @Override public synchronized ImageCRS createImageCRS(final String code) throws FactoryException { final ImageCRS crs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof ImageCRS) { crs = (ImageCRS) cached; } else { crs = getBackingStore().createImageCRS(code); } objectCache.put(key, crs); return crs; }
/** Returns a vertical coordinate system from a code. */ @Override public synchronized VerticalCS createVerticalCS(final String code) throws FactoryException { final VerticalCS cs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof VerticalCS) { cs = (VerticalCS) cached; } else { cs = getBackingStore().createVerticalCS(code); } objectCache.put(key, cs); return cs; }
/** Returns a temporal coordinate reference system from a code. */ @Override public synchronized TemporalCRS createTemporalCRS(final String code) throws FactoryException { final TemporalCRS crs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof TemporalCRS) { crs = (TemporalCRS) cached; } else { crs = getBackingStore().createTemporalCRS(code); } objectCache.put(key, crs); return crs; }
/** Returns an arbitrary object from a code. */ @Override public synchronized IdentifiedObject createObject(final String code) throws FactoryException { final IdentifiedObject object; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof IdentifiedObject) { object = (IdentifiedObject) cached; } else { object = getBackingStore().createObject(code); } objectCache.put(key, object); return object; }
/** Returns an extent (usually an area of validity) from a code. */ @Override public synchronized Extent createExtent(final String code) throws FactoryException { final Extent extent; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof Extent) { extent = (Extent) cached; } else { extent = getBackingStore().createExtent(code); } objectCache.put(key, extent); return extent; }
/** Returns a 3D coordinate reference system from a code. */ @Override public synchronized CompoundCRS createCompoundCRS(final String code) throws FactoryException { final CompoundCRS crs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof CompoundCRS) { crs = (CompoundCRS) cached; } else { crs = getBackingStore().createCompoundCRS(code); } objectCache.put(key, crs); return crs; }
/** Returns a vertical coordinate reference system from a code. */ @Override public synchronized VerticalCRS createVerticalCRS(final String code) throws FactoryException { final VerticalCRS crs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof VerticalCRS) { crs = (VerticalCRS) cached; } else { crs = getBackingStore().createVerticalCRS(code); } objectCache.put(key, crs); return crs; }
/** Returns an arbitrary coordinate reference system from a code. */ @Override public synchronized CoordinateReferenceSystem createCoordinateReferenceSystem(final String code) throws FactoryException { final CoordinateReferenceSystem crs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof CoordinateReferenceSystem) { crs = (CoordinateReferenceSystem) cached; } else { crs = getBackingStore().createCoordinateReferenceSystem(code); } objectCache.put(key, crs); return crs; }
/** Returns a geographic coordinate reference system from a code. */ @Override public synchronized GeographicCRS createGeographicCRS(final String code) throws FactoryException { final GeographicCRS crs; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof GeographicCRS) { crs = (GeographicCRS) cached; } else { crs = getBackingStore().createGeographicCRS(code); } objectCache.put(key, crs); return crs; }
/** Returns an operation method from a code. */ @Override public synchronized OperationMethod createOperationMethod(final String code) throws FactoryException { final OperationMethod method; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof OperationMethod) { method = (OperationMethod) cached; } else { method = getBackingStore().createOperationMethod(code); } objectCache.put(key, method); return method; }
/** Returns an arbitrary datum from a code. */ @Override public synchronized Datum createDatum(final String code) throws FactoryException { final Datum datum; final String key = trimAuthority(code); final Object cached = objectCache.get(key); if (cached instanceof Datum) { datum = (Datum) cached; } else { datum = getBackingStore().createDatum(code); } objectCache.put(key, datum); return datum; }