mirror of
https://gitee.com/dromara/hmily.git
synced 2024-12-03 11:47:39 +08:00
157 (#192)
* 1. Optimize other code format. 157 * 1. config push...157 * 1. config push...157 * 1 apollo config push.157 * 1. nacos config. * 1. zk config.157 * 1. zk config.157 * 1. Format code。 * 1. Format code。 * 1. Format code。 * 1. Update global update.157 * 1. Update global update.157
This commit is contained in:
parent
f3b18930fd
commit
c7f1f662ad
@ -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<EventConsumer<EventData>> EVENTS = new HashSet<>();
|
||||
|
||||
static {
|
||||
EVENTS.add(new DefaultConsumer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some custom configuration information.
|
||||
*/
|
||||
|
@ -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<EventData> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -38,5 +38,5 @@ public interface EventConsumer<T extends EventData> {
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
String properties();
|
||||
String regex();
|
||||
}
|
||||
|
@ -83,8 +83,8 @@ public interface ConfigLoader<T extends Config> {
|
||||
}
|
||||
String properties = data.getProperties();
|
||||
List<EventConsumer<EventData>> 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<EventData> consumer : eventsLists) {
|
||||
Optional<Config> first = ConfigEnv.getInstance().stream().filter(e -> properties.startsWith(e.prefix())).findFirst();
|
||||
@ -95,7 +95,7 @@ public interface ConfigLoader<T extends Config> {
|
||||
sources.add(new MapPropertyKeySource(first.get().prefix(), values));
|
||||
PassiveHandler<Config> handler = (ct, cf) -> {
|
||||
data.setConfig(cf);
|
||||
data.setSubscribe(consumer.properties());
|
||||
data.setSubscribe(consumer.regex());
|
||||
try {
|
||||
consumer.accept(data);
|
||||
} catch (ClassCastException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user