reworked images and videos of event -> removed double maintenance of imageURLs, videoURLs, sponsorImageURLs -> they are now always calculated from images and videos

This commit is contained in:
fmittag committed 2015-06-14 16:21:28 +02:00
1 parent 8125b4f3d4
commit 9decf43909
12 files changed
+143 -374

No files matched your search

@@ -1,13 +1,8 @@
package com.sap.sailing.domain.base;
import java.net.URL;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sse.common.media.ImageDescriptor;
import com.sap.sse.common.media.ImageSize;
import com.sap.sse.common.media.MediaUtils;
/**
* An event is a group of {@link Regatta regattas} carried out at a common venue within a common time frame. For
@@ -51,19 +46,4 @@ public interface Event extends EventBase {
* leaderboard groups in <code>leaderboardGroups</code>.
*/
void setLeaderboardGroups(Iterable<LeaderboardGroup> leaderboardGroups);
/**
* For the images references by the image URLs in {@link #getImageURLs()}, {@link #getSponsorImageURLs()} and {@link #getLogoImageURL()}
* determines the image dimensions. The retrieval of the image size is started when the URL is added to this event, and the result is
* cached. Should the image change its size afterwards or change its availability status, this event won't notice unless the image is
* removed from this event and added again.<p>
*
* Note that exceptions may result should the image be unavailable. If the image URL leads to a document that is not an image,
* <code>null</code> will result.
*
* @deprecated Use {@link MediaUtils#getImageDimensions(URL)} or simply use the dimensions given by {@link ImageDescriptor}
*/
@Deprecated
ImageSize getImageSize(URL imageURL) throws InterruptedException, ExecutionException;
}
@@ -34,15 +34,11 @@ import com.sap.sse.common.media.ImageSize;
public class EventImpl extends EventBaseImpl implements Event {
private static final long serialVersionUID = 855135446595485715L;
private static final Logger logger = Logger.getLogger(EventImpl.class.getName());
private final Set<Regatta> regattas;
private ConcurrentLinkedQueue<LeaderboardGroup> leaderboardGroups;
private transient ConcurrentHashMap<URL, Future<ImageSize>> imageSizeFetchers;
private transient ExecutorService executor;
public EventImpl(String name, TimePoint startDate, TimePoint endDate, String venueName, boolean isPublic, UUID id) {
this(name, startDate, endDate, new VenueImpl(venueName), isPublic, id);
}
@@ -54,8 +50,6 @@ public class EventImpl extends EventBaseImpl implements Event {
super(name, startDate, endDate, venue, isPublic, id);
this.regattas = new HashSet<Regatta>();
this.leaderboardGroups = new ConcurrentLinkedQueue<>();
this.imageSizeFetchers = new ConcurrentHashMap<>();
this.executor = Executors.newCachedThreadPool();
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
@@ -63,8 +57,6 @@ public class EventImpl extends EventBaseImpl implements Event {
if (leaderboardGroups == null) {
leaderboardGroups = new ConcurrentLinkedQueue<>();
}
this.imageSizeFetchers = new ConcurrentHashMap<>();
this.executor = Executors.newCachedThreadPool();
}
@Override
@@ -106,86 +98,4 @@ public class EventImpl extends EventBaseImpl implements Event {
public boolean removeLeaderboardGroup(LeaderboardGroup leaderboardGroup) {
return leaderboardGroups.remove(leaderboardGroup);
}
private Future<ImageSize> getOrCreateImageSizeCalculator(final URL imageURL) {
Future<ImageSize> imageSizeFetcher = imageSizeFetchers.get(imageURL);
if (imageSizeFetcher == null) {
imageSizeFetcher = executor.submit(new Callable<ImageSize>() {
@Override
public ImageSize call() throws IOException {
ImageSize result = null;
ImageInputStream in = null;
try {
URLConnection conn = imageURL.openConnection();
in = ImageIO.createImageInputStream(conn.getInputStream());
final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
if (readers.hasNext()) {
ImageReader reader = readers.next();
try {
reader.setInput(in);
result = new ImageSizeImpl(reader.getWidth(0), reader.getHeight(0));
} finally {
reader.dispose();
}
}
} catch (IOException ioe) {
logger.log(Level.SEVERE, "Stale image link "+imageURL+" for event "+getName()+". Please double-check and replace or remove.", ioe);
throw ioe;
} finally {
if (in != null) {
in.close();
}
}
return result;
}
});
imageSizeFetchers.put(imageURL, imageSizeFetcher);
}
return imageSizeFetcher;
}
@Override
public ImageSize getImageSize(URL imageURL) throws InterruptedException, ExecutionException {
Future<ImageSize> imageSizeCalculator = getOrCreateImageSizeCalculator(imageURL);
return imageSizeCalculator.get();
}
private void refreshImageSizeFetcher(URL imageURL) {
if (imageURL != null) {
removeImageSizeFetcher(imageURL);
getOrCreateImageSizeCalculator(imageURL);
}
}
private void removeImageSizeFetcher(URL imageURL) {
if (imageURL != null) {
imageSizeFetchers.remove(imageURL);
}
}
@Override
public void setImageURLs(Iterable<URL> imageURLs) {
super.setImageURLs(imageURLs);
if (imageURLs != null) {
for (URL imageURL : imageURLs) {
refreshImageSizeFetcher(imageURL);
}
}
}
@Override
public void setSponsorImageURLs(Iterable<URL> sponsorImageURLs) {
super.setSponsorImageURLs(sponsorImageURLs);
if (sponsorImageURLs != null) {
for (URL imageURL : sponsorImageURLs) {
refreshImageSizeFetcher(imageURL);
}
}
}
@Override
public void setLogoImageURL(URL logoImageURL) {
super.setLogoImageURL(logoImageURL);
refreshImageSizeFetcher(logoImageURL);
}
}