r7248 - in dumbhippo/trunk/server/src/com/dumbhippo/server: . impl



Author: otaylor
Date: 2008-01-22 10:58:56 -0600 (Tue, 22 Jan 2008)
New Revision: 7248

Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/server/CachedExternalUpdater.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/AmazonUpdaterBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/CachedExternalUpdaterBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FlickrUpdaterBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/LastFmUpdaterBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/PicasaUpdaterBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/YouTubeUpdaterBean.java
Log:
* More work at making sure we have ReadWrite transactions when stacking blocks
* Remove old CachedExternalUpdater.periodicUpdate() which was no longer used


Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/CachedExternalUpdater.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/CachedExternalUpdater.java	2008-01-22 16:06:41 UTC (rev 7247)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/CachedExternalUpdater.java	2008-01-22 16:58:56 UTC (rev 7248)
@@ -15,6 +15,4 @@
 	public Status getCachedStatus(User user) throws NotFoundException;
 	public Status getCachedStatus(ExternalAccount external) throws NotFoundException;
 	public Status getCachedStatus(String key) throws NotFoundException;
-
-	public void periodicUpdate(String key);
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/AmazonUpdaterBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/AmazonUpdaterBean.java	2008-01-22 16:06:41 UTC (rev 7247)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/AmazonUpdaterBean.java	2008-01-22 16:58:56 UTC (rev 7248)
@@ -10,8 +10,6 @@
 import javax.annotation.PostConstruct;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
 import javax.persistence.Query;
 
 import org.slf4j.Logger;
@@ -32,7 +30,9 @@
 import com.dumbhippo.server.Configuration;
 import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.Notifier;
+import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.util.EJBUtil;
+import com.dumbhippo.server.views.SystemViewpoint;
 import com.dumbhippo.services.AmazonItem;
 import com.dumbhippo.services.AmazonItemLookupWebServices;
 import com.dumbhippo.services.AmazonList;
@@ -51,6 +51,7 @@
 import com.dumbhippo.services.caches.CacheFactoryBean;
 import com.dumbhippo.services.caches.NotCachedException;
 import com.dumbhippo.services.caches.WebServiceCache;
+import com.dumbhippo.tx.TxUtils;
 
 @Stateless
 public class AmazonUpdaterBean extends CachedExternalUpdaterBean<AmazonUpdateStatus> implements AmazonUpdater {
@@ -99,12 +100,6 @@
 		return TypeUtils.castList(AmazonActivityStatus.class, q.getResultList());
 	}
 	
-	@Override
-	@TransactionAttribute(TransactionAttributeType.NEVER)	
-	public void doPeriodicUpdate(String amazonUserId) {
-	    logger.warn("Not doing anything for Amazon periodic update for {}, a polling task is expected to be used", amazonUserId);	
-	}
-	
 	// compute a "hash" (relies on the most recent reviews being first, 
 	// so it always changes if there are new reviews)
 	private String computeReviewsHash(List<? extends AmazonReviewView> reviewViews) {
@@ -366,7 +361,6 @@
 		protected PollResult execute() throws Exception {
 			AmazonUpdater proxy = EJBUtil.defaultLookup(AmazonUpdater.class);
 			Configuration config = EJBUtil.defaultLookup(Configuration.class);
-			Notifier notifier = EJBUtil.defaultLookup(Notifier.class);
 			AmazonReviewsCache reviewsCache = CacheFactoryBean.defaultLookup(AmazonReviewsCache.class);
 			AmazonListsCache listsCache = CacheFactoryBean.defaultLookup(AmazonListsCache.class);
 			AmazonListItemsCache listItemsCache = CacheFactoryBean.defaultLookup(AmazonListItemsCache.class);
@@ -434,7 +428,7 @@
 			
 			// the returned list will be null if we were saving something because it 
 			// expired, but nothing really changed
-			List<AmazonActivityStatus> statuses = proxy.saveUpdatedStatus(amazonUserId, reviewsView, refreshedListsView);
+			final List<AmazonActivityStatus> statuses = proxy.saveUpdatedStatus(amazonUserId, reviewsView, refreshedListsView);
 			
 			if (statuses == null) 
 				return new PollResult(false, false);
@@ -467,9 +461,16 @@
 			    proxy.saveItemsInCache(items);				
 			}
 			
-			for (AmazonActivityStatus status : statuses) {
-			    notifier.onAmazonActivityCreated(status);
-			}
+			TxUtils.runInTransaction(new Runnable() {
+				public void run() {
+					DataService.getModel().initializeReadWriteSession(SystemViewpoint.getInstance());
+					
+					Notifier notifier = EJBUtil.defaultLookup(Notifier.class);
+					for (AmazonActivityStatus status : statuses) {
+					    notifier.onAmazonActivityCreated(status);
+					}
+				}
+			});
 			
 			return new PollResult(true, false);
 		}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/CachedExternalUpdaterBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/CachedExternalUpdaterBean.java	2008-01-22 16:06:41 UTC (rev 7247)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/CachedExternalUpdaterBean.java	2008-01-22 16:58:56 UTC (rev 7248)
