[jboss-svn-commits] JBL Code SVN: r5204 - in labs/shotoku/trunk: shotoku-base/src/java/org/jboss/shotoku/service shotoku-feeds/src/java/org/jboss/shotoku/feeds/data shotoku-svn/src/java/org/jboss/shotoku/svn/service shotoku-tags/src/java/org/jboss/shotoku/tags/service
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 20 16:51:43 EDT 2006
Author: adamw
Date: 2006-07-20 16:51:38 -0400 (Thu, 20 Jul 2006)
New Revision: 5204
Modified:
labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java
labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java
labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/SpecialFeed.java
labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java
labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java
labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java
Log:
Refactoring
Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java 2006-07-20 18:30:52 UTC (rev 5203)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedService.java 2006-07-20 20:51:38 UTC (rev 5204)
@@ -21,6 +21,8 @@
public void update();
+ public AdministratedService getServiceInstance();
+
/*
* SERVICE MANAGEMENT METHODS
*/
Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java 2006-07-20 18:30:52 UTC (rev 5203)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/AdministratedServiceImpl.java 2006-07-20 20:51:38 UTC (rev 5204)
@@ -1,8 +1,10 @@
package org.jboss.shotoku.service;
import org.apache.log4j.Logger;
+import org.jboss.shotoku.tools.Tools;
import java.util.Date;
+import java.util.Calendar;
/**
* @author Adam Warski (adamw at aster.pl)
@@ -49,6 +51,14 @@
public void start() throws Exception {
log.info("Starting " + getServiceName() + "...");
setServiceRunnable(true);
+
+ // Enabling administration for this service.
+ Tools.getService().addAdministratedService(
+ new AdministratedServiceGetter() {
+ public AdministratedService getService() {
+ return getServiceInstance();
+ }
+ });
}
public void stop() {
@@ -60,4 +70,33 @@
public void destroy() {
log.info("Destroying " + getServiceName() + "...");
}
+
+ public void startUpdateThread() {
+ new Thread() {
+ {
+ setDaemon(true);
+ }
+
+ public void run() {
+ while (getServiceRunnable()) {
+ try {
+ sleep(getTimerInterval());
+ } catch (InterruptedException e) {
+ log.error("Sleeping of updater thread interrupted.", e);
+ }
+
+ try {
+ update();
+ } catch (Throwable t) {
+ // Making sure that an exception won't stop the thread.
+ log.error("Update method threw an exception.", t);
+ }
+
+ setLastUpdate(Calendar.getInstance().getTimeInMillis());
+ }
+
+ log.info(getServiceName() + " deaemon thread terminated.");
+ }
+ }.start();
+ }
}
Modified: labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java 2006-07-20 18:30:52 UTC (rev 5203)
+++ labs/shotoku/trunk/shotoku-base/src/java/org/jboss/shotoku/service/ShotokuServiceImpl.java 2006-07-20 20:51:38 UTC (rev 5204)
@@ -35,7 +35,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.Calendar;
import java.util.Set;
/**
@@ -56,13 +55,6 @@
public void create() throws Exception {
super.create();
- // Enabling administration for this service.
- addAdministratedService(new AdministratedServiceGetter() {
- public AdministratedService getService() {
- return Tools.getService();
- }
- });
-
/*
* Setting up content managers.
*/
@@ -80,34 +72,8 @@
setTimerInterval(ContentManager.getDefaultServiceInterval());
log.info("Timer interval is: "+ getTimerInterval() +". Starting update thread...");
+ startUpdateThread();
- new Thread() {
- {
- setDaemon(true);
- }
-
- public void run() {
- //noinspection InfiniteLoopStatement
- while (getServiceRunnable()) {
- try {
- sleep(getTimerInterval());
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- try {
- update();
- } catch (Throwable t) {
- // Making sure that an exception won't stop the thread.
- }
-
- setLastUpdate(Calendar.getInstance().getTimeInMillis());
- }
-
- log.info("Shotoku service deaemon thread terminated.");
- }
- }.start();
-
log.info("Shotoku service started.");
}
@@ -177,6 +143,9 @@
* Description functions.
*/
+ public AdministratedService getServiceInstance() {
+ return Tools.getService();
+ }
public String getServiceId() {
return "ShotokuService";
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/SpecialFeed.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/SpecialFeed.java 2006-07-20 18:30:52 UTC (rev 5203)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/SpecialFeed.java 2006-07-20 20:51:38 UTC (rev 5204)
@@ -1,7 +1,8 @@
package org.jboss.shotoku.feeds.data;
/**
- * A special feed interface, which has to be concretized, to get a full feed.
+ * A special feed interface, which has to be concretized, to get a full feed
+ * (basing on a specific request data).
* @author Adam Warski (adamw at aster.pl)
*/
public interface SpecialFeed extends Feed {
Modified: labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java
===================================================================
--- labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java 2006-07-20 18:30:52 UTC (rev 5203)
+++ labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/TagFeed.java 2006-07-20 20:51:38 UTC (rev 5204)
@@ -40,6 +40,7 @@
nameLength = name.length();
cm = ContentManager.getContentManager(attributes.get("id"),
attributes.get("prefix"));
+
try {
limit = Integer.parseInt(attributes.get("limit"));
} catch (NumberFormatException e) {
@@ -83,104 +84,76 @@
List<Tag> tags;
TagService service = TagTools.getService();
- if (FeedType.RESOURCE.toString().equals(infoTokens[0])) {
- vc.put(FeedType.RESOURCE.toString(), infoDataDecoded);
+ FeedType ft;
- // Getting the list of tags.
- try {
- tags = TagTools.getService().getUniqueTags(infoDataDecoded);
- } catch (TagGetException e) {
- throw new IOException(e.getMessage());
- }
+ try {
+ ft = FeedType.valueOf(infoTokens[0]);
+ } catch (IllegalArgumentException e) {
+ throw new IOException("Invalid tag feed request.");
+ }
- template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
- FeedType.RESOURCE.toString());
+ String[] feedCounterData = new String[] { infoDataDecoded };
+ try {
+ switch (ft) {
+ case RESOURCE:
+ vc.put("resource", infoDataDecoded);
+ tags = TagTools.getService().getUniqueTags(infoDataDecoded);
+ break;
- service.increaseFeedCounters(FeedType.RESOURCE, infoDataDecoded,
- request.getRemoteAddr());
- } else if (FeedType.AUTHOR_UNIQUE.toString().equals(infoTokens[0])) {
- vc.put("author", infoDataDecoded);
+ case AUTHOR_UNIQUE:
+ vc.put("author", infoDataDecoded);
+ tags = TagTools.getService().getUniqueTagsByAuthor(
+ infoDataDecoded);
+ break;
- // Getting the list of tags.
- try {
- tags = TagTools.getService().getUniqueTagsByAuthor(
- infoDataDecoded);
- } catch (TagGetException e) {
- throw new IOException(e.getMessage());
- }
+ case AUTHOR_ALL:
+ vc.put("author", infoDataDecoded);
+ tags = TagTools.getService().getTagsByAuthor(infoDataDecoded);
+ break;
- template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
- FeedType.AUTHOR_UNIQUE.toString());
+ case AUTHOR_TAG:
+ String[] tagData = infoDataDecoded.split("[+]");
+ if (tagData.length != 2) {
+ throw new IOException("Not enough data for a tag-author" +
+ " feed.");
+ }
- service.increaseFeedCounters(FeedType.AUTHOR_UNIQUE, infoDataDecoded,
- request.getRemoteAddr());
- } else if (FeedType.AUTHOR_ALL.toString().equals(infoTokens[0])) {
- vc.put("author", infoDataDecoded);
+ vc.put("tagName", tagData[0]);
+ vc.put("author", tagData[1]);
+ tags = TagTools.getService().getTags(tagData[0], tagData[1]);
+ break;
- // Getting the list of tags.
- try {
- tags = TagTools.getService().getTagsByAuthor(infoDataDecoded);
- } catch (TagGetException e) {
- throw new IOException(e.getMessage());
- }
+ case TAGS:
+ String[] tagNames = infoDataDecoded.split("[+]");
- template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
- FeedType.AUTHOR_ALL.toString());
+ StringBuffer tagsAsString = new StringBuffer();
+ for (int i=0; i < tagNames.length; i++) {
+ tagsAsString.append(tagNames[i]);
+ if (i < tagNames.length - 1) {
+ tagsAsString.append(", ");
+ }
+ }
- service.increaseFeedCounters(FeedType.AUTHOR_ALL, infoDataDecoded,
- request.getRemoteAddr());
- } else if (FeedType.AUTHOR_TAG.toString().equals(infoTokens[0])) {
- String[] tagData = infoDataDecoded.split("[+]");
- if (tagData.length != 2) {
- throw new IOException("Not enough data for a tag-author" +
- " feed.");
- }
+ vc.put("tagsAsString", tagsAsString.toString());
+ tags = service.getUniqueTags(Arrays.asList(tagNames));
+ feedCounterData = tagNames;
+ break;
- vc.put("tagName", tagData[0]);
- vc.put("author", tagData[1]);
-
- // Getting the list of tags.
- try {
- tags = TagTools.getService().getTags(tagData[0], tagData[1]);
- } catch (TagGetException e) {
- throw new IOException(e.getMessage());
+ default:
+ throw new IOException("Invalid tag feed request.");
}
+ } catch (TagGetException e) {
+ throw new IOException(e.getMessage());
+ }
- template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
- FeedType.AUTHOR_TAG.toString());
-
- service.increaseFeedCounters(FeedType.AUTHOR_TAG, infoDataDecoded,
+ for (String feedCounterSingleData : feedCounterData) {
+ service.increaseFeedCounters(ft, feedCounterSingleData,
request.getRemoteAddr());
- } else if (FeedType.TAGS.toString().equals(infoTokens[0])) {
- String[] tagNames = infoDataDecoded.split("[+]");
-
- StringBuffer tagsAsString = new StringBuffer();
- for (int i=0; i < tagNames.length; i++) {
- tagsAsString.append(tagNames[i]);
- if (i < tagNames.length - 1) {
- tagsAsString.append(", ");
- }
- }
- vc.put("tagsAsString", tagsAsString.toString());
-
- // Getting the tags with the given names.
- try {
- tags = service.getUniqueTags(Arrays.asList(tagNames));
- } catch (TagGetException e) {
- throw new IOException(e.getMessage());
- }
-
- template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
- FeedType.TAGS.toString());
-
- for (String tagName : tagNames) {
- service.increaseFeedCounters(FeedType.TAGS, tagName,
- request.getRemoteAddr());
- }
- } else {
- throw new IOException("Invalid tag feed request.");
}
+ template = template.replace(Constants.TAG_FEED_TYPE_VARIABLE,
+ ft.toString());
+
// Computing the date of the youngest tag.
vc.put("youngest", getYoungestTagDate(tags));
vc.put("tags",
Modified: labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2006-07-20 18:30:52 UTC (rev 5203)
+++ labs/shotoku/trunk/shotoku-svn/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2006-07-20 20:51:38 UTC (rev 5204)
@@ -23,7 +23,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.Calendar;
import java.util.Set;
import javax.ejb.Local;
@@ -38,9 +37,7 @@
import org.jboss.shotoku.svn.SvnContentManager;
import org.jboss.shotoku.svn.service.delayed.DelayedOperation;
import org.jboss.shotoku.tools.Constants;
-import org.jboss.shotoku.tools.Tools;
import org.jboss.shotoku.service.AdministratedServiceImpl;
-import org.jboss.shotoku.service.AdministratedServiceGetter;
import org.jboss.shotoku.service.AdministratedService;
import org.jboss.shotoku.ContentManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
@@ -83,13 +80,6 @@
// Setting the default timer interval.
setTimerInterval(SvnTools.DEFAULT_TIMER_INTERVAL);
- // Enabling administration for this service.
- Tools.getService().addAdministratedService(new AdministratedServiceGetter() {
- public AdministratedService getService() {
- return SvnTools.getService();
- }
- });
-
ContentManager.initializeContentManager(SvnContentManager.class.getName());
log.info("Svn service created.");
@@ -98,34 +88,8 @@
public void start() throws Exception {
super.start();
- // Starting the updater thread.
- new Thread() {
- {
- setDaemon(true);
- }
+ startUpdateThread();
- public void run() {
- while (getServiceRunnable()) {
- try {
- sleep(getTimerInterval());
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- try {
- update();
- } catch (Throwable t) {
- log.debug("SVN update threw an exception.", t);
- // Making sure that an exception won't stop the thread.
- }
-
- setLastUpdate(Calendar.getInstance().getTimeInMillis());
- }
-
- log.info("Subversion Service Deaemon Thread terminated.");
- }
- }.start();
-
log.info("Subversion Service started with update interval: "+ getTimerInterval());
}
@@ -136,6 +100,10 @@
* Timer-handling functions.
*/
+ public AdministratedService getServiceInstance() {
+ return SvnTools.getService();
+ }
+
public void update() {
log.debug("Starting SVN update.");
for (SvnRepository repo : repositories.values()) {
Modified: labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java 2006-07-20 18:30:52 UTC (rev 5203)
+++ labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java 2006-07-20 20:51:38 UTC (rev 5204)
@@ -33,9 +33,7 @@
import org.jboss.annotation.ejb.Service;
import org.jboss.annotation.ejb.Depends;
import org.jboss.shotoku.tools.Constants;
-import org.jboss.shotoku.tools.Tools;
import org.jboss.shotoku.service.AdministratedServiceImpl;
-import org.jboss.shotoku.service.AdministratedServiceGetter;
import org.jboss.shotoku.service.AdministratedService;
import org.jboss.shotoku.tags.*;
import org.jboss.shotoku.tags.tools.TagTools;
@@ -72,14 +70,6 @@
public void create() throws Exception {
super.create();
- // Enabling administration for this service.
- Tools.getService().addAdministratedService(
- new AdministratedServiceGetter() {
- public AdministratedService getService() {
- return TagTools.getService();
- }
- });
-
setTimerInterval(ContentManager.getProperty(
org.jboss.shotoku.tags.tools.Constants.PROPERTY_INTERVAL, 10000));
@@ -206,6 +196,10 @@
return "Shotoku tag service";
}
+ public AdministratedService getServiceInstance() {
+ return TagTools.getService();
+ }
+
/*
* TagService implementation.
*/
More information about the jboss-svn-commits
mailing list