diff --git a/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/ConfigEnv.java b/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/ConfigEnv.java index c3e32c91..c4db4f7e 100644 --- a/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/ConfigEnv.java +++ b/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/ConfigEnv.java @@ -18,6 +18,7 @@ package org.dromara.hmily.config.api; import org.apache.commons.lang3.StringUtils; +import org.dromara.hmily.config.api.event.DefaultConsumer; import org.dromara.hmily.config.api.event.EventConsumer; import org.dromara.hmily.config.api.event.EventData; import org.dromara.hmily.config.api.exception.ConfigException; @@ -46,6 +47,10 @@ public final class ConfigEnv { */ private static final Set> EVENTS = new HashSet<>(); + static { + EVENTS.add(new DefaultConsumer()); + } + /** * Save some custom configuration information. */ diff --git a/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/event/DefaultConsumer.java b/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/event/DefaultConsumer.java new file mode 100644 index 00000000..81f13e6d --- /dev/null +++ b/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/event/DefaultConsumer.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.hmily.config.api.event; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Custom monitor all changes. + * + * @author sixh chenbin + */ +public class DefaultConsumer implements EventConsumer { + + private final Logger logger = LoggerFactory.getLogger(DefaultConsumer.class); + + @Override + public void accept(final EventData data) { + logger.info("{}:config has changed....", data); + } + + @Override + public String regex() { + return "[\\s\\S\\d\\D]*"; + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(final Object obj) { + return super.equals(obj); + } +} diff --git a/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/event/EventConsumer.java b/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/event/EventConsumer.java index 833892e5..39f3a0ca 100644 --- a/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/event/EventConsumer.java +++ b/hmily-config/hmily-config-api/src/main/java/org/dromara/hmily/config/api/event/EventConsumer.java @@ -38,5 +38,5 @@ public interface EventConsumer { * * @return the string */ - String properties(); + String regex(); } diff --git a/hmily-config/hmily-config-loader/src/main/java/org/dromara/hmily/config/loader/ConfigLoader.java b/hmily-config/hmily-config-loader/src/main/java/org/dromara/hmily/config/loader/ConfigLoader.java index 8b9273bb..91dbb18c 100644 --- a/hmily-config/hmily-config-loader/src/main/java/org/dromara/hmily/config/loader/ConfigLoader.java +++ b/hmily-config/hmily-config-loader/src/main/java/org/dromara/hmily/config/loader/ConfigLoader.java @@ -83,8 +83,8 @@ public interface ConfigLoader { } String properties = data.getProperties(); List> eventsLists = events.stream() - .filter(e -> !Objects.isNull(e.properties())) - .filter(e -> Pattern.matches(e.properties(), properties)) + .filter(e -> !Objects.isNull(e.regex())) + .filter(e -> Pattern.matches(e.regex(), properties)) .collect(Collectors.toList()); for (EventConsumer consumer : eventsLists) { Optional first = ConfigEnv.getInstance().stream().filter(e -> properties.startsWith(e.prefix())).findFirst(); @@ -95,7 +95,7 @@ public interface ConfigLoader { sources.add(new MapPropertyKeySource(first.get().prefix(), values)); PassiveHandler handler = (ct, cf) -> { data.setConfig(cf); - data.setSubscribe(consumer.properties()); + data.setSubscribe(consumer.regex()); try { consumer.accept(data); } catch (ClassCastException e) {