Пример #1
0
  public synchronized Stock getStock(StockInfo info, boolean force) {

    if (info == null) {
      Log.v(TAG, "getStock - info is null");
      return null;
    }

    Log.v(TAG, "getStock - stock_id:" + info.stock_id + ", force:" + force);

    // 先内存
    Stock stock = cache.get(info.getKey());

    // 再sql
    if (stock == null) {
      stock = new Stock(info);
      cache.put(info.getKey(), stock);
    }

    // 最后网络
    if (stock.outOfDate()) {
      cache.remove(info.getKey());
      stock.updateSQL(force); // sync NET and persit to SQL

      stock = new Stock(info); // reload from SQL
      cache.put(info.getKey(), stock);
    }

    return stock;
  }
  public void put(K key, V value) {
    RefCountedMemory mem = serialize(value);
    if (mem == null) return; // out of memory.  never mind.

    RefCountedMemory old = map.put(key, mem);
    if (old != null) old.unreference();
  }
  @SuppressWarnings("rawtypes")
  @Override
  public GrailsClass getArtefactForFeature(Object featureId) {
    if (artefactInfo == null) {
      return null;
    }

    String uri;
    String pluginName = null;

    if (featureId instanceof Map) {
      Map featureIdMap = (Map) featureId;
      uri = (String) featureIdMap.get("uri");
      pluginName = (String) featureIdMap.get("pluginName");
    } else {
      uri = featureId.toString();
    }

    GrailsClass controllerClass = uriToControllerClassCache.get(uri);
    if (controllerClass == null) {
      final ApplicationContext mainContext = grailsApplication.getMainContext();
      GrailsPluginManager grailsPluginManager = null;
      if (mainContext.containsBean(GrailsPluginManager.BEAN_NAME)) {
        final Object pluginManagerBean = mainContext.getBean(GrailsPluginManager.BEAN_NAME);
        if (pluginManagerBean instanceof GrailsPluginManager) {
          grailsPluginManager = (GrailsPluginManager) pluginManagerBean;
        }
      }
      final GrailsClass[] controllerClasses = artefactInfo.getGrailsClasses();
      // iterate in reverse in order to pick up application classes first
      for (int i = (controllerClasses.length - 1); i >= 0; i--) {
        GrailsClass c = controllerClasses[i];
        if (((GrailsControllerClass) c).mapsToURI(uri)) {
          boolean foundController = false;
          if (pluginName != null && grailsPluginManager != null) {
            final GrailsPlugin pluginForClass = grailsPluginManager.getPluginForClass(c.getClazz());
            if (pluginForClass != null && pluginName.equals(pluginForClass.getName())) {
              foundController = true;
            }
          } else {
            foundController = true;
          }
          if (foundController) {
            controllerClass = c;
            break;
          }
        }
      }
      if (controllerClass == null) {
        controllerClass = NO_CONTROLLER;
      }

      // don't cache for dev environment
      if (Environment.getCurrent() != Environment.DEVELOPMENT) {
        uriToControllerClassCache.put(uri, controllerClass);
      }
    }

    if (controllerClass == NO_CONTROLLER) {
      controllerClass = null;
    }
    return controllerClass;
  }
 public void put(K key, V value) {
   map.put(key, value);
 }