Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/upstream/v3.0-develop' int…
Browse files Browse the repository at this point in the history
…o summer-ospp#12028-sync-develop
  • Loading branch information
KomachiSion committed Jan 10, 2025
2 parents 7ccf2fb + bfb01f7 commit 9b07673
Show file tree
Hide file tree
Showing 90 changed files with 7,292 additions and 144 deletions.
60 changes: 60 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,66 @@ public static class Naming {
public static final String CMDB_CONTEXT_TYPE = "CMDB";
}

public static final String FUZZY_WATCH_PATTERN_SPLITTER = ">>";

/**
* fuzzy watch sync type of watch init notify.
*/
public static final String FUZZY_WATCH_INIT_NOTIFY = "FUZZY_WATCH_INIT_NOTIFY";

/**
* fuzzy watch sync type of watch init notify finish.
*/
public static final String FINISH_FUZZY_WATCH_INIT_NOTIFY = "FINISH_FUZZY_WATCH_INIT_NOTIFY";

/**
* fuzzy watch sync type of watch diff sync notify.
*/
public static final String FUZZY_WATCH_DIFF_SYNC_NOTIFY = "FUZZY_WATCH_DIFF_SYNC_NOTIFY";

/**
* fuzzy watch sync type of watch resource changed.
*/
public static final String FUZZY_WATCH_RESOURCE_CHANGED = "FUZZY_WATCH_RESOURCE_CHANGED";

/**
* watch type of watch.
*/
public static final String WATCH_TYPE_WATCH = "WATCH";

/**
* watch type of cancel watch.
*/
public static final String WATCH_TYPE_CANCEL_WATCH = "CANCEL_WATCH";

/**
* The constants in config fuzzy watch changed type directory.
*/
public static class ConfigChangedType {

public static final String ADD_CONFIG = "ADD_CONFIG";

public static final String DELETE_CONFIG = "DELETE_CONFIG";

public static final String CONFIG_CHANGED = "CONFIG_CHANGED";

}

/**
* The constants in naming fuzzy watch changed type directory.
*/
public static class ServiceChangedType {

public static final String ADD_SERVICE = "ADD_SERVICE";

public static final String DELETE_SERVICE = "DELETE_SERVICE";

public static final String INSTANCE_CHANGED = "INSTANCE_CHANGED";

public static final String HEART_BEAT = "HEART_BEAT";

}

/**
* The constants in lock directory.
*/
Expand Down
83 changes: 83 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/config/ConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
package com.alibaba.nacos.api.config;

import com.alibaba.nacos.api.config.filter.IConfigFilter;
import com.alibaba.nacos.api.config.listener.FuzzyWatchEventWatcher;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;

import java.util.Set;
import java.util.concurrent.Future;

/**
* Config Service Interface.
*
Expand Down Expand Up @@ -160,4 +164,83 @@ boolean publishConfigCas(String dataId, String group, String content, String cas
* @throws NacosException exception.
*/
void shutDown() throws NacosException;

/**
* Add a fuzzy listener to the configuration. After the server modifies the configuration matching the specified
* fixed group name, the client will utilize the incoming fuzzy listener callback. Fuzzy listeners allow for
* pattern-based subscription to configurations, where the fixed group name represents the group and dataId patterns
* specified for subscription.
*
* @param groupNamePattern The group name pattern representing the group and dataId patterns to subscribe to.
* @param watcher The fuzzy watcher to be added.
* @throws NacosException NacosException
* @since 3.0
*/
void fuzzyWatch(String groupNamePattern, FuzzyWatchEventWatcher watcher) throws NacosException;

/**
* Add a fuzzy listener to the configuration. After the server modifies the configuration matching the specified
* dataId pattern and fixed group name, the client will utilize the incoming fuzzy listener callback. Fuzzy
* listeners allow for pattern-based subscription to configurations.
*
* @param dataIdPattern The pattern to match dataIds for subscription.
* @param groupNamePattern The pattern to match group name representing the group and dataId patterns to subscribe to.
* @param watcher The fuzzy listener to be added.
* @throws NacosException NacosException
* @since 3.0
*/
void fuzzyWatch(String dataIdPattern, String groupNamePattern, FuzzyWatchEventWatcher watcher)
throws NacosException;

/**
* Add a fuzzy listener to the configuration and retrieve all configs that match the specified fixed group name.
* Fuzzy listeners allow for pattern-based subscription to configs, where the fixed group name represents the group
* and dataId patterns specified for subscription.
*
* @param groupNamePattern The group name pattern representing the group and dataId patterns to subscribe to.
* @param watcher The fuzzy watcher to be added.
* @return CompletableFuture containing collection of configs that match the specified fixed group name.
* @throws NacosException NacosException
* @since 3.0
*/
Future<Set<String>> fuzzyWatchWithGroupKeys(String groupNamePattern,
FuzzyWatchEventWatcher watcher) throws NacosException;

