Package org.apache.synapse.mediators.builtin

Examples of org.apache.synapse.mediators.builtin.CacheMediator


    protected OMElement serializeSpecificMediator(Mediator m) {

        if (!(m instanceof CacheMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }
        CacheMediator mediator = (CacheMediator) m;
        OMElement cache = fac.createOMElement("cache", synNS);
        saveTracingState(cache, mediator);

        if (mediator.getId() != null) {
            cache.addAttribute(fac.createOMAttribute("id", nullNS, mediator.getId()));
        }

        if (mediator.getScope() != null) {
            cache.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
        }

        if (mediator.isCollector()) {
            cache.addAttribute(fac.createOMAttribute("collector", nullNS, "true"));
        } else {

            cache.addAttribute(fac.createOMAttribute("collector", nullNS, "false"));

            if (mediator.getDigestGenerator() != null) {
                cache.addAttribute(fac.createOMAttribute("hashGenerator", nullNS,
                    mediator.getDigestGenerator().getClass().getName()));
            }

            if (mediator.getTimeout() != 0) {
                cache.addAttribute(
                    fac.createOMAttribute("timeout", nullNS, Long.toString(mediator.getTimeout())));
            }

            if (mediator.getMaxMessageSize() != 0) {
                cache.addAttribute(
                    fac.createOMAttribute("maxMessageSize", nullNS,
                        Integer.toString(mediator.getMaxMessageSize())));
            }

            if (mediator.getOnCacheHitRef() != null) {
                OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
                onCacheHit.addAttribute(
                    fac.createOMAttribute("sequence", nullNS, mediator.getOnCacheHitRef()));
                cache.addChild(onCacheHit);
            } else if (mediator.getOnCacheHitSequence() != null) {
                OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
                new SequenceMediatorSerializer()
                    .serializeChildren(onCacheHit, mediator.getOnCacheHitSequence().getList());
                cache.addChild(onCacheHit);
            }

            if (mediator.getInMemoryCacheSize() != 0) {
                OMElement implElem = fac.createOMElement("implementation", synNS);
                implElem.addAttribute(fac.createOMAttribute("type", nullNS, "memory"));
                implElem.addAttribute(fac.createOMAttribute("maxSize", nullNS,
                    Integer.toString(mediator.getInMemoryCacheSize())));
                cache.addChild(implElem);
            }

            if (mediator.getDiskCacheSize() != 0) {
                OMElement implElem = fac.createOMElement("implementation", synNS);
                implElem.addAttribute(fac.createOMAttribute("type", nullNS, "disk"));
                implElem.addAttribute(fac.createOMAttribute("maxSize", nullNS,
                    Integer.toString(mediator.getDiskCacheSize())));
                cache.addChild(implElem);
            }
        }

        return cache;
View Full Code Here


        if (!CACHE_Q.equals(elem.getQName())) {
            handleException("Unable to create the cache mediator. " +
                "Unexpected element as the cache mediator configuration");
        }

        CacheMediator cache = new CacheMediator();

        OMAttribute idAttr = elem.getAttribute(ATT_ID);
        if (idAttr != null && idAttr.getAttributeValue() != null) {
            cache.setId(idAttr.getAttributeValue());
        }

        OMAttribute scopeAttr = elem.getAttribute(ATT_SCOPE);
        if (scopeAttr != null && scopeAttr.getAttributeValue() != null &&
            isValidScope(scopeAttr.getAttributeValue(), cache.getId())) {
            cache.setScope(scopeAttr.getAttributeValue());
        } else {
            cache.setScope(CachingConstants.SCOPE_PER_HOST);
        }

        OMAttribute collectorAttr = elem.getAttribute(ATT_COLLECTOR);
        if (collectorAttr != null && collectorAttr.getAttributeValue() != null &&
            "true".equals(collectorAttr.getAttributeValue())) {

            cache.setCollector(true);
        } else {
           
            cache.setCollector(false);

            OMAttribute hashGeneratorAttr = elem.getAttribute(ATT_HASH_GENERATOR);
            if (hashGeneratorAttr != null && hashGeneratorAttr.getAttributeValue() != null) {
                try {
                    Class generator = Class.forName(hashGeneratorAttr.getAttributeValue());
                    Object o = generator.newInstance();
                    if (o instanceof DigestGenerator) {
                        cache.setDigestGenerator((DigestGenerator) o);
                    } else {
                        handleException("Specified class for the hashGenerator is not a " +
                            "DigestGenerator. It *must* implement " +
                            "org.wso2.caching.digest.DigestGenerator interface");
                    }
                } catch (ClassNotFoundException e) {
                    handleException("Unable to load the hash generator class", e);
                } catch (IllegalAccessException e) {
                    handleException("Unable to access the hash generator class", e);
                } catch (InstantiationException e) {
                    handleException("Unable to instantiate the hash generator class", e);
                }
            }

            OMAttribute timeoutAttr = elem.getAttribute(ATT_TIMEOUT);
            if (timeoutAttr != null && timeoutAttr.getAttributeValue() != null) {
                cache.setTimeout(Long.parseLong(timeoutAttr.getAttributeValue()));
            } else {
                cache.setTimeout(DEFAULT_TIMEOUT);
            }

            OMAttribute maxMessageSizeAttr = elem.getAttribute(ATT_MAX_MSG_SIZE);
            if (maxMessageSizeAttr != null && maxMessageSizeAttr.getAttributeValue() != null) {
                cache.setMaxMessageSize(Integer.parseInt(maxMessageSizeAttr.getAttributeValue()));
            }

            OMElement onCacheHitElem = elem.getFirstChildWithName(ON_CACHE_HIT_Q);
            if (onCacheHitElem != null) {
                OMAttribute sequenceAttr = onCacheHitElem.getAttribute(ATT_SEQUENCE);
                if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
                    cache.setOnCacheHitRef(sequenceAttr.getAttributeValue());
                } else if (onCacheHitElem.getFirstElement() != null) {
                    cache.setOnCacheHitSequence(new SequenceMediatorFactory()
                            .createAnonymousSequence(onCacheHitElem, properties));
                }
            }

            for (Iterator itr = elem.getChildrenWithName(IMPLEMENTATION_Q); itr.hasNext();) {
                OMElement implElem = (OMElement) itr.next();
                OMAttribute typeAttr = implElem.getAttribute(ATT_TYPE);
                OMAttribute sizeAttr = implElem.getAttribute(ATT_SIZE);
                if (typeAttr != null && typeAttr.getAttributeValue() != null) {
                    String type = typeAttr.getAttributeValue();
                    if (CachingConstants.TYPE_MEMORY.equals(type) && sizeAttr != null &&
                        sizeAttr.getAttributeValue() != null) {
                        cache.setInMemoryCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                    } else if (CachingConstants.TYPE_DISK.equals(type)) {
                        log.warn("Disk based and hirearchycal caching is not implemented yet");
                        if (sizeAttr != null && sizeAttr.getAttributeValue() != null) {
                            cache.setDiskCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                        } else {
                            cache.setDiskCacheSize(DEFAULT_DISK_CACHE_SIZE);
                        }
                    } else {
                        handleException("unknown implementation type for the Cache mediator");
                    }
                }
View Full Code Here

        if (!CACHE_Q.equals(elem.getQName())) {
            handleException("Unable to create the cache mediator. " +
                "Unexpected element as the cache mediator configuration");
        }
       
        CacheMediator cache = new CacheMediator();

        OMAttribute idAttr = elem.getAttribute(ATT_ID);
        if (idAttr != null && idAttr.getAttributeValue() != null){
            cache.setId(idAttr.getAttributeValue());
        }

        OMAttribute hashGeneratorAttr = elem.getAttribute(ATT_HASH_GENERATOR);
        if (hashGeneratorAttr != null && hashGeneratorAttr.getAttributeValue() != null) {
            try {
                Class generator = Class.forName(hashGeneratorAttr.getAttributeValue());
                Object o = generator.newInstance();
                if (o instanceof DigestGenerator) {
                    cache.setDigestGenerator((DigestGenerator) o);
                } else {
                    handleException("Specified class for the hashGenerator is not a " +
                        "DigestGenerator. It *must* implement " +
                        "org.wso2.caching.digest.DigestGenerator interface");
                }
            } catch (ClassNotFoundException e) {
                handleException("Unable to load the hash generator class", e);
            } catch (IllegalAccessException e) {
                handleException("Unable to access the hash generator class", e);
            } catch (InstantiationException e) {
                handleException("Unable to instantiate the hash generator class", e);
            }
        }

        OMAttribute timeoutAttr = elem.getAttribute(ATT_TIMEOUT);
        if (timeoutAttr != null && timeoutAttr.getAttributeValue() != null) {
            cache.setTimeout(Long.parseLong(timeoutAttr.getAttributeValue()));
        } else {
            cache.setTimeout(DEFAULT_TIMEOUT);
        }

        OMAttribute scopeAttr = elem.getAttribute(ATT_SCOPE);
        if (scopeAttr != null && scopeAttr.getAttributeValue() != null
            && isValidScope(scopeAttr.getAttributeValue())) {
            cache.setScope(scopeAttr.getAttributeValue());
        } else {
            cache.setScope(CachingConstants.SCOPE_PER_HOST);
        }

        OMElement onCacheHitElem = elem.getFirstChildWithName(ON_CACHE_HIT_Q);
        if (onCacheHitElem != null) {
            OMAttribute sequenceAttr = onCacheHitElem.getAttribute(ATT_SEQUENCE);
            if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
                cache.setOnCacheHitRef(sequenceAttr.getAttributeValue());
            } else {
                cache.setOnCacheHitSequence(
                    new SequenceMediatorFactory().createAnonymousSequence(onCacheHitElem));
            }
        }

        for (Iterator itr = elem.getChildrenWithName(IMPLEMENTATION_Q); itr.hasNext();) {
            OMElement implElem = (OMElement) itr.next();
            OMAttribute typeAttr = implElem.getAttribute(ATT_TYPE);
            OMAttribute sizeAttr = implElem.getAttribute(ATT_SIZE);
            if (typeAttr != null && typeAttr.getAttributeValue() != null) {
                String type = typeAttr.getAttributeValue();
                if (CachingConstants.TYPE_MEMORY.equals(type) && sizeAttr != null
                    && sizeAttr.getAttributeValue() != null) {
                    cache.setInMemoryCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                } else if (CachingConstants.TYPE_DISK.equals(type)) {
                    log.warn("Disk based and hirearchycal caching is not implemented yet");
                    if (sizeAttr != null && sizeAttr.getAttributeValue() != null) {
                        cache.setDiskCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                    } else {
                        cache.setDiskCacheSize(DEFAULT_DISK_CACHE_SIZE);
                    }
                } else {
                    handleException("unknown implementation type for the Cache mediator");
                }
            }
View Full Code Here

    public OMElement serializeMediator(OMElement parent, Mediator m) {

        if (!(m instanceof CacheMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }
        CacheMediator mediator = (CacheMediator) m;
        OMElement cache = fac.createOMElement("cache", synNS);
        saveTracingState(cache, mediator);

        if (mediator.getId() != null) {
            cache.addAttribute(fac.createOMAttribute("id", nullNS, mediator.getId()));
        }

        if (mediator.getDigestGenerator() != null) {
            cache.addAttribute(fac.createOMAttribute("hashGenerator", nullNS,
                mediator.getDigestGenerator().getClass().getName()));
        }

        if (mediator.getScope() != null) {
            cache.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
        }

        if (mediator.getTimeout() != 0) {
            cache.addAttribute(
                fac.createOMAttribute("timeout", nullNS, Long.toString(mediator.getTimeout())));
        }

        if (mediator.getOnCacheHitRef() != null) {
            OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
            onCacheHit.addAttribute(
                fac.createOMAttribute("sequence", nullNS, mediator.getOnCacheHitRef()));
            cache.addChild(onCacheHit);
        } else if (mediator.getOnCacheHitSequence() != null) {
            OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
            new SequenceMediatorSerializer().serializeChildren(
                onCacheHit, mediator.getOnCacheHitSequence().getList());
            cache.addChild(onCacheHit);
        }

        if (mediator.getInMemoryCacheSize() != 0) {
            OMElement implElem = fac.createOMElement("implementation", synNS);
            implElem.addAttribute(fac.createOMAttribute("type", nullNS, "memory"));
            implElem.addAttribute(fac.createOMAttribute(
                "maxSize", nullNS, Integer.toString(mediator.getInMemoryCacheSize())));
            cache.addChild(implElem);
        }
       
        if (mediator.getDiskCacheSize() != 0) {
            OMElement implElem = fac.createOMElement("implementation", synNS);
            implElem.addAttribute(fac.createOMAttribute("type", nullNS, "disk"));
            implElem.addAttribute(fac.createOMAttribute(
                "maxSize", nullNS, Integer.toString(mediator.getDiskCacheSize())));
            cache.addChild(implElem);
        }

        if (parent != null) {
            parent.addChild(cache);
View Full Code Here

    public OMElement serializeSpecificMediator(Mediator m) {

        if (!(m instanceof CacheMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }
        CacheMediator mediator = (CacheMediator) m;
        OMElement cache = fac.createOMElement("cache", synNS);
        saveTracingState(cache, mediator);

        if (mediator.getId() != null) {
            cache.addAttribute(fac.createOMAttribute("id", nullNS, mediator.getId()));
        }

        if (mediator.getScope() != null) {
            cache.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
        }

        if (mediator.isCollector()) {
            cache.addAttribute(fac.createOMAttribute("collector", nullNS, "true"));
        } else {

            cache.addAttribute(fac.createOMAttribute("collector", nullNS, "false"));

            if (mediator.getDigestGenerator() != null) {
                cache.addAttribute(fac.createOMAttribute("hashGenerator", nullNS,
                    mediator.getDigestGenerator().getClass().getName()));
            }

            if (mediator.getTimeout() != 0) {
                cache.addAttribute(
                    fac.createOMAttribute("timeout", nullNS, Long.toString(mediator.getTimeout())));
            }

            if (mediator.getMaxMessageSize() != 0) {
                cache.addAttribute(
                    fac.createOMAttribute("maxMessageSize", nullNS,
                        Integer.toString(mediator.getMaxMessageSize())));
            }

            if (mediator.getOnCacheHitRef() != null) {
                OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
                onCacheHit.addAttribute(
                    fac.createOMAttribute("sequence", nullNS, mediator.getOnCacheHitRef()));
                cache.addChild(onCacheHit);
            } else if (mediator.getOnCacheHitSequence() != null) {
                OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
                new SequenceMediatorSerializer()
                    .serializeChildren(onCacheHit, mediator.getOnCacheHitSequence().getList());
                cache.addChild(onCacheHit);
            }

            if (mediator.getInMemoryCacheSize() != 0) {
                OMElement implElem = fac.createOMElement("implementation", synNS);
                implElem.addAttribute(fac.createOMAttribute("type", nullNS, "memory"));
                implElem.addAttribute(fac.createOMAttribute("maxSize", nullNS,
                    Integer.toString(mediator.getInMemoryCacheSize())));
                cache.addChild(implElem);
            }

            if (mediator.getDiskCacheSize() != 0) {
                OMElement implElem = fac.createOMElement("implementation", synNS);
                implElem.addAttribute(fac.createOMAttribute("type", nullNS, "disk"));
                implElem.addAttribute(fac.createOMAttribute("maxSize", nullNS,
                    Integer.toString(mediator.getDiskCacheSize())));
                cache.addChild(implElem);
            }
        }

        return cache;
View Full Code Here

        if (!CACHE_Q.equals(elem.getQName())) {
            handleException("Unable to create the cache mediator. " +
                "Unexpected element as the cache mediator configuration");
        }

        CacheMediator cache = new CacheMediator();

        OMAttribute idAttr = elem.getAttribute(ATT_ID);
        if (idAttr != null && idAttr.getAttributeValue() != null) {
            cache.setId(idAttr.getAttributeValue());
        }

        OMAttribute scopeAttr = elem.getAttribute(ATT_SCOPE);
        if (scopeAttr != null && scopeAttr.getAttributeValue() != null &&
            isValidScope(scopeAttr.getAttributeValue(), cache.getId())) {
            cache.setScope(scopeAttr.getAttributeValue());
        } else {
            cache.setScope(CachingConstants.SCOPE_PER_HOST);
        }

        OMAttribute collectorAttr = elem.getAttribute(ATT_COLLECTOR);
        if (collectorAttr != null && collectorAttr.getAttributeValue() != null &&
            "true".equals(collectorAttr.getAttributeValue())) {

            cache.setCollector(true);
        } else {
           
            cache.setCollector(false);

            OMAttribute hashGeneratorAttr = elem.getAttribute(ATT_HASH_GENERATOR);
            if (hashGeneratorAttr != null && hashGeneratorAttr.getAttributeValue() != null) {
                try {
                    Class generator = Class.forName(hashGeneratorAttr.getAttributeValue());
                    Object o = generator.newInstance();
                    if (o instanceof DigestGenerator) {
                        cache.setDigestGenerator((DigestGenerator) o);
                    } else {
                        handleException("Specified class for the hashGenerator is not a " +
                            "DigestGenerator. It *must* implement " +
                            "org.wso2.caching.digest.DigestGenerator interface");
                    }
                } catch (ClassNotFoundException e) {
                    handleException("Unable to load the hash generator class", e);
                } catch (IllegalAccessException e) {
                    handleException("Unable to access the hash generator class", e);
                } catch (InstantiationException e) {
                    handleException("Unable to instantiate the hash generator class", e);
                }
            }

            OMAttribute timeoutAttr = elem.getAttribute(ATT_TIMEOUT);
            if (timeoutAttr != null && timeoutAttr.getAttributeValue() != null) {
                cache.setTimeout(Long.parseLong(timeoutAttr.getAttributeValue()));
            } else {
                cache.setTimeout(DEFAULT_TIMEOUT);
            }

            OMAttribute maxMessageSizeAttr = elem.getAttribute(ATT_MAX_MSG_SIZE);
            if (maxMessageSizeAttr != null && maxMessageSizeAttr.getAttributeValue() != null) {
                cache.setMaxMessageSize(Integer.parseInt(maxMessageSizeAttr.getAttributeValue()));
            }

            OMElement onCacheHitElem = elem.getFirstChildWithName(ON_CACHE_HIT_Q);
            if (onCacheHitElem != null) {
                OMAttribute sequenceAttr = onCacheHitElem.getAttribute(ATT_SEQUENCE);
                if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
                    cache.setOnCacheHitRef(sequenceAttr.getAttributeValue());
                } else if (onCacheHitElem.getFirstElement() != null) {
                    cache.setOnCacheHitSequence(new SequenceMediatorFactory()
                            .createAnonymousSequence(onCacheHitElem, properties));
                }
            }

            for (Iterator itr = elem.getChildrenWithName(IMPLEMENTATION_Q); itr.hasNext();) {
                OMElement implElem = (OMElement) itr.next();
                OMAttribute typeAttr = implElem.getAttribute(ATT_TYPE);
                OMAttribute sizeAttr = implElem.getAttribute(ATT_SIZE);
                if (typeAttr != null && typeAttr.getAttributeValue() != null) {
                    String type = typeAttr.getAttributeValue();
                    if (CachingConstants.TYPE_MEMORY.equals(type) && sizeAttr != null &&
                        sizeAttr.getAttributeValue() != null) {
                        cache.setInMemoryCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                    } else if (CachingConstants.TYPE_DISK.equals(type)) {
                        log.warn("Disk based and hirearchycal caching is not implemented yet");
                        if (sizeAttr != null && sizeAttr.getAttributeValue() != null) {
                            cache.setDiskCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                        } else {
                            cache.setDiskCacheSize(DEFAULT_DISK_CACHE_SIZE);
                        }
                    } else {
                        handleException("unknown implementation type for the Cache mediator");
                    }
                }
View Full Code Here

        if (!(m instanceof CacheMediator)) {
            return null;
        }

        List<ConfigurationObject> providers = new ArrayList<ConfigurationObject>();
        CacheMediator cacheMediator = (CacheMediator) m;
        if (cacheMediator.getOnCacheHitSequence() != null) {
            DependencyResolver resolver = DependencyResolverFactory.getInstance().
                    getResolver(cacheMediator.getOnCacheHitSequence());
            List<ConfigurationObject> sequenceProviders = resolver.resolve(
                    cacheMediator.getOnCacheHitSequence());
            for (ConfigurationObject o : sequenceProviders) {
                addProvider(o, providers);
            }
        } else if (cacheMediator.getOnCacheHitRef() != null) {
            addProvider(new ConfigurationObject(ConfigurationObject.TYPE_SEQUENCE,
                    cacheMediator.getOnCacheHitRef()), providers);
        }
        return providers;
    }
View Full Code Here

        if (!CACHE_Q.equals(elem.getQName())) {
            handleException("Unable to create the cache mediator. " +
                "Unexpected element as the cache mediator configuration");
        }

        CacheMediator cache = new CacheMediator();

        OMAttribute idAttr = elem.getAttribute(ATT_ID);
        if (idAttr != null && idAttr.getAttributeValue() != null) {
            cache.setId(idAttr.getAttributeValue());
        }

        OMAttribute scopeAttr = elem.getAttribute(ATT_SCOPE);
        if (scopeAttr != null && scopeAttr.getAttributeValue() != null &&
            isValidScope(scopeAttr.getAttributeValue(), cache.getId())) {
            cache.setScope(scopeAttr.getAttributeValue());
        } else {
            cache.setScope(CachingConstants.SCOPE_PER_HOST);
        }

        OMAttribute collectorAttr = elem.getAttribute(ATT_COLLECTOR);
        if (collectorAttr != null && collectorAttr.getAttributeValue() != null &&
            "true".equals(collectorAttr.getAttributeValue())) {

            cache.setCollector(true);
        } else {
           
            cache.setCollector(false);

            OMAttribute hashGeneratorAttr = elem.getAttribute(ATT_HASH_GENERATOR);
            if (hashGeneratorAttr != null && hashGeneratorAttr.getAttributeValue() != null) {
                try {
                    Class generator = Class.forName(hashGeneratorAttr.getAttributeValue());
                    Object o = generator.newInstance();
                    if (o instanceof DigestGenerator) {
                        cache.setDigestGenerator((DigestGenerator) o);
                    } else {
                        handleException("Specified class for the hashGenerator is not a " +
                            "DigestGenerator. It *must* implement " +
                            "org.wso2.caching.digest.DigestGenerator interface");
                    }
                } catch (ClassNotFoundException e) {
                    handleException("Unable to load the hash generator class", e);
                } catch (IllegalAccessException e) {
                    handleException("Unable to access the hash generator class", e);
                } catch (InstantiationException e) {
                    handleException("Unable to instantiate the hash generator class", e);
                }
            }

            OMAttribute timeoutAttr = elem.getAttribute(ATT_TIMEOUT);
            if (timeoutAttr != null && timeoutAttr.getAttributeValue() != null) {
                cache.setTimeout(Long.parseLong(timeoutAttr.getAttributeValue()));
            } else {
                cache.setTimeout(DEFAULT_TIMEOUT);
            }

            OMAttribute maxMessageSizeAttr = elem.getAttribute(ATT_MAX_MSG_SIZE);
            if (maxMessageSizeAttr != null && maxMessageSizeAttr.getAttributeValue() != null) {
                cache.setMaxMessageSize(Integer.parseInt(maxMessageSizeAttr.getAttributeValue()));
            }

            OMElement onCacheHitElem = elem.getFirstChildWithName(ON_CACHE_HIT_Q);
            if (onCacheHitElem != null) {
                OMAttribute sequenceAttr = onCacheHitElem.getAttribute(ATT_SEQUENCE);
                if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
                    cache.setOnCacheHitRef(sequenceAttr.getAttributeValue());
                } else if (onCacheHitElem.getFirstElement() != null) {
                    cache.setOnCacheHitSequence(
                        new SequenceMediatorFactory().createAnonymousSequence(onCacheHitElem));
                }
            }

            for (Iterator itr = elem.getChildrenWithName(IMPLEMENTATION_Q); itr.hasNext();) {
                OMElement implElem = (OMElement) itr.next();
                OMAttribute typeAttr = implElem.getAttribute(ATT_TYPE);
                OMAttribute sizeAttr = implElem.getAttribute(ATT_SIZE);
                if (typeAttr != null && typeAttr.getAttributeValue() != null) {
                    String type = typeAttr.getAttributeValue();
                    if (CachingConstants.TYPE_MEMORY.equals(type) && sizeAttr != null &&
                        sizeAttr.getAttributeValue() != null) {
                        cache.setInMemoryCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                    } else if (CachingConstants.TYPE_DISK.equals(type)) {
                        log.warn("Disk based and hirearchycal caching is not implemented yet");
                        if (sizeAttr != null && sizeAttr.getAttributeValue() != null) {
                            cache.setDiskCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                        } else {
                            cache.setDiskCacheSize(DEFAULT_DISK_CACHE_SIZE);
                        }
                    } else {
                        handleException("unknown implementation type for the Cache mediator");
                    }
                }
View Full Code Here

    public OMElement serializeMediator(OMElement parent, Mediator m) {

        if (!(m instanceof CacheMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }
        CacheMediator mediator = (CacheMediator) m;
        OMElement cache = fac.createOMElement("cache", synNS);
        saveTracingState(cache, mediator);

        if (mediator.getId() != null) {
            cache.addAttribute(fac.createOMAttribute("id", nullNS, mediator.getId()));
        }

        if (mediator.getScope() != null) {
            cache.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
        }

        if (mediator.isCollector()) {
            cache.addAttribute(fac.createOMAttribute("collector", nullNS, "true"));
        } else {

            cache.addAttribute(fac.createOMAttribute("collector", nullNS, "false"));

            if (mediator.getDigestGenerator() != null) {
                cache.addAttribute(fac.createOMAttribute("hashGenerator", nullNS,
                    mediator.getDigestGenerator().getClass().getName()));
            }

            if (mediator.getTimeout() != 0) {
                cache.addAttribute(
                    fac.createOMAttribute("timeout", nullNS, Long.toString(mediator.getTimeout())));
            }

            if (mediator.getMaxMessageSize() != 0) {
                cache.addAttribute(
                    fac.createOMAttribute("maxMessageSize", nullNS,
                        Integer.toString(mediator.getMaxMessageSize())));
            }

            if (mediator.getOnCacheHitRef() != null) {
                OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
                onCacheHit.addAttribute(
                    fac.createOMAttribute("sequence", nullNS, mediator.getOnCacheHitRef()));
                cache.addChild(onCacheHit);
            } else if (mediator.getOnCacheHitSequence() != null) {
                OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
                new SequenceMediatorSerializer()
                    .serializeChildren(onCacheHit, mediator.getOnCacheHitSequence().getList());
                cache.addChild(onCacheHit);
            }

            if (mediator.getInMemoryCacheSize() != 0) {
                OMElement implElem = fac.createOMElement("implementation", synNS);
                implElem.addAttribute(fac.createOMAttribute("type", nullNS, "memory"));
                implElem.addAttribute(fac.createOMAttribute("maxSize", nullNS,
                    Integer.toString(mediator.getInMemoryCacheSize())));
                cache.addChild(implElem);
            }

            if (mediator.getDiskCacheSize() != 0) {
                OMElement implElem = fac.createOMElement("implementation", synNS);
                implElem.addAttribute(fac.createOMAttribute("type", nullNS, "disk"));
                implElem.addAttribute(fac.createOMAttribute("maxSize", nullNS,
                    Integer.toString(mediator.getDiskCacheSize())));
                cache.addChild(implElem);
            }
        }

        if (parent != null) {
View Full Code Here

    public OMElement serializeMediator(OMElement parent, Mediator m) {

        if (!(m instanceof CacheMediator)) {
            handleException("Unsupported mediator passed in for serialization : " + m.getType());
        }
        CacheMediator mediator = (CacheMediator) m;
        OMElement cache = fac.createOMElement("cache", synNS);
        saveTracingState(cache, mediator);

        if (mediator.getId() != null) {
            cache.addAttribute(fac.createOMAttribute("id", nullNS, mediator.getId()));
        }

        if (mediator.getScope() != null) {
            cache.addAttribute(fac.createOMAttribute("scope", nullNS, mediator.getScope()));
        }

        if (mediator.isCollector()) {
            cache.addAttribute(fac.createOMAttribute("collector", nullNS, "true"));
        } else {

            cache.addAttribute(fac.createOMAttribute("collector", nullNS, "false"));

            if (mediator.getDigestGenerator() != null) {
                cache.addAttribute(fac.createOMAttribute("hashGenerator", nullNS,
                    mediator.getDigestGenerator().getClass().getName()));
            }

            if (mediator.getTimeout() != 0) {
                cache.addAttribute(
                    fac.createOMAttribute("timeout", nullNS, Long.toString(mediator.getTimeout())));
            }

            if (mediator.getMaxMessageSize() != 0) {
                cache.addAttribute(
                    fac.createOMAttribute("maxMessageSize", nullNS,
                        Integer.toString(mediator.getMaxMessageSize())));
            }

            if (mediator.getOnCacheHitRef() != null) {
                OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
                onCacheHit.addAttribute(
                    fac.createOMAttribute("sequence", nullNS, mediator.getOnCacheHitRef()));
                cache.addChild(onCacheHit);
            } else if (mediator.getOnCacheHitSequence() != null) {
                OMElement onCacheHit = fac.createOMElement("onCacheHit", synNS);
                new SequenceMediatorSerializer()
                    .serializeChildren(onCacheHit, mediator.getOnCacheHitSequence().getList());
                cache.addChild(onCacheHit);
            }

            if (mediator.getInMemoryCacheSize() != 0) {
                OMElement implElem = fac.createOMElement("implementation", synNS);
                implElem.addAttribute(fac.createOMAttribute("type", nullNS, "memory"));
                implElem.addAttribute(fac.createOMAttribute("maxSize", nullNS,
                    Integer.toString(mediator.getInMemoryCacheSize())));
                cache.addChild(implElem);
            }

            if (mediator.getDiskCacheSize() != 0) {
                OMElement implElem = fac.createOMElement("implementation", synNS);
                implElem.addAttribute(fac.createOMAttribute("type", nullNS, "disk"));
                implElem.addAttribute(fac.createOMAttribute("maxSize", nullNS,
                    Integer.toString(mediator.getDiskCacheSize())));
                cache.addChild(implElem);
            }
        }

        if (parent != null) {
View Full Code Here

TOP

Related Classes of org.apache.synapse.mediators.builtin.CacheMediator

Copyright © 2018 www.massapicom. 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.