Package org.fao.geonet

Examples of org.fao.geonet.JeevesJCS


    }

    private OpenBitSet applySpatialFilter(Set<FeatureId> matches, Multimap<FeatureId, Integer> docIndexLookup, OpenBitSet bits) throws IOException
    {

        JeevesJCS jcs = getJCSCache();
        processCachedFeatures(jcs, matches, docIndexLookup, bits);

        while (!matches.isEmpty()) {
          Id fidFilter;
          if(matches.size() > MAX_FIDS_PER_QUERY) {
            FeatureId[] subset = new FeatureId[MAX_FIDS_PER_QUERY];
            int i = 0;
            Iterator<FeatureId> iter = matches.iterator();
            while(iter.hasNext() && i < MAX_FIDS_PER_QUERY) {
              subset[i] = iter.next();
              iter.remove();
              i++;
            }
            fidFilter = _filterFactory.id(subset);
          } else {
            fidFilter = _filterFactory.id(matches);
            matches = Collections.emptySet();
          }
          
          FeatureSource<SimpleFeatureType, SimpleFeature> _featureSource = sourceAccessor.one();
          String ftn = _featureSource.getSchema().getName().getLocalPart();
          String[] geomAtt = {_featureSource.getSchema().getGeometryDescriptor().getLocalName()};
          FeatureCollection<SimpleFeatureType, SimpleFeature> features = _featureSource
                  .getFeatures(new org.geotools.data.Query(ftn, fidFilter,geomAtt));
          FeatureIterator<SimpleFeature> iterator = features.features();
 
         
          try {
              while (iterator.hasNext()) {
                  SimpleFeature feature = iterator.next();
                  FeatureId featureId = feature.getIdentifier();
                  jcs.put(featureId.getID(), feature.getDefaultGeometry());
                  if( evaluateFeature(feature) ){
                    for(int doc:docIndexLookup.get(featureId)) {
                        bits.set(doc);
                    }
                  }
View Full Code Here


        }
        return bits;
    }

  static JeevesJCS getJCSCache() throws Error {
      JeevesJCS jcs;
        try {
            jcs = JeevesJCS.getInstance(SPATIAL_FILTER_JCS);
        } catch (CacheException e) {
            throw new Error(e);
        }
View Full Code Here

  //--------------------------------------------------------------------------
  /**
    * Add an XLink to the cache.
    */
  public void addXmlToCache(String uri, Element xml) throws CacheException {
    JeevesJCS xmlCache = JeevesJCS.getInstance(XMLRESOLVER_JCS);
    Element cachedXml = (Element) xmlCache.get(uri.toLowerCase());
    if (cachedXml == null) {
      Log.info(Log.XML_RESOLVER, "Caching "+uri.toLowerCase());
      xmlCache.put(uri.toLowerCase(), xml);
    }
  }
View Full Code Here

  }

  //--------------------------------------------------------------------------
  /** Resolves an xlink */
  public Element isXmlInCache(String uri) throws CacheException {
    JeevesJCS xmlCache = JeevesJCS.getInstance(XMLRESOLVER_JCS);
    Element xml = (Element) xmlCache.get(uri.toLowerCase());

    if (xml == null) {
      Log.info(Log.XML_RESOLVER, "cache MISS on "+uri.toLowerCase());
    } else {
      Log.info(Log.XML_RESOLVER, "cache HIT on "+uri.toLowerCase());
View Full Code Here

    /**
     * Remove an XLink from the cache.
     */
    public static void removeFromCache(String xlinkUri) throws CacheException {

        JeevesJCS xlinkCache = JeevesJCS.getInstance(XLINK_JCS);
        if (xlinkCache.get(xlinkUri)!=null) {
            xlinkCache.remove(xlinkUri);
        }
    }
View Full Code Here

    //--------------------------------------------------------------------------
    /**
     * Add an XLink to the cache.
     */
    public static void addXLinkToCache(String uri, Element fragment) throws CacheException {
        JeevesJCS xlinkCache = JeevesJCS.getInstance(XLINK_JCS);
        Element cachedFragment = (Element) xlinkCache.get(uri.toLowerCase());
        if (cachedFragment == null) {
            xlinkCache.put(uri.toLowerCase(), fragment);
        }
    }
View Full Code Here

        }

        uri = uri.replaceAll("&+","&");
        String mappedURI = mapURI(uri);

        JeevesJCS xlinkCache = JeevesJCS.getInstance(XLINK_JCS);
        Element remoteFragment = (Element) xlinkCache.getFromGroup(uri.toLowerCase(), mappedURI);

        if (remoteFragment == null) {
            Log.info(Log.XLINK_PROCESSOR, "cache MISS on "+uri.toLowerCase());

            try {
                if(uri.startsWith(XLink.LOCAL_PROTOCOL)) {
                    LocalServiceRequest request = LocalServiceRequest.create(uri.replaceAll("&amp;", "&"));
                    request.setDebug(false);
                    if(request.getLanguage() == null) {
                        request.setLanguage(srvContext.getLanguage());
                    }
                    request.setInputMethod(InputMethod.GET);
                    remoteFragment = srvContext.execute(request);
                } else {
                    URL url = new URL(uri.replaceAll("&amp;", "&"));

                    URLConnection conn = url.openConnection();
                    conn.setConnectTimeout(1000);

                    BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
                    try {
                        remoteFragment = Xml.loadStream(in);
                        if(Log.isDebugEnabled(Log.XLINK_PROCESSOR))
                            Log.debug(Log.XLINK_PROCESSOR,"Read:\n"+Xml.getString(remoteFragment));
                    } finally {
                        in.close();
                    }
                }
            } catch (Exception e) {  // MalformedURLException, IOException
                synchronized(Processor.class) {
                    failures.add (System.currentTimeMillis());
                }

                Log.error(Log.XLINK_PROCESSOR,"Failed on " + uri
                                              + " with exception message " + e.getMessage());
            }

            if (remoteFragment != null && !remoteFragment.getName().equalsIgnoreCase("error")) {
                xlinkCache.putInGroup(uri.toLowerCase(), mappedURI, remoteFragment);
                if(Log.isDebugEnabled(Log.XLINK_PROCESSOR))
                    Log.debug(Log.XLINK_PROCESSOR,"cache miss for "+uri);
            } else {
                return null;
            }
View Full Code Here

    }

    //--------------------------------------------------------------------------
    /** Uncaches an xlink */
    public static void uncacheXLinkUri(String uri) throws CacheException {
        JeevesJCS xlinkCache = JeevesJCS.getInstance(XLINK_JCS);
        String mappedURI = mapURI(uri);
        Set groupKeys = xlinkCache.getGroupKeys(mappedURI);
        if(groupKeys==null || groupKeys.isEmpty()) {
            xlinkCache.remove(uri);
        } else {
            for( Object key : groupKeys ) {
                xlinkCache.remove(key, mappedURI);
            }
        }
    }
View Full Code Here

        Lock lock = getLock(key);
        try {
            if(!lock.tryLock(30, TimeUnit.SECONDS)) {
                throw new IllegalStateException("Timed out trying to get the log for the JeevesCache");
            }
            JeevesJCS cache = JeevesJCS.getInstance(cacheName);
           
            @SuppressWarnings("unchecked")
            V value = (V) cache.get(key);
           
            if (value == null) {
                value = loader.call();
                if (value != null) {
                  cache.put(key, value);
              }
            }
            return value;
        } finally {
            lock.unlock();
View Full Code Here

TOP

Related Classes of org.fao.geonet.JeevesJCS

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.