r7243 - in dumbhippo/trunk/server/src/com/dumbhippo: mbean server/impl



Author: otaylor
Date: 2008-01-21 16:10:29 -0600 (Mon, 21 Jan 2008)
New Revision: 7243

Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/mbean/FacebookTrackerPeriodicJob.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
Log:
Initialize a ReadWrite DataModel session when stacking facebook blocks


Modified: dumbhippo/trunk/server/src/com/dumbhippo/mbean/FacebookTrackerPeriodicJob.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/mbean/FacebookTrackerPeriodicJob.java	2008-01-21 21:39:50 UTC (rev 7242)
+++ dumbhippo/trunk/server/src/com/dumbhippo/mbean/FacebookTrackerPeriodicJob.java	2008-01-21 22:10:29 UTC (rev 7243)
@@ -11,7 +11,10 @@
 import com.dumbhippo.persistence.FacebookAccount;
 import com.dumbhippo.server.FacebookSystem;
 import com.dumbhippo.server.FacebookTracker;
+import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.util.EJBUtil;
+import com.dumbhippo.server.views.SystemViewpoint;
+import com.dumbhippo.tx.TxUtils;
 
 public class FacebookTrackerPeriodicJob implements PeriodicJob {
 	static private final Logger logger = GlobalSetup.getLogger(FacebookTrackerPeriodicJob.class);
@@ -50,15 +53,28 @@
 		    threadPool.execute(new Runnable() {
 				public void run() {
 					final FacebookTracker facebookTracker = EJBUtil.defaultLookup(FacebookTracker.class);
-					// even if we find out that the session key is expired in updateMessageCount,
-					// we still want to call updateTaggedPhotos, because it removes the cached
-					// photos that we can't keep anymore when the session key is expired
-					facebookTracker.updateMessageCount(facebookAccount.getId());
+
+					// updateMessageCount expects to run in a transaction, but updateTaggedPhotos
+					// is TransactionAttributeType.NEVER, so we need to handle them differently.. 
+					
+					TxUtils.runInTransaction(new Runnable() {
+						public void run() {
+							DataService.getModel().initializeReadWriteSession(SystemViewpoint.getInstance());
+							
+							// even if we find out that the session key is expired in updateMessageCount,
+							// we still want to call updateTaggedPhotos, because it removes the cached
+							// photos that we can't keep anymore when the session key is expired
+							facebookTracker.updateMessageCount(facebookAccount.getId());
+
+							// don't do anything about albums for now, since we aren't showing
+							// facebook updates to anyone but the album owner, so it's not interesting,
+							// and we don't have a system for clearing the cached facebook info about albums
+							
+							// facebookTracker.updateAlbums(facebookAccount.getId());
+						}
+					});
+					
 					facebookTracker.updateTaggedPhotos(facebookAccount.getId());
-					// don't do anything about albums for now, since we aren't showing
-					// facebook updates to anyone but the album owner, so it's not interesting,
-					// and we don't have a system for clearing the cached facebook info about albums
-					// facebookTracker.updateAlbums(facebookAccount.getId());
 				}
 			});
 		}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java	2008-01-21 21:39:50 UTC (rev 7242)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java	2008-01-21 22:10:29 UTC (rev 7243)
@@ -53,7 +53,7 @@
 import com.dumbhippo.server.Pageable;
 import com.dumbhippo.server.Stacker;
 import com.dumbhippo.server.blocks.BlockView;
-import com.dumbhippo.server.util.EJBUtil;
+import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.views.AnonymousViewpoint;
 import com.dumbhippo.server.views.ExternalAccountView;
 import com.dumbhippo.server.views.SystemViewpoint;
@@ -460,15 +460,21 @@
 		FacebookWebServices ws = new FacebookWebServices(REQUEST_TIMEOUT, config);
 		
 		int newPhotoCount = ws.getTaggedPhotosCount(facebookAccount);
-			
-		FacebookTracker proxy = EJBUtil.defaultLookup(FacebookTracker.class);
+
 		if (newPhotoCount == -1) {
 			if (!facebookAccount.isSessionKeyValid()) {
 				// delete cache because the photo data is not storable past the end of the session				
 				taggedPhotosCache.deleteCache(user.getGuid().toString());
-				// that was a detached copy of facebookAccount, we need to set isSessionKeyValid on an attached copy
-				proxy.handleExpiredSessionKey(facebookAccountId);
-		    }
+
+				TxUtils.runInTransaction(new Runnable() {
+					public void run() {
+						DataService.getModel().initializeReadWriteSession(SystemViewpoint.getInstance());
+						handleExpiredSessionKey(facebookAccountId);
+				    }
+				});
+				
+			}
+			
 			return;			
 		}
 	
@@ -490,9 +496,14 @@
 				taggedPhotosCache.expireCache(user.getGuid().toString());
 			}
 			
-			List<? extends FacebookPhotoDataView> cachedPhotos = taggedPhotosCache.getSync(user.getGuid().toString());
+			final List<? extends FacebookPhotoDataView> cachedPhotos = taggedPhotosCache.getSync(user.getGuid().toString());
 			
-			proxy.saveUpdatedTaggedPhotos(facebookAccountId, cachedPhotos);
+			TxUtils.runInTransaction(new Runnable() {
+				public void run() {
+					DataService.getModel().initializeReadWriteSession(SystemViewpoint.getInstance());
+					saveUpdatedTaggedPhotos(facebookAccountId, cachedPhotos);
+				}
+			});
 		}	
 	}
 	



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