Examples of CachedObject


Examples of org.hsqldb_voltpatches.persist.CachedObject

        PersistentStore store =
            database.persistentStoreCollection.getStore(this);
        int[] roots = new int[getIndexCount()];

        for (int i = 0; i < getIndexCount(); i++) {
            CachedObject accessor = store.getAccessor(indexList[i]);

            roots[i] = accessor == null ? -1
                                        : accessor.getPos();
        }

        return roots;
    }
View Full Code Here

Examples of org.wso2.caching.CachedObject

            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Storing the response message into the cache at scope : " +
                    scope + " with ID : " + cacheKey + " for request hash : " + requestHash);
            }

            CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);
            if (cachedObj != null) {

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Storing the response for the message with ID : " +
                        synCtx.getMessageID() + " with request hash ID : " +
                        cachedObj.getRequestHash() + " in the cache : " + cacheKey);
                }

                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                try {
                    MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope()).serialize(outStream);
                    cachedObj.setResponseEnvelope(outStream.toByteArray());
                } catch (XMLStreamException e) {
                    handleException("Unable to set the response to the Cache", e, synCtx);
                }

                /* 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 */
                // cachedObj.setResponseHash(cache.getGenerator().getDigest(
                //     ((Axis2MessageContext) synCtx).getAxis2MessageContext()));

                if (cachedObj.getTimeout() > 0) {
                    cachedObj.setExpireTimeMillis(System.currentTimeMillis() + cachedObj.getTimeout());
                }

                cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//                Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
                Replicator.replicate(cfgCtx);
View Full Code Here

Examples of org.wso2.caching.CachedObject

        if (cacheManager.containsKey(cacheKey, requestHash) &&
            cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx) != null) {

            // get the response from the cache and attach to the context and change the
            // direction of the message
            CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);

            if (!cachedObj.isExpired() && cachedObj.getResponseEnvelope() != null) {

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Cache-hit for message ID : " + synCtx.getMessageID());
                }

                // mark as a response and replace envelope from cache
                synCtx.setResponse(true);
                try {
                    SOAPEnvelope omSOAPEnv = SOAPMessageHelper.buildSOAPEnvelopeFromBytes(
                            cachedObj.getResponseEnvelope());

                    // todo: if there is a WSA messageID in the response, is that need to be unique on each and every resp

                    synCtx.setEnvelope(omSOAPEnv);
                } catch (AxisFault axisFault) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, synCtx);
                } catch (IOException ioe) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, ioe, synCtx);
                } catch (SOAPException soape) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, soape, synCtx);
                }

                // take specified action on cache hit
                if (onCacheHitSequence != null) {
                    // if there is an onCacheHit use that for the mediation
                    synLog.traceOrDebug("Delegating message to the onCachingHit "
                            + "Anonymous sequence");
                    onCacheHitSequence.mediate(synCtx);

                } else if (onCacheHitRef != null) {

                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Delegating message to the onCachingHit " +
                            "sequence : " + onCacheHitRef);
                    }
                    synCtx.getSequence(onCacheHitRef).mediate(synCtx);

                } else {

                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Request message " + synCtx.getMessageID() +
                            " was served from the cache : " + cacheKey);
                    }
                    // send the response back if there is not onCacheHit is specified
                    synCtx.setTo(null);
                    Axis2Sender.sendBack(synCtx);
                }
                // stop any following mediators from executing
                return false;

            } else {
                // cache exists, but has expired...
                cachedObj.expire();
                cachedObj.setTimeout(timeout);
                synLog.traceOrDebug("Existing cached response has expired. Reset cache element");

                cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//                Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
                Replicator.replicate(cfgCtx);
View Full Code Here

Examples of org.wso2.caching.CachedObject

     * @throws ClusteringFault if there is an error in replicating the cfgCtx
     */
    private void storeRequestToCache(ConfigurationContext cfgCtx,
        String requestHash, CacheManager cacheManager) throws ClusteringFault {

        CachedObject cachedObj = new CachedObject();
        cachedObj.setRequestHash(requestHash);
        // this does not set the expiretime but just sets the timeout and the espiretime will
        // be set when the response is availabel
        cachedObj.setTimeout(timeout);
        cacheManager.addResponseWithKey(cacheKey, requestHash, cachedObj, cfgCtx);

        cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//        Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
        Replicator.replicate(cfgCtx);
View Full Code Here

Examples of org.wso2.caching.CachedObject

            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Storing the response message into the cache at scope : " +
                    scope + " with ID : " + cacheKey + " for request hash : " + requestHash);
            }

            CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);
            if (cachedObj != null) {

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Storing the response for the message with ID : " +
                        synCtx.getMessageID() + " with request hash ID : " +
                        cachedObj.getRequestHash() + " in the cache : " + cacheKey);
                }

                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                try {
                    MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope()).serialize(outStream);
                    cachedObj.setResponseEnvelope(outStream.toByteArray());
                } catch (XMLStreamException e) {
                    handleException("Unable to set the response to the Cache", e, synCtx);
                }

                /* 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 */
                // cachedObj.setResponseHash(cache.getGenerator().getDigest(
                //     ((Axis2MessageContext) synCtx).getAxis2MessageContext()));

                if (cachedObj.getTimeout() > 0) {
                    cachedObj.setExpireTimeMillis(System.currentTimeMillis() + cachedObj.getTimeout());
                }

                cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//                Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
                Replicator.replicate(cfgCtx);
