From a73d82bd6ca0f9bbcca8eb7ab6ba326fdf3c1021 Mon Sep 17 00:00:00 2001 From: Athou Date: Fri, 7 Jun 2013 15:47:13 +0200 Subject: [PATCH 1/3] table generator --- src/main/java/com/commafeed/backend/model/AbstractModel.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/commafeed/backend/model/AbstractModel.java b/src/main/java/com/commafeed/backend/model/AbstractModel.java index 235cd292..652ac3c7 100644 --- a/src/main/java/com/commafeed/backend/model/AbstractModel.java +++ b/src/main/java/com/commafeed/backend/model/AbstractModel.java @@ -6,13 +6,15 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.MappedSuperclass; +import javax.persistence.TableGenerator; @SuppressWarnings("serial") @MappedSuperclass public abstract class AbstractModel implements Serializable { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "gen") + @TableGenerator(name = "gen", allocationSize = 1000) private Long id; public Long getId() { From 27804db165bbd5c227b15f9b8dbe5c0b1d079a29 Mon Sep 17 00:00:00 2001 From: Athou Date: Fri, 7 Jun 2013 15:54:47 +0200 Subject: [PATCH 2/3] make sure the entry has been updated --- .../com/commafeed/backend/feeds/FeedRefreshUpdater.java | 7 +++++-- .../backend/pubsubhubbub/SubscriptionHandler.java | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/commafeed/backend/feeds/FeedRefreshUpdater.java b/src/main/java/com/commafeed/backend/feeds/FeedRefreshUpdater.java index 4948b568..be450af6 100644 --- a/src/main/java/com/commafeed/backend/feeds/FeedRefreshUpdater.java +++ b/src/main/java/com/commafeed/backend/feeds/FeedRefreshUpdater.java @@ -73,7 +73,7 @@ public class FeedRefreshUpdater { ApplicationSettings settings = applicationSettingsService.get(); int threads = Math.max(settings.getDatabaseUpdateThreads(), 1); log.info("Creating database pool with {} threads", threads); - locks = Striped.lazyWeakLock(threads * 1000); + locks = Striped.lazyWeakLock(threads * 100000); pool = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS, queue = new ArrayBlockingQueue(500 * threads)); @@ -140,6 +140,8 @@ public class FeedRefreshUpdater { private boolean updateEntry(final Feed feed, final FeedEntry entry, final List subscriptions) { + boolean success = false; + String key = StringUtils.trimToEmpty(entry.getGuid() + entry.getUrl()); Lock lock = locks.get(key); boolean locked = false; @@ -147,6 +149,7 @@ public class FeedRefreshUpdater { locked = lock.tryLock(1, TimeUnit.MINUTES); if (locked) { feedUpdateService.updateEntry(feed, entry, subscriptions); + success = true; } else { log.error("lock timeout for " + feed.getUrl() + " - " + key); } @@ -158,7 +161,7 @@ public class FeedRefreshUpdater { lock.unlock(); } } - return locked; + return success; } private void handlePubSub(final Feed feed) { diff --git a/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java b/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java index 263ee5e7..6ca377da 100644 --- a/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java +++ b/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java @@ -36,6 +36,14 @@ public class SubscriptionHandler { FeedDAO feedDAO; public void subscribe(Feed feed) { + + try { + // make sure the feed has been updated for the callback to work + Thread.sleep(30000); + } catch (InterruptedException e1) { + // do nothing + } + String hub = feed.getPushHub(); String topic = feed.getPushTopic(); String publicUrl = FeedUtils From 598630cc23617c75da17b55d916faca005b7a3a0 Mon Sep 17 00:00:00 2001 From: Athou Date: Fri, 7 Jun 2013 15:56:24 +0200 Subject: [PATCH 3/3] give back the feed to the queue --- .../commafeed/backend/pubsubhubbub/SubscriptionHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java b/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java index 6ca377da..20b807d2 100644 --- a/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java +++ b/src/main/java/com/commafeed/backend/pubsubhubbub/SubscriptionHandler.java @@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory; import com.commafeed.backend.HttpGetter; import com.commafeed.backend.dao.FeedDAO; +import com.commafeed.backend.feeds.FeedRefreshTaskGiver; import com.commafeed.backend.feeds.FeedUtils; import com.commafeed.backend.model.Feed; import com.commafeed.backend.services.ApplicationSettingsService; @@ -33,7 +34,7 @@ public class SubscriptionHandler { ApplicationSettingsService applicationSettingsService; @Inject - FeedDAO feedDAO; + FeedRefreshTaskGiver taskGiver; public void subscribe(Feed feed) { @@ -80,7 +81,7 @@ public class SubscriptionHandler { && StringUtils.contains(message, pushpressError)) { String[] tokens = message.split(" "); feed.setPushTopic(tokens[tokens.length - 1]); - feedDAO.saveOrUpdate(feed); + taskGiver.giveBack(feed); log.debug("handled pushpress subfeed {} : {}", topic, feed.getPushTopic()); } else {