@@ -5,8 +5,6 @@
 import java.util.Set;
 
 import javax.ejb.EJB;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
 import javax.persistence.PersistenceContext;
@@ -29,7 +27,6 @@
 import com.dumbhippo.server.Configuration;
 import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.PollingTaskPersistence;
-import com.dumbhippo.tx.TxUtils;
 
 public abstract class CachedExternalUpdaterBean<Status> implements CachedExternalUpdater<Status> {
 
@@ -114,15 +111,6 @@
 		return TypeUtils.castList(User.class, q.getResultList());
 	}	
 	
-	protected abstract void doPeriodicUpdate(String handle);
-	
-	// avoid log messages in here that will happen on every call, or it could get noisy
-	@TransactionAttribute(TransactionAttributeType.NEVER)
-	public void periodicUpdate(String handle) {
-		TxUtils.assertNoTransaction();
-		doPeriodicUpdate(handle);
-	}
-	
 	protected abstract Class<? extends CachedExternalUpdater<Status>> getUpdater();
 	
 	protected void onExternalAccountChange(User user, ExternalAccount external) {

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FlickrUpdaterBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FlickrUpdaterBean.java	2008-01-22 16:06:41 UTC (rev 7247)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FlickrUpdaterBean.java	2008-01-22 16:58:56 UTC (rev 7248)
@@ -10,8 +10,6 @@
 import javax.annotation.PostConstruct;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
 import javax.persistence.Query;
 
 import org.slf4j.Logger;
@@ -55,12 +53,6 @@
 	private Notifier notifier;
 
 	@WebServiceCache
-	private FlickrUserPhotosCache userPhotosCache;
-	
-	@WebServiceCache
-	private FlickrUserPhotosetsCache userPhotosetsCache;
-	
-	@WebServiceCache
 	private FlickrPhotosetPhotosCache photosetPhotosCache;
 
 	@EJB
@@ -94,22 +86,6 @@
 		return TypeUtils.castList(FlickrPhotosetStatus.class, q.getResultList());
 	}
 	
