2020import java .io .Serializable ;
2121import java .util .Set ;
2222import java .util .UUID ;
23- import java .util .regex .Pattern ;
24- import java .util .regex .PatternSyntaxException ;
2523
26- import org .apache .ignite .IgniteException ;
2724import org .apache .ignite .IgniteLogger ;
25+ import org .apache .ignite .cdc .CdcRegexManager ;
2826import org .apache .ignite .cluster .ClusterNode ;
2927import org .apache .ignite .internal .IgniteEx ;
3028import org .apache .ignite .internal .processors .cache .version .CacheVersionConflictResolver ;
4543 * @see CacheVersionConflictResolver
4644 */
4745public class CacheVersionConflictResolverPluginProvider <C extends PluginConfiguration > implements PluginProvider <C > {
48- /** */
49- public static final String DFLT_REGEXP = "" ;
50-
5146 /** Cluster id. */
5247 private byte clusterId ;
5348
@@ -72,11 +67,14 @@ public class CacheVersionConflictResolverPluginProvider<C extends PluginConfigur
7267 /** Custom conflict resolver. */
7368 private CacheVersionConflictResolver resolver ;
7469
70+ /** Regexp manager. */
71+ private CdcRegexManager regexManager ;
72+
7573 /** Include regex templates for cache names. */
76- private String includeTemplate = DFLT_REGEXP ;
74+ private String includeTemplate ;
7775
7876 /** Exclude regex templates for cache names. */
79- private String excludeTemplate = DFLT_REGEXP ;
77+ private String excludeTemplate ;
8078
8179 /** Log. */
8280 private IgniteLogger log ;
@@ -105,13 +103,15 @@ public CacheVersionConflictResolverPluginProvider() {
105103 @ Override public void initExtensions (PluginContext ctx , ExtensionRegistry registry ) {
106104 this .log = ctx .log (CacheVersionConflictResolverPluginProvider .class );
107105 this .provider = new CacheVersionConflictResolverCachePluginProvider <>(conflictResolveField , clusterId , resolver );
106+ this .regexManager = new CdcRegexManager (log );
107+ regexManager .compileRegexp (includeTemplate , excludeTemplate );
108108 }
109109
110110 /** {@inheritDoc} */
111111 @ Override public CachePluginProvider createCacheProvider (CachePluginContext ctx ) {
112112 String cacheName = ctx .igniteCacheConfiguration ().getName ();
113113
114- if (caches .contains (cacheName ) || matchesFilters (cacheName )) {
114+ if (caches .contains (cacheName ) || regexManager . matchesFilters (cacheName )) {
115115 log .info ("ConflictResolver provider set for cache [cacheName=" + cacheName + ']' );
116116
117117 return provider ;
@@ -201,24 +201,4 @@ public void setExcludeCacheTemplate(String excludeTemplate) {
201201 @ Nullable @ Override public <T > T createComponent (PluginContext ctx , Class <T > cls ) {
202202 return null ;
203203 }
204-
205- /**
206- * Matches cache name with compiled regex patterns.
207- *
208- * @param cacheName Cache name.
209- * @return True if cache name matches include pattern and doesn't match exclude pattern.
210- * @throws IgniteException If the template's syntax is invalid
211- */
212- private boolean matchesFilters (String cacheName ) {
213- try {
214- boolean matchesInclude = Pattern .compile (includeTemplate ).matcher (cacheName ).matches ();
215-
216- boolean matchesExclude = Pattern .compile (excludeTemplate ).matcher (cacheName ).matches ();
217-
218- return matchesInclude && !matchesExclude ;
219- }
220- catch (PatternSyntaxException e ) {
221- throw new IgniteException ("Invalid cache regexp template" , e );
222- }
223- }
224204}
0 commit comments