[jboss-cvs] JBossBlog SVN: r319 - in trunk: resources/WEB-INF and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 10 06:16:58 EDT 2008
Author: adamw
Date: 2008-06-10 06:16:58 -0400 (Tue, 10 Jun 2008)
New Revision: 319
Added:
trunk/src/action/org/jboss/blog/session/exceptions/
trunk/src/action/org/jboss/blog/session/exceptions/FeedNotFoundRuntimeException.java
trunk/src/action/org/jboss/blog/session/exceptions/PostNotFoundRuntimeException.java
trunk/view/error/
trunk/view/error/error.xhtml
trunk/view/error/feed_error.xhtml
trunk/view/error/post_error.xhtml
Modified:
trunk/blog.iml
trunk/resources/WEB-INF/pages.xml
trunk/src/action/org/jboss/blog/session/converter/FeedConverter.java
trunk/src/action/org/jboss/blog/session/converter/PostConverter.java
trunk/src/action/org/jboss/blog/session/update/UpdateHandler.java
trunk/src/action/org/jboss/blog/session/update/UpdateManager.java
trunk/src/action/org/jboss/blog/session/update/UpdateThread.java
trunk/src/model/org/jboss/blog/model/Post.java
Log:
Fixed updates - each feed in a separate transaction, meaningful exceptions when feed/post not found
Modified: trunk/blog.iml
===================================================================
--- trunk/blog.iml 2008-05-30 18:41:59 UTC (rev 318)
+++ trunk/blog.iml 2008-06-10 10:16:58 UTC (rev 319)
@@ -286,6 +286,9 @@
</containerElement>
</packaging>
</configuration>
+ <facet type="jsf" name="JSF" implicit="true">
+ <configuration />
+ </facet>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
Modified: trunk/resources/WEB-INF/pages.xml
===================================================================
--- trunk/resources/WEB-INF/pages.xml 2008-05-30 18:41:59 UTC (rev 318)
+++ trunk/resources/WEB-INF/pages.xml 2008-06-10 10:16:58 UTC (rev 319)
@@ -425,27 +425,40 @@
<!-- Exceptions -->
+ <!-- add in 2.0.2: log="false" -->
+ <exception class="org.jboss.blog.session.exceptions.FeedNotFoundRuntimeException">
+ <redirect view-id="/error/feed_error.xhtml">
+ <message>The requested feed hasn't been found.</message>
+ </redirect>
+ </exception>
+
+ <exception class="org.jboss.blog.session.exceptions.PostNotFoundRuntimeException">
+ <redirect view-id="/error/post_error.xhtml">
+ <message>The requested post hasn't been found.</message>
+ </redirect>
+ </exception>
+
<exception class="org.jboss.seam.framework.EntityNotFoundException">
- <redirect view-id="/error.xhtml">
+ <redirect view-id="/error/error.xhtml">
<message>Not found</message>
</redirect>
</exception>
<exception class="javax.persistence.EntityNotFoundException">
- <redirect view-id="/error.xhtml">
+ <redirect view-id="/error/error.xhtml">
<message>Not found</message>
</redirect>
</exception>
<exception class="javax.persistence.OptimisticLockException">
<end-conversation/>
- <redirect view-id="/error.xhtml">
+ <redirect view-id="/error/error.xhtml">
<message>Another user changed the same data, please try again</message>
</redirect>
</exception>
<exception class="org.jboss.seam.security.AuthorizationException">
- <redirect view-id="/error.xhtml">
+ <redirect view-id="/error/error.xhtml">
<message>You don't have permission to do this</message>
</redirect>
</exception>
@@ -457,13 +470,13 @@
</exception>
<exception class="javax.faces.application.ViewExpiredException">
- <redirect view-id="/error.xhtml">
+ <redirect view-id="/error/error.xhtml">
<message>Your session has timed out, please try again</message>
</redirect>
</exception>
<exception>
- <redirect view-id="/error.xhtml">
+ <redirect view-id="/error/error.xhtml">
<message>Unexpected error, please try again</message>
</redirect>
</exception>
Modified: trunk/src/action/org/jboss/blog/session/converter/FeedConverter.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/converter/FeedConverter.java 2008-05-30 18:41:59 UTC (rev 318)
+++ trunk/src/action/org/jboss/blog/session/converter/FeedConverter.java 2008-06-10 10:16:58 UTC (rev 319)
@@ -3,6 +3,7 @@
import org.jboss.blog.model.feed.Feed;
import org.jboss.blog.service.FeedsService;
import org.jboss.blog.service.FeedNotFoundException;
+import org.jboss.blog.session.exceptions.FeedNotFoundRuntimeException;
import org.jboss.seam.Component;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Transactional;
@@ -26,7 +27,7 @@
try {
return feedsService.getFeed(value);
} catch (FeedNotFoundException e) {
- throw new RuntimeException(e);
+ throw new FeedNotFoundRuntimeException(e.getMessage());
}
}
Modified: trunk/src/action/org/jboss/blog/session/converter/PostConverter.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/converter/PostConverter.java 2008-05-30 18:41:59 UTC (rev 318)
+++ trunk/src/action/org/jboss/blog/session/converter/PostConverter.java 2008-06-10 10:16:58 UTC (rev 319)
@@ -3,6 +3,7 @@
import org.jboss.blog.model.Post;
import org.jboss.blog.service.FeedsService;
import org.jboss.blog.service.PostNotFoundException;
+import org.jboss.blog.session.exceptions.PostNotFoundRuntimeException;
import org.jboss.seam.Component;
import org.jboss.seam.log.Log;
import org.jboss.seam.annotations.Name;
@@ -27,7 +28,7 @@
try {
return feedsService.getPost(value);
} catch (PostNotFoundException e) {
- throw new RuntimeException(e);
+ throw new PostNotFoundRuntimeException(e.getMessage());
}
}
Added: trunk/src/action/org/jboss/blog/session/exceptions/FeedNotFoundRuntimeException.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/exceptions/FeedNotFoundRuntimeException.java (rev 0)
+++ trunk/src/action/org/jboss/blog/session/exceptions/FeedNotFoundRuntimeException.java 2008-06-10 10:16:58 UTC (rev 319)
@@ -0,0 +1,21 @@
+package org.jboss.blog.session.exceptions;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class FeedNotFoundRuntimeException extends RuntimeException {
+ public FeedNotFoundRuntimeException() {
+ }
+
+ public FeedNotFoundRuntimeException(String message) {
+ super(message);
+ }
+
+ public FeedNotFoundRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public FeedNotFoundRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
Added: trunk/src/action/org/jboss/blog/session/exceptions/PostNotFoundRuntimeException.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/exceptions/PostNotFoundRuntimeException.java (rev 0)
+++ trunk/src/action/org/jboss/blog/session/exceptions/PostNotFoundRuntimeException.java 2008-06-10 10:16:58 UTC (rev 319)
@@ -0,0 +1,21 @@
+package org.jboss.blog.session.exceptions;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class PostNotFoundRuntimeException extends RuntimeException {
+ public PostNotFoundRuntimeException() {
+ }
+
+ public PostNotFoundRuntimeException(String message) {
+ super(message);
+ }
+
+ public PostNotFoundRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public PostNotFoundRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
Modified: trunk/src/action/org/jboss/blog/session/update/UpdateHandler.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/update/UpdateHandler.java 2008-05-30 18:41:59 UTC (rev 318)
+++ trunk/src/action/org/jboss/blog/session/update/UpdateHandler.java 2008-06-10 10:16:58 UTC (rev 319)
@@ -4,6 +4,8 @@
import org.jboss.blog.model.feed.RestrictedFeed;
import org.jboss.blog.model.Group;
import org.jboss.blog.service.GroupsService;
+import org.jboss.blog.service.FeedsService;
+import org.jboss.blog.service.FeedNotFoundException;
import org.jboss.blog.session.feed.type.FeedTypes;
import org.jboss.blog.session.security.FeedsIdentity;
import org.jboss.seam.annotations.AutoCreate;
@@ -13,6 +15,8 @@
import org.jboss.seam.ScopeType;
import javax.ejb.Remove;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author Adam Warski (adam at warski dot org)
@@ -25,6 +29,9 @@
private GroupsService groupsService;
@In
+ private FeedsService feedsService;
+
+ @In
private FeedTypes feedTypes;
@In
@@ -33,19 +40,31 @@
@In(create = true)
private FeedsIdentity identity;
- public void update() {
- identity.loginAsAdmin();
+ public List<String> getFeedsToUpdate() {
+ List<String> ret = new ArrayList<String>();
+
for (Group group : groupsService.getAllGroups()) {
for (Feed feed : groupsService.acceptedFeeds(group)) {
- update(feed);
+ ret.add(feed.getName());
}
for (Feed feed : groupsService.restrictedFeeds(group)) {
- update(feed);
+ ret.add(feed.getName());
}
}
+
+ return ret;
}
+ public void update(String feedName) {
+ try {
+ update(feedsService.getFeed(feedName));
+ } catch (FeedNotFoundException e) {
+ //noinspection ThrowableInstanceNeverThrown
+ updateManager.addFeedUpdateException(feedName, new UpdateException(e));
+ }
+ }
+
public void update(RestrictedFeed feed) {
identity.loginAsAdmin();
try {
Modified: trunk/src/action/org/jboss/blog/session/update/UpdateManager.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/update/UpdateManager.java 2008-05-30 18:41:59 UTC (rev 318)
+++ trunk/src/action/org/jboss/blog/session/update/UpdateManager.java 2008-06-10 10:16:58 UTC (rev 319)
@@ -44,8 +44,6 @@
globalExceptions = new ArrayList<Exception>();
feedUpdateExceptions = new LinkedHashMap<String, List<UpdateException>>();
- updateInProgress = new AtomicBoolean(false);
-
createAndStartExcutor();
}
@@ -57,6 +55,8 @@
private void createAndStartExcutor() {
executor = Executors.newScheduledThreadPool(1);
executor.scheduleAtFixedRate(new UpdateThread(), 10, getUpdateInterval(), TimeUnit.SECONDS);
+
+ updateInProgress = new AtomicBoolean(false);
}
public void addFeedUpdateException(String feedName, UpdateException exception) {
@@ -66,11 +66,17 @@
feedUpdateExceptions.put(feedName, exceptions);
}
- if (exceptions.size() < 10) {
+ if (exceptions.size() < 3) {
exceptions.add(exception);
}
}
+ public void addGlobalException(Exception exception) {
+ if (globalExceptions.size() < 3) {
+ globalExceptions.add(exception);
+ }
+ }
+
public List<UpdateException> getFeedUpdateExceptionsForFeed(String feedName) {
return feedUpdateExceptions.get(feedName);
}
Modified: trunk/src/action/org/jboss/blog/session/update/UpdateThread.java
===================================================================
--- trunk/src/action/org/jboss/blog/session/update/UpdateThread.java 2008-05-30 18:41:59 UTC (rev 318)
+++ trunk/src/action/org/jboss/blog/session/update/UpdateThread.java 2008-06-10 10:16:58 UTC (rev 319)
@@ -9,12 +9,57 @@
import javax.transaction.Status;
import java.text.DateFormat;
import java.util.Date;
+import java.util.List;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class UpdateThread implements Runnable {
public void run() {
+ List<String> feedsToUpdate = executeInTransaction(new RunnableWithReturn<List<String>>() {
+ public List<String> run() {
+ UpdateManager updateManager = (UpdateManager) Component.getInstance("updateManager");
+
+ if (!updateManager.getUpdateInProgress().getAndSet(true)) {
+ updateManager.setLastUpdateStart(System.currentTimeMillis());
+
+ return ((UpdateHandler) Component.getInstance("updateHandler")).getFeedsToUpdate();
+ } else {
+ //noinspection ThrowableInstanceNeverThrown
+ updateManager.addGlobalException(new Exception("New update started before the last one finished, " +
+ "at " + DateFormat.getDateTimeInstance().format(new Date()) + "!"));
+
+ updateManager.setLastUpdateEnd(System.currentTimeMillis());
+ updateManager.getUpdateInProgress().set(false);
+ return null;
+ }
+ }
+ });
+
+ if (feedsToUpdate != null) {
+ for (final String feedName : feedsToUpdate) {
+ executeInTransaction(new RunnableWithReturn<Object>() {
+ public Object run() {
+ ((UpdateHandler) Component.getInstance("updateHandler")).update(feedName);
+ return null;
+ }
+ });
+ }
+
+ executeInTransaction(new RunnableWithReturn<Object>() {
+ public List<Object> run() {
+ UpdateManager updateManager = (UpdateManager) Component.getInstance("updateManager");
+
+ updateManager.setLastUpdateEnd(System.currentTimeMillis());
+ updateManager.getUpdateInProgress().set(false);
+
+ return null;
+ }
+ });
+ }
+ }
+
+ private <T> T executeInTransaction(RunnableWithReturn<T> runnable) {
try {
boolean createContexts = !Contexts.isEventContextActive() && !Contexts.isApplicationContextActive();
if (createContexts) {
@@ -31,30 +76,13 @@
tx.begin();
}
- UpdateManager updateManager = (UpdateManager) Component.getInstance("updateManager");
+ T ret = runnable.run();
- try {
- if (!updateManager.getUpdateInProgress().getAndSet(true)) {
- updateManager.setLastUpdateStart(System.currentTimeMillis());
-
- ((UpdateHandler) Component.getInstance("updateHandler")).update();
-
- updateManager.setLastUpdateEnd(System.currentTimeMillis());
- updateManager.getUpdateInProgress().set(false);
- } else {
- throw new Exception("New update started before the last one finished, at " +
- DateFormat.getDateTimeInstance().format(new Date()) + "!");
- }
- } catch (Exception e) {
- updateManager.getGlobalExceptions().add(e);
-
- updateManager.setLastUpdateEnd(System.currentTimeMillis());
- updateManager.getUpdateInProgress().set(false);
- }
-
if (txStarted) {
tx.commit();
}
+
+ return ret;
} catch (Throwable e) {
try {
if (txStarted) {
@@ -63,6 +91,8 @@
} catch (Throwable e1) {
Logging.getLog(UpdateManager.class).error("Exception when rolling back the transaction", e1);
}
+
+ return null;
}
} finally {
if (createContexts) {
@@ -71,6 +101,11 @@
}
} catch (Throwable t) {
Logging.getLog(UpdateManager.class).error("Exception when updating!", t);
+ return null;
}
}
+
+ private static interface RunnableWithReturn<T> {
+ T run();
+ }
}
Modified: trunk/src/model/org/jboss/blog/model/Post.java
===================================================================
--- trunk/src/model/org/jboss/blog/model/Post.java 2008-05-30 18:41:59 UTC (rev 318)
+++ trunk/src/model/org/jboss/blog/model/Post.java 2008-06-10 10:16:58 UTC (rev 319)
@@ -218,7 +218,7 @@
public int compareTo(RestrictedPost post2) {
int result = - GeneralTools.compareDates(getPublished(), post2.getPublished());
if (result == 0) {
- return GeneralTools.compareStrings(getTitleAsId(), post2.getTitleAsId());
+ return GeneralTools.compareStrings(getTitle(), post2.getTitle());
} else {
return result;
}
Copied: trunk/view/error/error.xhtml (from rev 315, trunk/view/error.xhtml)
===================================================================
--- trunk/view/error/error.xhtml (rev 0)
+++ trunk/view/error/error.xhtml 2008-06-10 10:16:58 UTC (rev 319)
@@ -0,0 +1,16 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:s="http://jboss.com/products/seam/taglib"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ template="../layout/template.xhtml">
+ <ui:define name="header">
+ Error
+ </ui:define>
+
+ <ui:define name="body">
+ <p>Something bad happened :-(</p>
+ </ui:define>
+</ui:composition>
Added: trunk/view/error/feed_error.xhtml
===================================================================
--- trunk/view/error/feed_error.xhtml (rev 0)
+++ trunk/view/error/feed_error.xhtml 2008-06-10 10:16:58 UTC (rev 319)
@@ -0,0 +1,15 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:s="http://jboss.com/products/seam/taglib"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ template="../layout/template.xhtml">
+ <ui:define name="header">
+ Feed not found
+ </ui:define>
+
+ <ui:define name="body">
+ </ui:define>
+</ui:composition>
Added: trunk/view/error/post_error.xhtml
===================================================================
--- trunk/view/error/post_error.xhtml (rev 0)
+++ trunk/view/error/post_error.xhtml 2008-06-10 10:16:58 UTC (rev 319)
@@ -0,0 +1,15 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:s="http://jboss.com/products/seam/taglib"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ template="../layout/template.xhtml">
+ <ui:define name="header">
+ Post not found
+ </ui:define>
+
+ <ui:define name="body">
+ </ui:define>
+</ui:composition>
More information about the jboss-cvs-commits
mailing list