You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2008/04/02 08:07:12 UTC
svn commit: r643756 - in
/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow:
ContinuationsManagerImpl.java WebContinuation.java
Author: joerg
Date: Tue Apr 1 23:07:11 2008
New Revision: 643756
URL: http://svn.apache.org/viewvc?rev=643756&view=rev
Log:
formatting
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java?rev=643756&r1=643755&r2=643756&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/ContinuationsManagerImpl.java Tue Apr 1 23:07:11 2008
@@ -16,6 +16,21 @@
*/
package org.apache.cocoon.components.flow;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -27,12 +42,14 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
+
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.thread.RunnableManager;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.util.Deprecation;
+
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.FilterIterator;
@@ -41,21 +58,6 @@
import org.apache.excalibur.instrument.Instrumentable;
import org.apache.excalibur.instrument.ValueInstrument;
-import java.security.SecureRandom;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionBindingListener;
-
/**
* The default implementation of {@link ContinuationsManager}. <br/>There are
* two modes of work: <br/>
@@ -123,7 +125,6 @@
protected CounterInstrument continuationsInvalidated;
public ContinuationsManagerImpl() throws Exception {
-
try {
random = SecureRandom.getInstance("SHA1PRNG");
} catch(java.security.NoSuchAlgorithmException nsae) {
@@ -139,32 +140,23 @@
continuationsInvalidated = new CounterInstrument("invalidates");
}
- /**
- * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
- */
public void contextualize(Context context) throws ContextException {
this.context = context;
}
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(final ServiceManager manager) throws ServiceException {
+ public void service(ServiceManager manager) throws ServiceException {
this.serviceManager = manager;
}
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
- */
public void configure(Configuration config) {
this.defaultTimeToLive = config.getAttributeAsInteger("time-to-live", (3600 * 1000));
this.isContinuationSharingBugCompatible = config.getAttributeAsBoolean("continuation-sharing-bug-compatible", false);
this.bindContinuationsToSession = config.getAttributeAsBoolean( "session-bound-continuations", false );
// create a global ContinuationsHolder if this the "session-bound-continuations" parameter is set to false
- if(!this.bindContinuationsToSession) {
+ if (!this.bindContinuationsToSession) {
this.continuationsHolder = new WebContinuationsHolder();
- }
+ }
// create a thread that invalidates the continuations
final Configuration expireConf = config.getChild("expirations-check");
@@ -185,23 +177,14 @@
}
}
- /**
- * @see org.apache.excalibur.instrument.Instrumentable#setInstrumentableName(java.lang.String)
- */
public void setInstrumentableName(String instrumentableName) {
this.instrumentableName = instrumentableName;
}
- /**
- * @see org.apache.excalibur.instrument.Instrumentable#getInstrumentableName()
- */
public String getInstrumentableName() {
return instrumentableName;
}
- /**
- * @see org.apache.excalibur.instrument.Instrumentable#getInstruments()
- */
public Instrument[] getInstruments() {
return new Instrument[]{
continuationsCount,
@@ -210,16 +193,10 @@
};
}
- /**
- * @see org.apache.excalibur.instrument.Instrumentable#getChildInstrumentables()
- */
public Instrumentable[] getChildInstrumentables() {
return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
}
- /**
- * @see org.apache.cocoon.components.flow.ContinuationsManager#createWebContinuation(java.lang.Object, org.apache.cocoon.components.flow.WebContinuation, int, java.lang.String, org.apache.cocoon.components.flow.ContinuationsDisposer)
- */
public WebContinuation createWebContinuation(Object kont,
WebContinuation parent,
int timeToLive,
@@ -236,7 +213,7 @@
expirations.add(wk);
expirationsSize.setValue(expirations.size());
}
-
+
if (getLogger().isDebugEnabled()) {
getLogger().debug("WK: Created continuation " + wk.getId());
}
@@ -244,9 +221,6 @@
return wk;
}
- /**
- * @see org.apache.cocoon.components.flow.ContinuationsManager#lookupWebContinuation(java.lang.String, java.lang.String)
- */
public WebContinuation lookupWebContinuation(String id, String interpreterId) {
WebContinuationsHolder continuationsHolder = lookupWebContinuationsHolder(false);
if (continuationsHolder == null) {
@@ -283,6 +257,7 @@
kont.updateLastAccessTime();
this.expirations.add(kont);
}
+
return kont;
}
@@ -304,9 +279,8 @@
int ttl,
String interpreterId,
ContinuationsDisposer disposer) {
-
char[] result = new char[bytes.length * 2];
- WebContinuation wk = null;
+ WebContinuation wk;
WebContinuationsHolder continuationsHolder = lookupWebContinuationsHolder(true);
while (true) {
random.nextBytes(bytes);
@@ -322,12 +296,11 @@
if (!continuationsHolder.contains(id)) {
if (this.bindContinuationsToSession) {
wk = new HolderAwareWebContinuation(id, kont, parent,
- ttl, interpreterId, disposer,
- continuationsHolder);
- }
- else {
+ ttl, interpreterId, disposer,
+ continuationsHolder);
+ } else {
wk = new WebContinuation(id, kont, parent, ttl,
- interpreterId, disposer);
+ interpreterId, disposer);
}
continuationsHolder.addContinuation(wk);
synchronized (continuationsCount) {
@@ -353,7 +326,7 @@
_invalidate(continuationsHolder, wk);
}
- protected void _invalidate(WebContinuationsHolder continuationsHolder, WebContinuation wk) {
+ private void _invalidate(WebContinuationsHolder continuationsHolder, WebContinuation wk) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("WK: Manual expire of continuation " + wk.getId());
}
@@ -362,6 +335,7 @@
expirations.remove(wk);
expirationsSize.setValue(expirations.size());
}
+
// Invalidate all the children continuations as well
List children = wk.getChildren();
int size = children.size();
@@ -439,7 +413,6 @@
/* Continuations before clean up: */
displayAllContinuations();
displayExpireSet();
-
}
// Clean up expired continuations
@@ -452,10 +425,9 @@
while (expirationIterator.hasNext()) {
WebContinuation wk = (WebContinuation) expirationIterator.next();
expirationIterator.remove();
- WebContinuationsHolder continuationsHolder = null;
+ WebContinuationsHolder continuationsHolder;
if (wk instanceof HolderAwareWebContinuation) {
- continuationsHolder =
- ((HolderAwareWebContinuation) wk).getContinuationsHolder();
+ continuationsHolder = ((HolderAwareWebContinuation) wk).getContinuationsHolder();
} else {
continuationsHolder = this.continuationsHolder;
}
@@ -464,7 +436,7 @@
}
expirationsSize.setValue(expirations.size());
}
-
+
if (getLogger().isDebugEnabled()) {
getLogger().debug("WK Cleaned up " + count + " continuations in " +
(System.currentTimeMillis() - now) + " ms");
@@ -551,12 +523,12 @@
+ " is deprecated and should be replaced with getForest().");
}
List beanList = new ArrayList();
- for(Iterator it = getForest().iterator(); it.hasNext();) {
+ for (Iterator it = getForest().iterator(); it.hasNext();) {
beanList.add(new WebContinuationDataBean((WebContinuation) it.next()));
}
return beanList;
}
-
+
/**
* Dump to Log file the current contents of
* the expirations <code>SortedSet</code>
@@ -651,12 +623,14 @@
private WebContinuationsHolder continuationsHolder;
- public HolderAwareWebContinuation(String id, Object continuation,
- WebContinuation parentContinuation, int timeToLive,
- String interpreterId, ContinuationsDisposer disposer,
- WebContinuationsHolder continuationsHolder) {
- super(id, continuation, parentContinuation, timeToLive,
- interpreterId, disposer);
+ public HolderAwareWebContinuation(String id,
+ Object continuation,
+ WebContinuation parentContinuation,
+ int timeToLive,
+ String interpreterId,
+ ContinuationsDisposer disposer,
+ WebContinuationsHolder continuationsHolder) {
+ super(id, continuation, parentContinuation, timeToLive, interpreterId, disposer);
this.continuationsHolder = continuationsHolder;
}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java?rev=643756&r1=643755&r2=643756&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/WebContinuation.java Tue Apr 1 23:07:11 2008
@@ -149,8 +149,9 @@
* @param name the attribute name.
*/
public Object getAttribute(String name) {
- if (this.attributes == null)
+ if (this.attributes == null) {
return null;
+ }
return this.attributes.get(name);
}
@@ -368,7 +369,7 @@
public boolean hasExpired() {
long currentTime = System.currentTimeMillis();
long expireTime = this.getLastAccessTime() + this.timeToLive;
-
+
return (currentTime > expireTime);
}
@@ -392,14 +393,15 @@
}
public boolean interpreterMatches( String interpreterId ) {
- return StringUtils.equals( this.interpreterId, interpreterId );
+ return StringUtils.equals(this.interpreterId, interpreterId);
}
public void detachFromParent() {
- if (getParentContinuation() != null)
+ if (getParentContinuation() != null) {
getParentContinuation().getChildren().remove(this);
+ }
}
-
+
/**
* Creates a clone of this WebContinuation without trying to clone the actual continuation, the
* user object or the disposer.
@@ -422,7 +424,7 @@
}
return clone;
}
-
+
/**
* Debugging method.
*
@@ -452,7 +454,7 @@
.append(id)
.append(" ExpireTime [");
- if ((lastAccessTime + timeToLive) < System.currentTimeMillis()) {
+ if (hasExpired()) {
tree.append("Expired");
} else {
tree.append(lastAccessTime + timeToLive);