-	@Override
-	@TransactionAttribute(TransactionAttributeType.NEVER)	
-	public void doPeriodicUpdate(String flickrId) {
-		FlickrUpdater proxy = EJBUtil.defaultLookup(FlickrUpdater.class);
-
-		FlickrPhotosView photosView = userPhotosCache.getSync(flickrId, true);
-		FlickrPhotosetsView photosetsView = userPhotosetsCache.getSync(flickrId, true);
-		
-		if (photosView == null || photosetsView == null) {
-			logger.debug("one of two flickr requests failed, not saving new flickr status for " + flickrId);
-			return;
-		}
-		
-		proxy.saveUpdatedStatus(flickrId, photosView, photosetsView);
-	}
-	
 	private void updateUserPhotosetStatuses(String ownerId, List<? extends FlickrPhotosetView> allPhotosets) {
 		Query q = em.createQuery("SELECT setStatus FROM FlickrPhotosetStatus setStatus WHERE " + 
 				"setStatus.ownerId = :ownerId");

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/LastFmUpdaterBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/LastFmUpdaterBean.java	2008-01-22 16:06:41 UTC (rev 7247)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/LastFmUpdaterBean.java	2008-01-22 16:58:56 UTC (rev 7248)
@@ -7,8 +7,6 @@
 
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
 import javax.persistence.Query;
 
 import org.slf4j.Logger;
@@ -45,21 +43,6 @@
 	@EJB
 	private MusicSystem musicSystem;
 
-	@Override
-	@TransactionAttribute(TransactionAttributeType.NEVER)	
-	public void doPeriodicUpdate(String username) {
-		LastFmUpdater proxy = EJBUtil.defaultLookup(LastFmUpdater.class);
-		
-		List<LastFmTrack> tracks;
-		try {
-			tracks = LastFmWebServices.getTracksForUser(username);
-		} catch (TransientServiceException e) {
-			logger.warn("Exception from LastFmWebServices", e);
-			return;
-		}
-		proxy.saveUpdatedStatus(username, tracks);
-	}
-	
 	private String computeTrackHash(LastFmTrack track) {
 		return track.getUrl() + " " + track.getListenTime();		
 	}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/PicasaUpdaterBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/PicasaUpdaterBean.java	2008-01-22 16:06:41 UTC (rev 7247)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/PicasaUpdaterBean.java	2008-01-22 16:58:56 UTC (rev 7248)
@@ -1,12 +1,11 @@
 package com.dumbhippo.server.impl;
 
 import java.util.List;
+import java.util.concurrent.Callable;
 
 import javax.annotation.PostConstruct;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
 import javax.persistence.Query;
 
 import org.slf4j.Logger;
@@ -23,12 +22,13 @@
 import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.Notifier;
 import com.dumbhippo.server.PicasaUpdater;
+import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.util.EJBUtil;
+import com.dumbhippo.server.views.SystemViewpoint;
 import com.dumbhippo.services.PicasaAlbum;
 import com.dumbhippo.services.caches.CacheFactory;
 import com.dumbhippo.services.caches.CacheFactoryBean;
 import com.dumbhippo.services.caches.PicasaAlbumsCache;
-import com.dumbhippo.services.caches.WebServiceCache;
 import com.dumbhippo.tx.TxUtils;
 
 @Stateless
@@ -40,9 +40,6 @@
 	@EJB
 	private Notifier notifier;
 
-	@WebServiceCache
-	private PicasaAlbumsCache albumsCache;	
-	
 	@EJB
 	private CacheFactory cacheFactory;	
 	
@@ -51,17 +48,6 @@
 		cacheFactory.injectCaches(this);
 	}
 	
-	@Override
-	@TransactionAttribute(TransactionAttributeType.NEVER)	
-	public void doPeriodicUpdate(String username) {
-		TxUtils.assertNoTransaction();
-		
-		PicasaUpdater proxy = EJBUtil.defaultLookup(PicasaUpdater.class);
-		
-		List<? extends PicasaAlbum> albums = albumsCache.getSync(username, true);
-		proxy.saveUpdatedStatus(username, albums);
-	}
-	
 	//TODO: Identify the unique part of picasa urls instead of using the whole thing,
 	// though it doesn't really matter once we digest. What might be better is
 	// to use guid from the feed items rather than the thumbnail link, since
