Search in sources :

Example 1 with Environment

use of com.blade.Environment in project blade by biezhi.

the class ConfigChanged method trigger.

@Override
public void trigger(Event e) {
    Environment environment = (Environment) e.attribute("environment");
    System.out.println("EventListener::ConfigChanged");
    System.out.println(environment.toMap());
}
Also used : Environment(com.blade.Environment)

Example 2 with Environment

use of com.blade.Environment in project blade by biezhi.

the class EnvironmentWatcher method run.

@Override
public void run() {
    if (Const.CLASSPATH.endsWith(".jar")) {
        return;
    }
    final Path path = Paths.get(Const.CLASSPATH);
    try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
        path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE);
        // start an infinite loop
        while (true) {
            final WatchKey key = watchService.take();
            for (WatchEvent<?> watchEvent : key.pollEvents()) {
                final WatchEvent.Kind<?> kind = watchEvent.kind();
                if (kind == StandardWatchEventKinds.OVERFLOW) {
                    continue;
                }
                // get the filename for the event
                final WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent;
                final String filename = watchEventPath.context().toString();
                // print it out
                if (log.isDebugEnabled()) {
                    log.debug("⬢ {} -> {}", kind, filename);
                }
                if (kind == StandardWatchEventKinds.ENTRY_DELETE && filename.startsWith(".app") && filename.endsWith(".properties.swp")) {
                    // reload env
                    log.info("⬢ Reload environment");
                    Environment environment = Environment.of("classpath:" + filename.substring(1, filename.length() - 4));
                    WebContext.blade().environment(environment);
                    // notify
                    WebContext.blade().eventManager().fireEvent(EventType.ENVIRONMENT_CHANGED, new Event().attribute("environment", environment));
                }
            }
            // reset the keyf
            boolean valid = key.reset();
            // deleted, for
            if (!valid) {
                break;
            }
        }
    } catch (IOException | InterruptedException ex) {
        log.error("Environment watch error", ex);
    }
}
Also used : IOException(java.io.IOException) Environment(com.blade.Environment) Event(com.blade.event.Event)

Example 3 with Environment

use of com.blade.Environment in project tale by otale.

the class AdminApiController method saveOptions.

@SysLog("保存系统配置")
@PostRoute("options/save")
public RestResponse<?> saveOptions(Request request) {
    Map<String, List<String>> querys = request.parameters();
    querys.forEach((k, v) -> optionsService.saveOption(k, v.get(0)));
    Environment config = Environment.of(optionsService.getOptions());
    TaleConst.OPTIONS = config;
    return RestResponse.ok();
}
Also used : Environment(com.blade.Environment) SysLog(com.tale.annotation.SysLog)

Aggregations

Environment (com.blade.Environment)3 Event (com.blade.event.Event)1 SysLog (com.tale.annotation.SysLog)1 IOException (java.io.IOException)1