/* * Copyright 2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.photos.concurrent; import java.io.IOException; import java.io.InputStream; import org.wamblee.photos.model.Photo; /** * Decorator for a photo to make it thread-safe. */ public class ConcurrentPhoto extends ConcurrentPhotoEntry implements Photo { public ConcurrentPhoto(Photo aPhoto) { super(aPhoto); } private Photo decorated() { return (Photo)getEntry(); } /* * (non-Javadoc) * * @see org.wamblee.photos.model.Photo#getThumbNail() */ public InputStream getThumbNail() throws IOException { lock().acquireRead(); try { return decorated().getThumbNail(); } finally { lock().releaseRead(); } } /* * (non-Javadoc) * * @see org.wamblee.photos.model.Photo#getPhoto() */ public InputStream getPhoto() throws IOException { lock().acquireRead(); try { return decorated().getPhoto(); } finally { lock().releaseRead(); } } }