@@ -152,13 +138,20 @@
 
 		@Override
 		protected PollResult execute() throws Exception {
-			boolean changed = false;
-			PicasaUpdater proxy = EJBUtil.defaultLookup(PicasaUpdater.class);
 			PicasaAlbumsCache cache = CacheFactoryBean.defaultLookup(PicasaAlbumsCache.class);
 			
-			List<? extends PicasaAlbum> albums = cache.getSync(username, true);
-			changed = proxy.saveUpdatedStatus(username, albums);			
-			return new PollResult(changed, false);
+			final List<? extends PicasaAlbum> albums = cache.getSync(username, true);
+			
+			return TxUtils.runInTransaction(new Callable<PollResult>() {
+				public PollResult call() {
+					DataService.getModel().initializeReadWriteSession(SystemViewpoint.getInstance());
+					
+					PicasaUpdater proxy = EJBUtil.defaultLookup(PicasaUpdater.class);
+					boolean changed = proxy.saveUpdatedStatus(username, albums);
+					
+					return new PollResult(changed, false);
+				}
+			});
 		}
 
 		@Override

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/YouTubeUpdaterBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/YouTubeUpdaterBean.java	2008-01-22 16:06:41 UTC (rev 7247)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/YouTubeUpdaterBean.java	2008-01-22 16:58:56 UTC (rev 7248)
@@ -1,12 +1,11 @@
 package com.dumbhippo.server.impl;
 
 import java.util.List;
+import java.util.concurrent.Callable;
 
 import javax.annotation.PostConstruct;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
 import javax.persistence.Query;
 
 import org.slf4j.Logger;
@@ -22,11 +21,12 @@
 import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.Notifier;
 import com.dumbhippo.server.YouTubeUpdater;
+import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.util.EJBUtil;
+import com.dumbhippo.server.views.SystemViewpoint;
 import com.dumbhippo.services.YouTubeVideo;
 import com.dumbhippo.services.caches.CacheFactory;
 import com.dumbhippo.services.caches.CacheFactoryBean;
-import com.dumbhippo.services.caches.WebServiceCache;
 import com.dumbhippo.services.caches.YouTubeVideosCache;
 import com.dumbhippo.tx.TxUtils;
 
@@ -39,9 +39,6 @@
 	@EJB
 	private Notifier notifier;
 
-	@WebServiceCache
-	private YouTubeVideosCache videosCache;	
-	
 	@EJB
 	private CacheFactory cacheFactory;	
 	
@@ -50,17 +47,6 @@
 		cacheFactory.injectCaches(this);
 	}
 	
-	@Override
-	@TransactionAttribute(TransactionAttributeType.NEVER)	
-	public void doPeriodicUpdate(String username) {
-		TxUtils.assertNoTransaction();
-		
-		YouTubeUpdater proxy = EJBUtil.defaultLookup(YouTubeUpdater.class);
-		
-		List<? extends YouTubeVideo> videos = videosCache.getSync(username, true);
-		proxy.saveUpdatedStatus(username, videos);
-	}
-	
 	//TODO: Identify the unique part of youtube urls instead of using the whole thing
 	private String computeHash(List<? extends YouTubeVideo> videos) {
 		StringBuilder sb = new StringBuilder();
@@ -147,13 +133,20 @@
 
 		@Override
 		protected PollResult execute() throws Exception {
-			boolean changed = false;
-			YouTubeUpdater proxy = EJBUtil.defaultLookup(YouTubeUpdater.class);
 			YouTubeVideosCache cache = CacheFactoryBean.defaultLookup(YouTubeVideosCache.class);
 			
-			List<? extends YouTubeVideo> videos = cache.getSync(username, true);
-			changed = proxy.saveUpdatedStatus(username, videos);			
-			return new PollResult(changed, false);
+			final List<? extends YouTubeVideo> videos = cache.getSync(username, true);
+			
+			return TxUtils.runInTransaction(new Callable<PollResult>() {
+				public PollResult call() {
+					DataService.getModel().initializeReadWriteSession(SystemViewpoint.getInstance());
+					
+					YouTubeUpdater proxy = EJBUtil.defaultLookup(YouTubeUpdater.class);
+					boolean changed = proxy.saveUpdatedStatus(username, videos);
+					
+					return new PollResult(changed, false);
+				}
+			});
 		}
 
 		@Override



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]