Package org.apache.stanbol.entityhub.servicesapi.yard

Examples of org.apache.stanbol.entityhub.servicesapi.yard.Cache


                    id,contentType,siteConfiguration.getAccessUri(),siteConfiguration.getEntityDereferencerType()),e);
        }
    }
    @Override
    public Entity getEntity(String id) throws ReferencedSiteException {
        Cache cache = getCache();
        Entity entity = null;
        long start = System.currentTimeMillis();
        if (cache != null) {
            try {
                Representation rep = cache.getRepresentation(id);
                if(rep != null){
                   entity = new EntityImpl(getId(), rep, null);
                   initEntityMetadata(entity, true);
                } else if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
                    return null; //do no remote lokkups on CacheStrategy.all!!
                }
            } catch (YardException e) {
                if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
                    throw new ReferencedSiteException(String.format("Unable to get Represetnation %s form Cache %s",
                        id, siteConfiguration.getCacheId()), e);
                } else {
                    log.warn(String.format("Unable to get Represetnation %s form Cache %s. Will dereference from remote site %s",
                            id, siteConfiguration.getCacheId(), siteConfiguration.getAccessUri()), e);
                }
            }
        } else {
            if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
                throw new ReferencedSiteException(String.format("Unable to get Represetnation %s because configured Cache %s is currently not available",
                        id, siteConfiguration.getCacheId()));
            } else {
                log.warn(String.format("Cache %s is currently not available. Will use remote site %s to load Representation %s",
                        siteConfiguration.getCacheId(), siteConfiguration.getEntityDereferencerType(), id));
            }
        }
        if (entity == null) { // no cache or not found in cache
            if(dereferencer == null){
                throw new ReferencedSiteException(String.format("Entity Dereferencer %s for accessing remote site %s is not available",
                    siteConfiguration.getEntityDereferencerType(),siteConfiguration.getAccessUri()));
            }
            ensureOnline(siteConfiguration.getAccessUri(), dereferencer.getClass());
            Representation rep = null;
            try {
                rep = dereferencer.dereference(id);
            } catch (IOException e) {
                throw new ReferencedSiteException(
                    String.format("Unable to load Representation for entity %s form remote site %s with dereferencer %s",
                        id, siteConfiguration.getAccessUri(), siteConfiguration.getEntityDereferencerType()), e);
            }
            //representation loaded from remote site and cache is available
            if (rep != null){
                Boolean cachedVersion = Boolean.FALSE;
                if(cache != null) {// -> cache the representation
                    try {
                        start = System.currentTimeMillis();
                        //return the the cached version
                        rep = cache.store(rep);
                        cachedVersion = Boolean.TRUE;
                        log.debug("  - cached Representation {} in {} ms",    id, (System.currentTimeMillis() - start));
                    } catch (YardException e) {
                        log.warn(String.format("Unable to cache Represetnation %s in Cache %s! Representation not cached!",
                            id, siteConfiguration.getCacheId()), e);
View Full Code Here


     */
    @Override
    public FieldQueryFactory getQueryFactory() {
        FieldQueryFactory factory = null;
        if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
            Cache cache = getCache();
            if(cache != null){
                factory = cache.getQueryFactory();
            }
        }
        if(factory == null){
            factory = DefaultQueryFactory.getInstance();
        }
View Full Code Here

     */
    protected Cache getCache(){
        if(siteConfiguration.getCacheStrategy() == CacheStrategy.none){
            return null;
        } else {
            Cache cache = (Cache)cacheTracker.getService();
            if(cache != null && cache.isAvailable()){
                return cache;
            } else {
                return null;
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.yard.Cache

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.