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

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


    public QueryResultList<Entity> findEntities(FieldQuery query) throws SiteException {
        List<Entity> results;
        if (siteConfiguration.getCacheStrategy() == CacheStrategy.all) {
            // TODO: check if query can be executed based on the base
            // configuration of the Cache
            Cache cache = getCache();
            if (cache != null) {
                try {
                    // When using the Cache, directly get the representations!
                    QueryResultList<Representation> representations = cache.findRepresentation((query));
                    results = new ArrayList<Entity>(representations.size());
                    for (Representation result : representations) {
                        Entity entity = new EntityImpl(getId(), result, null);
                        results.add(entity);
                        initEntityMetadata(entity, siteMetadata,
View Full Code Here


    @Override
    public QueryResultList<Representation> find(FieldQuery query) throws SiteException {
        if (siteConfiguration.getCacheStrategy() == CacheStrategy.all) {
            // TODO: check if query can be executed based on the base
            // configuration of the Cache
            Cache cache = getCache();
            if (cache != null) {
                try {
                    return cache.find(query);
                } catch (YardException e) {
                    if (siteConfiguration.getEntitySearcherType() == null || isOfflineMode()) {
                        throw new SiteException("Unable to execute query on Cache "
                                + siteConfiguration.getCacheId(), e);
                    } else {
View Full Code Here

    @Override
    public QueryResultList<String> findReferences(FieldQuery query) throws SiteException {
        if (siteConfiguration.getCacheStrategy() == CacheStrategy.all) {
            // TODO: check if query can be executed based on the base
            // configuration of the Cache
            Cache cache = getCache();
            if (cache != null) {
                try {
                    return cache.findReferences(query);
                } catch (YardException e) {
                    if (siteConfiguration.getEntitySearcherType() == null || isOfflineMode()) {
                        throw new SiteException("Unable to execute query on Cache "
                                + siteConfiguration.getCacheId(), e);
                    } else {
View Full Code Here

        }
    }

    @Override
    public Entity getEntity(String id) throws SiteException {
        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, siteMetadata,
                        singletonMap(RdfResourceEnum.isChached.getUri(), (Object) Boolean.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 SiteException(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 SiteException(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 SiteException(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 SiteException(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(
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

                   
                    @Override
                    public void modifiedService(ServiceReference reference, Object service) {
                        //the service.ranking might have changed ... so check if the
                        //top ranked Cache is a different one
                        Cache newCache = (Cache)cacheTracker.getService();
                        if(newCache == null || !newCache.equals(cache)){
                            cache = newCache; //set the new cahce
                            //and update the service registration
                            updateServiceRegistration(bc, siteConfiguration,
                                dereferencerComponentInstance, entitySearcherComponentInstance,
                                cache, nsPrefixService, offlineMode);
View Full Code Here

    @Override
    public QueryResultList<Entity> findEntities(FieldQuery query) throws ReferencedSiteException {
        List<Entity> results;
        if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
            //TODO: check if query can be executed based on the base configuration of the Cache
            Cache cache = getCache();
            if(cache != null){
                try {
                    //When using the Cache, directly get the representations!
                    QueryResultList<Representation> representations = cache.findRepresentation((query));
                    results = new ArrayList<Entity>(representations.size());
                    for(Representation result : representations){
                        Entity entity = new EntityImpl(getId(),result,null);
                        results.add(entity);
                        initEntityMetadata(entity,true);
View Full Code Here

    }
    @Override
    public QueryResultList<Representation> find(FieldQuery query) throws ReferencedSiteException{
        if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
            //TODO: check if query can be executed based on the base configuration of the Cache
            Cache cache = getCache();
            if(cache != null){
                try {
                    return cache.find(query);
                } catch (YardException e) {
                    if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                        throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
                    } else {
                        log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
View Full Code Here

    }
    @Override
    public QueryResultList<String> findReferences(FieldQuery query) throws ReferencedSiteException {
        if(siteConfiguration.getCacheStrategy() == CacheStrategy.all){
            //TODO: check if query can be executed based on the base configuration of the Cache
            Cache cache = getCache();
            if(cache != null){
                try {
                    return cache.findReferences(query);
                } catch (YardException e) {
                    if(siteConfiguration.getEntitySearcherType()==null || isOfflineMode()){
                        throw new ReferencedSiteException("Unable to execute query on Cache "+siteConfiguration.getCacheId(),e);
                    } else {
                        log.warn(String.format("Error while performing query on Cache %s! Try to use remote site %s as fallback!",
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.