-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAMEL-21241: properties component - Should capture details about reso…
…lved placeholders
- Loading branch information
Showing
10 changed files
with
299 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
core/camel-api/src/main/java/org/apache/camel/spi/PropertiesResolvedValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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.apache.camel.spi; | ||
|
||
/** | ||
* Data about a {@link PropertiesComponent} property placeholder that has been resolved to a value by Camel. | ||
*/ | ||
public record PropertiesResolvedValue(String name, String originalValue, String value, String defaultValue, String source) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../src/main/java/org/apache/camel/component/properties/DefaultPropertiesLookupListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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.apache.camel.component.properties; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.camel.PropertiesLookupListener; | ||
import org.apache.camel.spi.PropertiesResolvedValue; | ||
import org.apache.camel.support.LRUCacheFactory; | ||
import org.apache.camel.support.service.ServiceSupport; | ||
|
||
/** | ||
* A {@link PropertiesLookupListener} listener that captures the resolved properties for dev consoles, management and | ||
* troubleshooting purposes. | ||
*/ | ||
public class DefaultPropertiesLookupListener extends ServiceSupport implements PropertiesLookupListener { | ||
|
||
private Map<String, PropertiesResolvedValue> properties; | ||
|
||
@Override | ||
public void onLookup(String name, String value, String defaultValue, String source) { | ||
properties.put(name, new PropertiesResolvedValue(name, value, value, defaultValue, source)); | ||
} | ||
|
||
void updateValue(String name, String newValue, String newSource) { | ||
var p = properties.get(name); | ||
if (p != null) { | ||
String source = newSource != null ? newSource : p.source(); | ||
properties.put(name, new PropertiesResolvedValue(p.name(), p.originalValue(), newValue, p.defaultValue(), source)); | ||
} | ||
} | ||
|
||
public PropertiesResolvedValue getProperty(String key) { | ||
return properties.get(key); | ||
} | ||
|
||
@Override | ||
protected void doBuild() throws Exception { | ||
// use a cache with max limit to avoid capturing endless property values | ||
// if there are a lot of dynamic values | ||
properties = LRUCacheFactory.newLRUCache(1000); | ||
} | ||
|
||
@Override | ||
protected void doShutdown() throws Exception { | ||
properties.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.