mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
allows http threads to continue their job by asynchronously queuing database updates
This commit is contained in:
@@ -303,8 +303,8 @@
|
||||
</subsystem>
|
||||
<subsystem xmlns="urn:jboss:domain:messaging:1.2">
|
||||
<hornetq-server>
|
||||
<clustered>true</clustered>
|
||||
<persistence-enabled>true</persistence-enabled>
|
||||
<clustered>false</clustered>
|
||||
<persistence-enabled>false</persistence-enabled>
|
||||
<security-enabled>false</security-enabled>
|
||||
<journal-file-size>102400</journal-file-size>
|
||||
<journal-min-files>2</journal-min-files>
|
||||
@@ -359,6 +359,7 @@
|
||||
<entry name="java:/ConnectionFactory" />
|
||||
</entries>
|
||||
</connection-factory>
|
||||
<!--
|
||||
<connection-factory name="RemoteConnectionFactory">
|
||||
<connectors>
|
||||
<connector-ref connector-name="netty" />
|
||||
@@ -367,6 +368,7 @@
|
||||
<entry name="java:jboss/exported/jms/RemoteConnectionFactory" />
|
||||
</entries>
|
||||
</connection-factory>
|
||||
-->
|
||||
<pooled-connection-factory name="hornetq-ra">
|
||||
<transaction mode="xa" />
|
||||
<connectors>
|
||||
@@ -377,6 +379,12 @@
|
||||
</entries>
|
||||
</pooled-connection-factory>
|
||||
</jms-connection-factories>
|
||||
<jms-destinations>
|
||||
<jms-queue name="refreshQueue">
|
||||
<entry name="jms/refreshQueue"/>
|
||||
<entry name="java:jboss/exported/jms/refreshQueue"/>
|
||||
</jms-queue>
|
||||
</jms-destinations>
|
||||
</hornetq-server>
|
||||
</subsystem>
|
||||
<subsystem xmlns="urn:jboss:domain:naming:1.2">
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.commafeed.backend.feeds;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.ejb.ActivationConfigProperty;
|
||||
import javax.ejb.MessageDriven;
|
||||
import javax.inject.Inject;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageListener;
|
||||
import javax.jms.ObjectMessage;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.dao.FeedDAO;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.services.FeedUpdateService;
|
||||
|
||||
@MessageDriven(name = "FeedRefreshUpdater", activationConfig = {
|
||||
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
|
||||
@ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/refreshQueue") })
|
||||
public class FeedRefreshUpdater implements MessageListener {
|
||||
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(FeedRefreshUpdater.class);
|
||||
|
||||
@Inject
|
||||
FeedDAO feedDAO;
|
||||
|
||||
@Inject
|
||||
FeedUpdateService feedUpdateService;
|
||||
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
if (message instanceof ObjectMessage) {
|
||||
ObjectMessage objectMessage = (ObjectMessage) message;
|
||||
try {
|
||||
FeedRefreshTask task = (FeedRefreshTask) objectMessage
|
||||
.getObject();
|
||||
|
||||
if (task.getEntries() != null) {
|
||||
feedUpdateService.updateEntries(task.getFeed(),
|
||||
task.getEntries());
|
||||
}
|
||||
feedDAO.update(task.getFeed());
|
||||
} catch (JMSException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class FeedRefreshTask implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Feed feed;
|
||||
private Collection<FeedEntry> entries;
|
||||
|
||||
public FeedRefreshTask(Feed feed, Collection<FeedEntry> entries) {
|
||||
this.feed = feed;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public Feed getFeed() {
|
||||
return feed;
|
||||
}
|
||||
|
||||
public Collection<FeedEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,19 @@
|
||||
package com.commafeed.backend.feeds;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.ObjectMessage;
|
||||
import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.NotSupportedException;
|
||||
@@ -16,24 +26,24 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.HttpGetter.NotModifiedException;
|
||||
import com.commafeed.backend.dao.FeedDAO;
|
||||
import com.commafeed.backend.feeds.FeedRefreshUpdater.FeedRefreshTask;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.services.FeedUpdateService;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
|
||||
public class FeedRefreshWorker {
|
||||
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(FeedRefreshWorker.class);
|
||||
|
||||
@Resource(name = "jms/refreshQueue")
|
||||
private Queue queue;
|
||||
|
||||
@Resource
|
||||
private ConnectionFactory connectionFactory;
|
||||
|
||||
@Inject
|
||||
FeedFetcher fetcher;
|
||||
|
||||
@Inject
|
||||
FeedDAO feedDAO;
|
||||
|
||||
@Inject
|
||||
FeedUpdateService feedUpdateService;
|
||||
|
||||
@Inject
|
||||
FeedRefreshTaskGiver taskGiver;
|
||||
|
||||
@@ -68,7 +78,7 @@ public class FeedRefreshWorker {
|
||||
private void update(Feed feed) throws NotSupportedException,
|
||||
SystemException, SecurityException, IllegalStateException,
|
||||
RollbackException, HeuristicMixedException,
|
||||
HeuristicRollbackException {
|
||||
HeuristicRollbackException, JMSException {
|
||||
|
||||
String message = null;
|
||||
int errorCount = 0;
|
||||
@@ -115,16 +125,32 @@ public class FeedRefreshWorker {
|
||||
feed.setMessage(message);
|
||||
feed.setDisabledUntil(disabledUntil);
|
||||
|
||||
Collection<FeedEntry> entries = null;
|
||||
if (fetchedFeed != null) {
|
||||
feed.setLink(fetchedFeed.getLink());
|
||||
feed.setLastModifiedHeader(fetchedFeed.getLastModifiedHeader());
|
||||
feed.setEtagHeader(fetchedFeed.getEtagHeader());
|
||||
feedUpdateService.updateEntries(feed, fetchedFeed.getEntries());
|
||||
entries = fetchedFeed.getEntries();
|
||||
}
|
||||
feedDAO.update(feed);
|
||||
FeedRefreshTask task = new FeedRefreshTask(feed, entries);
|
||||
send(task);
|
||||
|
||||
}
|
||||
|
||||
private void send(FeedRefreshTask task) throws JMSException {
|
||||
Connection connection = connectionFactory.createConnection();
|
||||
connection.start();
|
||||
Session session = connection.createSession(false,
|
||||
Session.AUTO_ACKNOWLEDGE);
|
||||
MessageProducer producer = session.createProducer(queue);
|
||||
producer.setDisableMessageID(true);
|
||||
producer.setDisableMessageTimestamp(true);
|
||||
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
|
||||
ObjectMessage message = session.createObjectMessage(task);
|
||||
producer.send(message);
|
||||
connection.close();
|
||||
}
|
||||
|
||||
private Feed getNextFeed() {
|
||||
return taskGiver.take();
|
||||
}
|
||||
|
||||
@@ -9,11 +9,10 @@
|
||||
MaxActive 50
|
||||
</Resource>
|
||||
-->
|
||||
<!--
|
||||
<Container id="CommaFeedStateless" type="STATELESS">
|
||||
MaxSize=50
|
||||
PoolSize=50
|
||||
StrictPooling=true
|
||||
<Container id="CommaFeedMessage" type="MESSAGE">
|
||||
InstanceLimit 5
|
||||
ResourceAdapter=JMSCommaFeedAdapter
|
||||
</Container>
|
||||
-->
|
||||
<Resource id="JMSCommaFeedAdapter" type="ActiveMQResourceAdapter">
|
||||
</Resource>
|
||||
</tomee>
|
||||
|
||||
Reference in New Issue
Block a user