Author: ruwan
Date: Mon Nov 26 04:31:11 2007
New Revision: 598249
URL: http://svn.apache.org/viewvc?rev=598249&view=rev
Log:
Perf improvements to the caching on clustered env
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorFactory.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorFactory.java?rev=598249&r1=598248&r2=598249&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorFactory.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorFactory.java
Mon Nov 26 04:31:11 2007
@@ -33,7 +33,7 @@
* Creates an instance of a Cache mediator using XML configuration specified
*
* <cache (id="string")? scope="string" collector=(true | false)
- * hashGenerator="class" timeout="mili-seconds">
+ * hashGenerator="class" timeout="mili-seconds"
maxMessageSize="in-bytes">
* <onCacheHit (sequence="key")?>
* (mediator)+
* </onCacheHit>
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorSerializer.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorSerializer.java?rev=598249&r1=598248&r2=598249&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorSerializer.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CacheMediatorSerializer.java
Mon Nov 26 04:31:11 2007
@@ -27,7 +27,7 @@
* Serializes the Cache mediator to the XML configuration specified
* <p/>
* <cache (id="string")? scope="string" collector=(true | false)
- * hashGenerator="class" timeout="mili-seconds">
+ * hashGenerator="class" timeout="mili-seconds"
maxMessageSize="in-bytes">
* <onCacheHit (sequence="key")?>
* (mediator)+
* </onCacheHit>
@@ -71,7 +71,8 @@
if (mediator.getMaxMessageSize() != 0) {
cache.addAttribute(
- fac.createOMAttribute("maxMessageSize", nullNS,
Integer.toString(mediator.getMaxMessageSize())));
+ fac.createOMAttribute("maxMessageSize", nullNS,
+ Integer.toString(mediator.getMaxMessageSize())));
}
if (mediator.getOnCacheHitRef() != null) {
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java?rev=598249&r1=598248&r2=598249&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java
Mon Nov 26 04:31:11 2007
@@ -100,8 +100,8 @@
ConfigurationContext cfgCtx =
((Axis2MessageContext)
synCtx).getAxis2MessageContext().getConfigurationContext();
if (cfgCtx == null) {
- handleException("Unable to perform caching, " + "
ConfigurationContext cannot be found",
- synCtx);
+ handleException("Unable to perform caching, "
+ + " ConfigurationContext cannot be found", synCtx);
return false; // never executes.. but keeps IDE happy
}
@@ -165,8 +165,8 @@
* @param cfgCtx the abstract context in which the cache will be
kept
* @param cache the cache
*/
- private void processResponseMessage(MessageContext synCtx,
ConfigurationContext cfgCtx, boolean traceOrDebugOn,
- boolean traceOn, Cache cache) {
+ private void processResponseMessage(MessageContext synCtx,
ConfigurationContext cfgCtx,
+ boolean traceOrDebugOn, boolean traceOn, Cache cache) {
if (!collector) {
handleException("Response messages cannot be handled in a non
collector cache", synCtx);
@@ -180,7 +180,7 @@
scope + " with ID : " + cacheObjKey + " for request hash :
" + requestHash);
}
- Object obj = cache.getResponseForKey(requestHash);
+ Object obj = cache.getResponseForKey(requestHash, cfgCtx);
if (obj != null && obj instanceof CachedObject) {
@@ -200,9 +200,10 @@
}
/* this is not required yet, can commented this for perf
improvements
- in the future there can be a situation where user sends the
request with the
- response hash (if client side caching is on) in which case
we can compare that
- response hash with the given response hash and respond with
not-modified http header */
+ in the future there can be a situation where user sends the
request
+ with the response hash (if client side caching is on) in
which case
+ we can compare that response hash with the given response
hash and
+ respond with not-modified http header */
// cachedObj.setResponseHash(cache.getGenerator().getDigest(
// ((Axis2MessageContext)
synCtx).getAxis2MessageContext()));
@@ -234,8 +235,8 @@
* @param fbaos the serialized request envelope
* @return should this mediator terminate further processing?
*/
- private boolean processRequestMessage(MessageContext synCtx,
ConfigurationContext cfgCtx, boolean traceOrDebugOn,
- boolean traceOn, Cache cache, FixedByteArrayOutputStream fbaos) {
+ private boolean processRequestMessage(MessageContext synCtx,
ConfigurationContext cfgCtx,
+ boolean traceOrDebugOn, boolean traceOn, Cache cache,
FixedByteArrayOutputStream fbaos) {
if (collector) {
handleException("Request messages cannot be handled in a collector
cache", synCtx);
@@ -250,11 +251,11 @@
}
if (cache.containsKey(requestHash) &&
- cache.getResponseForKey(requestHash) instanceof CachedObject) {
+ cache.getResponseForKey(requestHash, cfgCtx) instanceof
CachedObject) {
// get the response from the cache and attach to the context and
change the
// direction of the message
- CachedObject cachedObj = (CachedObject)
cache.getResponseForKey(requestHash);
+ CachedObject cachedObj = (CachedObject)
cache.getResponseForKey(requestHash, cfgCtx);
if (!cachedObj.isExpired() && cachedObj.getResponseEnvelope() !=
null) {
@@ -328,9 +329,9 @@
} else {
// if not found in cache, check if we can cache this request
- if (cache.getCache().size() == inMemoryCacheSize) {
- cache.removeExpiredResponses();
- if (cache.getCache().size() == inMemoryCacheSize) {
+ if (cache.getCacheKeys().size() == inMemoryCacheSize) {
+ cache.removeExpiredResponses(cfgCtx);
+ if (cache.getCacheKeys().size() == inMemoryCacheSize) {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "In-memory cache is full. Unable
to cache");
}
@@ -353,15 +354,15 @@
* @param cache the cache
* @param fbaos the serialized request envelope
*/
- private void storeRequestToCache(MessageContext synCtx,
ConfigurationContext cfgCtx, String requestHash, Cache cache,
- FixedByteArrayOutputStream fbaos) {
+ private void storeRequestToCache(MessageContext synCtx,
ConfigurationContext cfgCtx,
+ String requestHash, Cache cache, FixedByteArrayOutputStream fbaos) {
CachedObject cachedObj = new CachedObject();
if (fbaos != null) {
cachedObj.setRequestEnvelope(fbaos.toByteArray());
} else {
- // this else block can be commented out for the perf improvements,
because we are not using
- // this for the moment
+ // this else block can be commented out for the perf improvements,
+ // because we are not using this for the moment
ByteArrayOutputStream requestStream = new ByteArrayOutputStream();
try {
MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope()).serialize(requestStream);
@@ -372,7 +373,7 @@
}
cachedObj.setRequestHash(requestHash);
cachedObj.setTimeout(timeout);
- cache.addResponseWithKey(requestHash, cachedObj);
+ cache.addResponseWithKey(requestHash, cachedObj, cfgCtx);
cfgCtx.setProperty(cacheObjKey, cache);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]