/**
* Add a fuzzy listener to the configuration and retrieve all configs that match the specified dataId pattern and
* fixed group name. Fuzzy listeners allow for pattern-based subscription to configs.
*
* @param dataIdPattern The pattern to match dataIds for subscription.
* @param groupNamePattern The group name pattern representing the group and dataId patterns to subscribe to.
* @param watcher The fuzzy watcher to be added.
* @return CompletableFuture containing collection of configs that match the specified dataId pattern and fixed
* group name.
* @throws NacosException NacosException
* @since 3.0
*/
Future<Set<String>> fuzzyWatchWithGroupKeys(String dataIdPattern, String groupNamePattern,
FuzzyWatchEventWatcher watcher) throws NacosException;

/**
* Cancel fuzzy listen and remove the event listener for a specified fixed group name.
*
* @param groupNamePattern The group name pattern for fuzzy watch.
* @param watcher The event watcher to be removed.
* @throws NacosException If an error occurs during the cancellation process.
* @since 3.0
*/
void cancelFuzzyWatch(String groupNamePattern, FuzzyWatchEventWatcher watcher) throws NacosException;

/**
* Cancel fuzzy listen and remove the event listener for a specified service name pattern and fixed group name.
*
* @param dataIdPattern The pattern to match dataId for fuzzy watch.
* @param groupNamePattern The group name pattern for fuzzy watch.
* @param watcher The event listener to be removed.
* @throws NacosException If an error occurs during the cancellation process.
* @since 3.0
*/
void cancelFuzzyWatch(String dataIdPattern, String groupNamePattern, FuzzyWatchEventWatcher watcher)
throws NacosException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.config.listener;

import java.util.concurrent.Executor;

/**
* AbstractFuzzyListenListener is an abstract class that provides basic functionality for listening to fuzzy
* configuration changes in Nacos.
*
* @author stone-98
* @date 2024/3/4
*/
public abstract class AbstractFuzzyWatchEventWatcher implements FuzzyWatchEventWatcher {

/**
* Get executor for execute this receive.
*
* @return Executor
*/
public Executor getExecutor() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*
* @author water.lyl
*/
@SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
public abstract class AbstractListener implements Listener {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.config.listener;

import com.alibaba.nacos.api.common.Constants;

/**
* Represents a fuzzy listening configuration change event.
*
* <p>This event indicates that a change has occurred in a configuration that matches a fuzzy listening pattern.
*
* @author stone-98
* @date 2024/3/12
*/
public class ConfigFuzzyWatchChangeEvent {

/**
* The group of the configuration that has changed.
*/
private String group;

/**
* The data ID of the configuration that has changed.
*/
private String dataId;

/**
* The namespace of the configuration that has changed.
*/
private String namespace;

/**
* The change type of local watcher , contains {"ADD_CONFIG", "DELETE_CONFIG"}.
* {@link Constants.ConfigChangedType}.
*/
private String changedType;

/**
* the sync type that trigger this changed,contains {"FUZZY_WATCH_INIT_NOTIFY","FUZZY_WATCH_RESOURCE_CHANGED",
* "FUZZY_WATCH_DIFF_SYNC_NOTIFY"}.
*/
private String syncType;

/**
* Constructs a FuzzyListenConfigChangeEvent with the specified parameters.
*
* @param group The group of the configuration that has changed
* @param dataId The data ID of the configuration that has changed
* @param changedType The type of change that has occurred
*/
private ConfigFuzzyWatchChangeEvent(String namespace, String group, String dataId, String changedType,
String syncType) {
this.group = group;
this.dataId = dataId;
this.namespace = namespace;
this.changedType = changedType;
this.syncType = syncType;
}

/**
* Constructs and returns a new FuzzyListenConfigChangeEvent with the specified parameters.
*
* @param group The group of the configuration that has changed
* @param dataId The data ID of the configuration that has changed
* @param changedType The type of change that has occurred
* @return A new FuzzyListenConfigChangeEvent instance
*/
public static ConfigFuzzyWatchChangeEvent build(String namespace, String group, String dataId, String changedType,
String syncType) {
return new ConfigFuzzyWatchChangeEvent(namespace, group, dataId, changedType, syncType);
}

public String getNamespace() {
return namespace;
}

public String getGroup() {
return group;
}

public String getDataId() {
return dataId;
}

public String getChangedType() {
return changedType;
}

public String getSyncType() {
return syncType;
}

@Override
public String toString() {
return "ConfigFuzzyWatchChangeEvent{" + "group='" + group + '\'' + ", dataId='" + dataId + '\''
+ ", namespace='" + namespace + '\'' + ", changedType='" + changedType + '\'' + ", syncType='"
+ syncType + '\'' + '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.config.listener;

import java.util.concurrent.Executor;

/**
* fuzzy watch config changes.
*
* @author stone-98
* @date 2024/3/4
*/
public interface FuzzyWatchEventWatcher {

/**
* Callback method invoked when a fuzzy configuration change event occurs.
*
* @param event The fuzzy configuration change event
*/
void onEvent(ConfigFuzzyWatchChangeEvent event);

/**
* Get executor for execute this receive.
*
* @return Executor
*/
Executor getExecutor();

}
Loading

0 comments on commit 9b07673

Please sign in to comment.