Beispiel #1
1
  /**
   * model
   *
   * @param me
   */
  @Override
  public void configPlugin(Plugins me) {

    componentSscan(basePackage);

    IDataSourceProvider iDataSourceProvider = setDataSource();
    try {
      me.add((IPlugin) iDataSourceProvider);
    } catch (Exception e) {
      throw new RuntimeException("is not IPlugin type");
    }
    ActiveRecordPlugin arp = new ActiveRecordPlugin(iDataSourceProvider);

    addActiveRecord(arp); // 加入附加的活动记录
    Scan driven = new Scan();
    for (String pake : basePackage) {
      Set<Class<?>> clazzs = driven.getClasses(pake);

      for (Class<?> clazz : clazzs) {
        LOG.info(clazz.getName());
        Class superClass = clazz.getSuperclass();
        Class<?> jfClz = com.jfinal.plugin.activerecord.Model.class;
        if (superClass == jfClz || superClass.getSuperclass() == jfClz) {
          M model = clazz.getAnnotation(M.class);
          if (null != model) {
            arp.addMapping(model.value(), model.id(), (Class<? extends Model<?>>) clazz);
          }
        }
      }
    }
    me.add(arp);
  }
Beispiel #2
0
  /**
   * controller
   *
   * @param me
   */
  @Override
  public void configRoute(Routes me) {

    //        String path = this.getClass().getClassLoader().getResource("").getPath();
    controlSscan(controlPackage); // 获取需要扫描的包

    // 扫描器
    Scan driven = new Scan();
    for (String pake : controlPackage) {
      Set<Class<?>> clazzs = driven.getClasses(pake);
      /*System.out.println("pake: " + pake);*/
      for (Class<?> clazz : clazzs) {
        //            	System.out.println(clazz.getSuperclass());
        LOG.info(clazz.getName());
        Class<?> superclass = clazz.getSuperclass();
        Class<?> jfClz = com.jfinal.core.Controller.class;
        if (superclass == jfClz || superclass.getSuperclass() == jfClz) {
          C con = clazz.getAnnotation(C.class);
          if (null != con) {
            me.add(con.value(), (Class<? extends Controller>) clazz);
          }
        }
      }
    }
  }
Beispiel #3
0
 @Override
 public boolean start() {
   createShardedJedisPool();
   RedisKit.init(shardedJedisPool);
   logger.info("初始化redis插件成功");
   return true;
 }
Beispiel #4
0
 private static void checkFileModify() {
   Set<String> filenames = lastmodifies.keySet();
   for (String filename : filenames) {
     File file = new File(filename);
     if (lastmodifies.get(filename) != file.lastModified()) {
       LOG.info(filename + " changed, reload.");
       init(includeResources, excludeResources, reload);
     }
   }
 }
Beispiel #5
0
 /**
  * 构建redis集群配置信息
  *
  * @param bundle
  * @return
  */
 private List<JedisShardInfo> createJedisShardInfoList(ResourceBundle bundle) {
   List<JedisShardInfo> list = new LinkedList<JedisShardInfo>();
   String defaultRedisPort = bundle.getString("redis.port");
   for (int i = 0; i < 10; i++) {
     if (!bundle.containsKey("redis" + (i == 0 ? "" : i) + ".ip")) {
       continue;
     }
     String redisIp = bundle.getString("redis" + (i == 0 ? "" : i) + ".ip");
     String redisPort = bundle.getString("redis" + (i == 0 ? "" : i) + ".port");
     if (StringUtils.isEmpty(redisPort)) {
       redisPort = defaultRedisPort;
     }
     if (StringUtils.isNotEmpty(redisIp) && StringUtils.isNotEmpty(redisPort)) {
       JedisShardInfo jedisShardInfo = new JedisShardInfo(redisIp, redisPort);
       logger.info("初始化redis,redis" + (i == 0 ? "" : i) + ".ip:" + redisIp + ",端口:" + redisPort);
       list.add(jedisShardInfo);
     }
   }
   return list;
 }
Beispiel #6
0
  /**
   * @param includeResources
   * @param excludeResources
   * @param reload
   */
  static void init(List<String> includeResources, List<String> excludeResources, boolean reload) {
    ConfigKit.includeResources = includeResources;
    ConfigKit.excludeResources = excludeResources;
    ConfigKit.reload = reload;
    for (final String resource : includeResources) {
      LOG.debug("include :" + resource);
      File[] propertiesFiles = null;
      propertiesFiles =
          new File(PathKit.getRootClassPath())
              .listFiles(
                  new FileFilter() {

                    @Override
                    public boolean accept(File pathname) {
                      return Pattern.compile(resource).matcher(pathname.getName()).matches();
                    }
                  });
      for (File file : propertiesFiles) {
        String fileName = file.getAbsolutePath();
        LOG.debug("fileName:" + fileName);
        if (fileName.endsWith("-test." + ConfigPlugin.getSuffix())) {
          continue;
        }
        boolean excluded = false;
        for (String exclude : excludeResources) {
          if (Pattern.compile(exclude).matcher(file.getName()).matches()) {
            excluded = true;
          }
        }
        if (excluded) {
          continue;
        }
        lastmodifies.put(fileName, new File(fileName).lastModified());
        map = ResourceKit.readProperties(fileName);
        testMap = ResourceKit.readProperties(testFileName(fileName));
      }
    }
    LOG.debug("map" + map);
    LOG.debug("testMap" + testMap);
    LOG.info("config init success!");
  }