View Full Code Here

Examples of org.wso2.caching.CachedObject

        if (cacheManager.containsKey(cacheKey, requestHash) &&
            cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx) != null) {

            // get the response from the cache and attach to the context and change the
            // direction of the message
            CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);

            if (!cachedObj.isExpired() && cachedObj.getResponseEnvelope() != null) {

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Cache-hit for message ID : " + synCtx.getMessageID());
                }

                // mark as a response and replace envelope from cache
                synCtx.setResponse(true);
                try {
                    MessageFactory mf = MessageFactory.newInstance();
                    SOAPMessage smsg;
                    if (synCtx.isSOAP11()) {
                        smsg = mf.createMessage(new MimeHeaders(),
                                new ByteArrayInputStream(cachedObj.getResponseEnvelope()));
                    } else {
                        MimeHeaders mimeHeaders = new MimeHeaders();
                        mimeHeaders.addHeader("Content-ID", IDGenerator.generateID());
                        mimeHeaders.addHeader("content-type",
                                HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML);
                        smsg = mf.createMessage(mimeHeaders,
                                new ByteArrayInputStream((cachedObj).getResponseEnvelope()));
                    }

                    if (smsg != null) {
                        org.apache.axiom.soap.SOAPEnvelope omSOAPEnv =
                                SAAJUtil.toOMSOAPEnvelope(
                                        smsg.getSOAPPart().getDocumentElement());
                        synCtx.setEnvelope(omSOAPEnv);
                    } else {
                        handleException("Unable to serve from the cache : " +
                                "Couldn't build the SOAP response from the cached byte stream",
                                synCtx);
                    }

                    // todo: if there is a WSA messageID in the response, is that need to be unique on each and every resp
                } catch (AxisFault axisFault) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, synCtx);
                } catch (IOException ioe) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, ioe, synCtx);
                } catch (SOAPException soape) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, soape, synCtx);
                }

                // take specified action on cache hit
                if (onCacheHitSequence != null) {
                    // if there is an onCacheHit use that for the mediation
                    synLog.traceOrDebug("Delegating message to the onCachingHit "
                            + "Anonymous sequence");
                    onCacheHitSequence.mediate(synCtx);

                } else if (onCacheHitRef != null) {

                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Delegating message to the onCachingHit " +
                            "sequence : " + onCacheHitRef);
                    }
                    synCtx.getSequence(onCacheHitRef).mediate(synCtx);

                } else {

                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Request message " + synCtx.getMessageID() +
                            " was served from the cache : " + cacheKey);
                    }
                    // send the response back if there is not onCacheHit is specified
                    synCtx.setTo(null);
                    Axis2Sender.sendBack(synCtx);
                }
                // stop any following mediators from executing
                return false;

            } else {
                // cache exists, but has expired...
                cachedObj.expire();
                cachedObj.setTimeout(timeout);
                synLog.traceOrDebug("Existing cached response has expired. Reset cache element");

                cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//                Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
                Replicator.replicate(cfgCtx);
View Full Code Here

Examples of org.wso2.caching.CachedObject

     * @throws ClusteringFault if there is an error in replicating the cfgCtx
     */
    private void storeRequestToCache(ConfigurationContext cfgCtx,
        String requestHash, CacheManager cacheManager) throws ClusteringFault {

        CachedObject cachedObj = new CachedObject();
        cachedObj.setRequestHash(requestHash);
        // this does not set the expiretime but just sets the timeout and the espiretime will
        // be set when the response is availabel
        cachedObj.setTimeout(timeout);
        cacheManager.addResponseWithKey(cacheKey, requestHash, cachedObj, cfgCtx);

        cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//        Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
        Replicator.replicate(cfgCtx);
View Full Code Here

Examples of org.wso2.caching.CachedObject

            Object obj = cache.getResponseForKey(requestHash);

            if (obj != null && obj instanceof CachedObject) {

                CachedObject cachedObj = (CachedObject) obj;
                if (traceOrDebugOn) {
                    traceOrDebug(traceOn, "Storing the response for the message with ID : "
                        + synCtx.getMessageID() + " with request hash ID : " +
                        cachedObj.getRequestHash() + " in the cache : " + cacheObjKey);
                }

                cachedObj.setResponseEnvelope(
                    MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope()));

                // 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
                cachedObj.setResponseHash(digestGenerator.getDigest(
                    ((Axis2MessageContext) synCtx).getAxis2MessageContext()));

                cachedObj.setExpireTime(
                    System.currentTimeMillis() + cachedObj.getTimeout());

            } else {
                auditWarn("A response message without a valid mapping to the " +
                    "request hash found. Unable to store the response in cache", synCtx);
            }
View Full Code Here

Examples of org.wso2.caching.CachedObject

        if (cache.containsKey(requestHash) &&
            cache.getResponseForKey(requestHash) 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);

            if (!cachedObj.isExpired() && cachedObj.getResponseEnvelope() != null) {

                if (traceOrDebugOn) {
                    traceOrDebug(traceOn,
                        "Cache-hit for message ID : " + synCtx.getMessageID());
                }

                // mark as a response and replace envelope from cache
                synCtx.setResponse(true);
                try {
                    synCtx.setEnvelope(cachedObj.getResponseEnvelope());
                } catch (AxisFault axisFault) {
                    handleException(
                        "Error setting response envelope from cache : " + cacheObjKey, synCtx);
                }

                // take specified action on cache hit
                if (onCacheHitSequence != null) {
                    // if there is an onCacheHit use that for the mediation
                    if (traceOrDebugOn) {
                        traceOrDebug(traceOn, "Delegating message to the onCachingHit " +
                            "Anonymous sequence");
                    }
                    onCacheHitSequence.mediate(synCtx);

                } else if (onCacheHitRef != null) {

                    if (traceOrDebugOn) {
                        traceOrDebug(traceOn, "Delegating message to the onCachingHit " +
                            "sequence : " + onCacheHitRef);
                    }
                    synCtx.getSequence(onCacheHitRef).mediate(synCtx);

                } else {

                    if (traceOrDebugOn) {
                        traceOrDebug(traceOn, "Request message " + synCtx.getMessageID() +
                            " has served from the cache : " + cacheObjKey);
                    }
                    // send the response back if there is not onCacheHit is specified
                    synCtx.setTo(null);
                    Axis2Sender.sendBack(synCtx);
                }
                // stop any following mediators from executing
                return false;

            } else {
                // cache exists, but has expired...
                cachedObj.clearCache();
                if (traceOrDebugOn) {
                    traceOrDebug(traceOn, "Existing cached response has expired. Reset cache element");
                }
            }
View Full Code Here

Examples of org.wso2.caching.CachedObject

     * @param synCtx the request message
     * @param requestHash the request hash that has already been computed
     * @param cache the cache
     */
    private void storeRequestToCache(MessageContext synCtx, Object requestHash, Cache cache) {
        CachedObject cachedObj = new CachedObject();
        cachedObj.setRequestEnvelope(MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope()));
        cachedObj.setRequestHash(requestHash);
        cachedObj.setTimeout(timeout);
        cache.addResponseWithKey(requestHash, cachedObj);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.