AssetType implements Closeable { public T loadAsset(ResourceUrn urn, U data) { if (urn.isInstance()) { return factory.build(urn, this, data); } else { T asset = loadedAssets.get(urn); if (asset != null) { asset.reload(data); } else { ResourceLock lock; synchronized (locks) { lock = locks.computeIfAbsent(urn, k -> new ResourceLock(urn)); } try { lock.lock(); if (!closed) { asset = loadedAssets.get(urn); if (asset == null) { asset = factory.build(urn, this, data); } else { asset.reload(data); } } synchronized (locks) { if (lock.unlock()) { locks.remove(urn); } } } catch (InterruptedException e) { logger.error("Failed to load asset - interrupted awaiting lock on resource {}", urn); } } return asset; } } @SuppressWarnings("unchecked")  AssetType(Class<T> assetClass, AssetFactory<T, U> factory); @Override synchronized void close(); @SuppressWarnings("unchecked") void processDisposal(); synchronized boolean isClosed(); synchronized void disposeAll(); void refresh(); Class<T> getAssetClass(); Class<U> getAssetDataClass(); void setResolutionStrategy(ResolutionStrategy strategy); synchronized void addProducer(AssetDataProducer<U> producer); List<AssetDataProducer<U>> getProducers(); synchronized boolean removeProducer(AssetDataProducer<U> producer); synchronized void clearProducers(); Optional<T> getAsset(ResourceUrn urn); @SuppressWarnings("unchecked") Optional<T> getInstanceAsset(ResourceUrn urn); Optional<T> reload(ResourceUrn urn); Optional<T> getAsset(String urn); Optional<T> getAsset(String urn, Name moduleContext); Set<ResourceUrn> resolve(String urn); Set<ResourceUrn> resolve(String urn, Name moduleContext); T loadAsset(ResourceUrn urn, U data); boolean isLoaded(ResourceUrn urn); Set<ResourceUrn> getLoadedAssetUrns(); Set<T> getLoadedAssets(); Set<ResourceUrn> getAvailableAssetUrns(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void loadingAssetWithSameUrnReloadsExistingAsset() { TextData initialData = new TextData(TEXT_VALUE); Text initialText = assetType.loadAsset(URN, initialData); TextData newData = new TextData(TEXT_VALUE_2); Text newText = assetType.loadAsset(URN, newData); assertSame(initialText, newText); assertEquals(newData.getValue(), initialText.getValue()); }