From: <jbo...@li...> - 2006-04-20 21:33:53
|
Author: adamw Date: 2006-04-20 17:33:41 -0400 (Thu, 20 Apr 2006) New Revision: 3859 Modified: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/META-INF/jboss-service.xml labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-cms.sar/META-INF/jboss-service.xml labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/service/ForgeManagement.java labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeServiceManagement.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-82 Modified: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/META-INF/jboss-service.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/META-INF/jboss-service.xml 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/META-INF/jboss-service.xml 2006-04-20 21:33:41 UTC (rev 3859) @@ -605,7 +605,7 @@ code="org.jboss.labs.mapper.LabsCommandMapper" name="portal:mapper=Labs" xmbean-dd="org/jboss/labs/mapper/LabsCommandMapper.xml"> - <depends>shotoku:service=shotoku</depends> + <depends>shotoku:service=shotoku</depends> <depends optional-attribute-name="NextMapper" proxy-type="attribute">portal:mapper=DefaultPortal</depends> <depends optional-attribute-name="Container" proxy-type="attribute">portal:container=PortalObject,type=global</depends> Modified: labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-cms.sar/META-INF/jboss-service.xml =================================================================== --- labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-cms.sar/META-INF/jboss-service.xml 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/configuration/to-copy/jboss-portal.sar/portal-cms.sar/META-INF/jboss-service.xml 2006-04-20 21:33:41 UTC (rev 3859) @@ -4,6 +4,7 @@ name="portal:service=CMS" xmbean-dd="org/jboss/shotoku/portal/ShotokuCMS.xml"> <depends>shotoku:service=shotoku</depends> + <depends>shotoku:service=svn</depends> <attribute name="RepositoryId">default</attribute> <attribute name="RepositoryPrefix"></attribute> <attribute name="DefaultLocale">en</attribute> Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/service/ForgeManagement.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/service/ForgeManagement.java 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/service/ForgeManagement.java 2006-04-20 21:33:41 UTC (rev 3859) @@ -21,66 +21,64 @@ */ package org.jboss.forge.common.service; +import org.jboss.shotoku.service.AdministratedService; + /** * @author adamw * Forge management - cache and update functions. */ -public interface ForgeManagement { - /** - * Adds the given value to the given cache node. - * @param portalName Name of the portal to which this value is - * specific. - * @param key Unique key under which the value should be placed. - * @param value Value to put. - */ - public void putToCache(String portalName, String key, Object value); - /** - * Gets a value from the given cache node. - * @param portalName Name of the portal to which this value is - * specific. - * @param key Unique key under which the value can be found. - * @return Value that can be found under the given portalName - * and key or null if no such value exists. - */ - public Object getFromCache(String portalName, String key); - /** - * Adds a node watcher, who's methods will be called periodically - * by the timer service. Generates an intial value of the node - * by calling the <code>nw.init()</code> method and puts it into - * the cache. - * @param portalName Name of the portal to which this value is - * specific. - * @param key Unique key under which value corresponding to this - * watcher can be found. - * @param nw Node watcher to add. - * @return Generated initial value. - */ - public Object addNodeWatcher(String portalName, String key, NodeWatcher nw); - /** - * Forces an update of the given node. The update is accomplished by - * calling the corresponding node watcher's <code>nodeUpdate</code> - * method, so there should be a node watcher registered for this - * node. If there is no node watcher registered, null is returned. - * @param portalName Name of the portal to which this value is - * specific. - * @param key Unique key under which the node watcher can be found. - * @return An update object or null, if there is no node watcher associated - * with the given key. - */ - public Object forceNodeUpdate(String portalName, String key); - /** - * Updates the forge: executes update methods of all node watchers. - */ - public void update(); - /** - * Sets the forge timer interval, that is, time that elapses between two calls - * of <code>update()</code>. - * @param interval New forge timer interval. - */ - public void setTimerInterval(long interval); - /** - * Gets the current forge timer interval, that is, time that elapses between - * two calls of <code>update()</code>. - */ - public long getTimerInterval(); +public interface ForgeManagement extends AdministratedService { + /** + * Adds the given value to the given cache node. + * @param portalName Name of the portal to which this value is + * specific. + * @param key Unique key under which the value should be placed. + * @param value Value to put. + */ + public void putToCache(String portalName, String key, Object value); + /** + * Gets a value from the given cache node. + * @param portalName Name of the portal to which this value is + * specific. + * @param key Unique key under which the value can be found. + * @return Value that can be found under the given portalName + * and key or null if no such value exists. + */ + public Object getFromCache(String portalName, String key); + /** + * Adds a node watcher, who's methods will be called periodically + * by the timer service. Generates an intial value of the node + * by calling the <code>nw.init()</code> method and puts it into + * the cache. + * @param portalName Name of the portal to which this value is + * specific. + * @param key Unique key under which value corresponding to this + * watcher can be found. + * @param nw Node watcher to add. + * @return Generated initial value. + */ + public Object addNodeWatcher(String portalName, String key, NodeWatcher nw); + /** + * Forces an update of the given node. The update is accomplished by + * calling the corresponding node watcher's <code>nodeUpdate</code> + * method, so there should be a node watcher registered for this + * node. If there is no node watcher registered, null is returned. + * @param portalName Name of the portal to which this value is + * specific. + * @param key Unique key under which the node watcher can be found. + * @return An update object or null, if there is no node watcher associated + * with the given key. + */ + public Object forceNodeUpdate(String portalName, String key); + /** + * Sets the forge timer interval, that is, time that elapses between two calls + * of <code>update()</code>. + * @param interval New forge timer interval. + */ + public void setTimerInterval(long interval); + /** + * Gets the current forge timer interval, that is, time that elapses between + * two calls of <code>update()</code>. + */ + public long getTimerInterval(); } Modified: labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeService.java 2006-04-20 21:33:41 UTC (rev 3859) @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Calendar; import javax.ejb.Local; @@ -34,6 +35,10 @@ import org.jboss.forge.common.service.NodeWatcher; import org.jboss.logging.Logger; 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; /** * An implementation of the ForgeManagement interface. @@ -43,161 +48,180 @@ @Local(ForgeServiceLocal.class) @Management(ForgeServiceManagement.class) @Depends(Constants.SHOTOKU_SERVICE_NAME) -public class ForgeService implements ForgeServiceLocal, - ForgeServiceManagement { - private Map<CacheKey, Object> cache; - private Map<CacheKey, NodeWatcher> nodeWatchers; - - private static final Logger log = Logger.getLogger(ForgeService.class); - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#putToCache(java.lang.String, java.lang.String, java.lang.Object) - */ - public void putToCache(String portalName, String key, Object value) { - putToCache(new CacheKey(portalName, key), value); - } - - private void putToCache(CacheKey ck, Object value) { - cache.put(ck, value); - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#getFromCache(java.lang.String, java.lang.String) - */ - public Object getFromCache(String portalName, String key) { - return getFromCache(new CacheKey(portalName, key)); - } - - private Object getFromCache(CacheKey ck) { - return cache.get(ck); - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#addNodeWatcher(java.lang.String, java.lang.String, org.jboss.forge.common.service.NodeWatcher) - */ - public Object addNodeWatcher(String portalName, String key, NodeWatcher nw) { - // Calculating the initial value & putting it into the cache. - Object initialValue = nw.init(portalName); - putToCache(portalName, key, initialValue); - - // Registering a new node watcher. - nodeWatchers.put(new CacheKey(portalName, key), nw); - - return initialValue; - } - - /** - * Updates the value of a node with the specified key. - * @param ck Key of a node which should be updated. - * @return Updated value of the node or null if no node watcher is - * registered under the given key. - */ - private Object updateNode(CacheKey ck) { - NodeWatcher nw = nodeWatchers.get(ck); - if (nw == null) return null; - - Object currentValue = getFromCache(ck); - - Object newValue = null; - try { - newValue = nw.nodeUpdate(ck.getPortalName(), - currentValue); - if (newValue != null) - putToCache(ck, newValue); - } catch (Exception e) { - // In case of an error, doing nothing. - } - - return newValue == null ? currentValue : newValue; - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#update() - */ - public synchronized void update() { - try { - synchronized (nodeWatchers) { - // Updating nodes. - for (CacheKey ck : nodeWatchers.keySet()) { - updateNode(ck); +public class ForgeService extends AdministratedServiceImpl implements ForgeServiceLocal, + ForgeServiceManagement { + private Map<CacheKey, Object> cache; + private Map<CacheKey, NodeWatcher> nodeWatchers; + + private static final Logger log = Logger.getLogger(ForgeService.class); + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#putToCache(java.lang.String, java.lang.String, java.lang.Object) + */ + public void putToCache(String portalName, String key, Object value) { + putToCache(new CacheKey(portalName, key), value); + } + + private void putToCache(CacheKey ck, Object value) { + cache.put(ck, value); + } + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#getFromCache(java.lang.String, java.lang.String) + */ + public Object getFromCache(String portalName, String key) { + return getFromCache(new CacheKey(portalName, key)); + } + + private Object getFromCache(CacheKey ck) { + return cache.get(ck); + } + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#addNodeWatcher(java.lang.String, java.lang.String, org.jboss.forge.common.service.NodeWatcher) + */ + public Object addNodeWatcher(String portalName, String key, NodeWatcher nw) { + // Calculating the initial value & putting it into the cache. + Object initialValue = nw.init(portalName); + putToCache(portalName, key, initialValue); + + // Registering a new node watcher. + nodeWatchers.put(new CacheKey(portalName, key), nw); + + return initialValue; + } + + /** + * Updates the value of a node with the specified key. + * @param ck Key of a node which should be updated. + * @return Updated value of the node or null if no node watcher is + * registered under the given key. + */ + private Object updateNode(CacheKey ck) { + NodeWatcher nw = nodeWatchers.get(ck); + if (nw == null) return null; + + Object currentValue = getFromCache(ck); + + Object newValue = null; + try { + newValue = nw.nodeUpdate(ck.getPortalName(), + currentValue); + if (newValue != null) + putToCache(ck, newValue); + } catch (Exception e) { + // In case of an error, doing nothing. + } + + return newValue == null ? currentValue : newValue; + } + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#update() + */ + public synchronized void update() { + try { + synchronized (nodeWatchers) { + // Updating nodes. + for (CacheKey ck : nodeWatchers.keySet()) { + updateNode(ck); } } - } catch (Exception e) { - log.warn(e); - e.printStackTrace(); - } - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#forceNodeUpdate(java.lang.String, java.lang.String) - */ - public Object forceNodeUpdate(String portalName, String key) { - return updateNode(new CacheKey(portalName, key)); - } - - /** - * <code>DEFAULT_TIMER_INTERVAL</code> - default interval lenght of the - * timer. - */ - private final static long DEFAULT_TIMER_INTERVAL = 1000*30; // 30 seconds. - private long timerInterval; - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#setTimerInterval(long) - */ - public void setTimerInterval(long timerInterval) { - this.timerInterval = timerInterval; - } - - /* (non-Javadoc) - * @see org.jboss.forge.common.service.ForgeManagement#getTimerInterval() - */ - public long getTimerInterval() { - return timerInterval; - } - - public void create() throws Exception { + } catch (Exception e) { + log.warn(e); + e.printStackTrace(); + } + } + + /* (non-Javadoc) + * @see org.jboss.forge.common.service.ForgeManagement#forceNodeUpdate(java.lang.String, java.lang.String) + */ + public Object forceNodeUpdate(String portalName, String key) { + return updateNode(new CacheKey(portalName, key)); + } + + /** + * <code>DEFAULT_TIMER_INTERVAL</code> - default interval lenght of the + * timer. + */ + private final static long DEFAULT_TIMER_INTERVAL = 1000*30; // 30 seconds. + + public void create() throws Exception { + super.create(); + cache = Collections.synchronizedMap( new HashMap<CacheKey, Object>()); nodeWatchers = Collections.synchronizedMap( new HashMap<CacheKey, NodeWatcher>()); // Setting the default timer interval. - timerInterval = DEFAULT_TIMER_INTERVAL; + setTimerInterval(DEFAULT_TIMER_INTERVAL); // And starting the timer. - //timer.scheduleTimer(DEFAULT_TIMER_INTERVAL); + //timer.scheduleTimer(DEFAULT_TIMER_INTERVAL); + + // Enabling administration for this service. + Tools.getService().addAdministratedService(new AdministratedServiceGetter() { + public AdministratedService getService() { + return ForgeHelper.getForgeManagement(); + } + }); + + log.info("Forge service created, with timer interval: " + getTimerInterval()); } - - //@EJB - //private ForgeTimerLocal timer; - public void start() throws Exception { - new Thread() { - { - setDaemon(true); - } + //@EJB + //private ForgeTimerLocal timer; - public void run() { - while (true) { - try { - sleep(getTimerInterval()); - } catch (InterruptedException e) { - e.printStackTrace(); - } + public void start() throws Exception { + super.start(); + new Thread() { + { + setDaemon(true); + } + + public void run() { + 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()); } - } - }.start(); - } - public void stop() { - } + log.info("Forge service thread stopped."); + } + }.start(); - public void destroy() { - } + log.info("Forge service started."); + } + + public void stop() { + super.stop(); + log.info("Forge service stopped."); + } + + public void destroy() { + } + + public String getServiceId() { + return "ForgeService"; + } + + public String getServiceName() { + return "Forge service"; + } + + public String getServiceDescription() { + return "A deprecated forge service which should disappear in the future, when " + + "everybody will stop being lazy and switch to Shotoku services ;)."; + } } Modified: labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeServiceManagement.java =================================================================== --- labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeServiceManagement.java 2006-04-20 21:31:58 UTC (rev 3858) +++ labs/jbosslabs/trunk/portal-extensions/forge-service/src/java/org/jboss/forge/service/ForgeServiceManagement.java 2006-04-20 21:33:41 UTC (rev 3859) @@ -24,8 +24,4 @@ import org.jboss.forge.common.service.ForgeManagement; public interface ForgeServiceManagement extends ForgeManagement { - public void create() throws Exception; - public void start() throws Exception; - public void stop(); - public void destroy(); } |