apupier commented on code in PR #20506: URL: https://github.com/apache/camel/pull/20506#discussion_r2630924404
########## components/camel-once/src/main/java/org/apache/camel/component/once/OnceEndpoint.java: ########## @@ -0,0 +1,156 @@ +/* + * 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.once; + +import java.util.Map; + +import org.apache.camel.Category; +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.DefaultEndpoint; + +@UriEndpoint(firstVersion = "4.170.0", scheme = "once", title = "Once", syntax = "once:name", consumerOnly = true, Review Comment: typo 4.170.0 -> 4.17.0 ########## components/camel-once/src/main/java/org/apache/camel/component/once/OnceEndpoint.java: ########## @@ -0,0 +1,156 @@ +/* + * 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.once; + +import java.util.Map; + +import org.apache.camel.Category; +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.DefaultEndpoint; + +@UriEndpoint(firstVersion = "4.170.0", scheme = "once", title = "Once", syntax = "once:name", consumerOnly = true, + remote = false, category = { Category.CORE, Category.SCHEDULING }) +public class OnceEndpoint extends DefaultEndpoint { + + @UriPath + @Metadata(required = true) + private String name; + @UriParam(label = "advanced", defaultValue = "1000") + private long delay = 1000; + @UriParam + @Metadata(supportFileReference = true) + private String body; + @UriParam(multiValue = true, prefix = "header.") + @Metadata(supportFileReference = true) + private Map<String, String> headers; + @UriParam(label = "advanced", multiValue = true, prefix = "variable.") + @Metadata(supportFileReference = true) + private Map<String, String> variables; + @UriParam(label = "advanced", multiValue = true, prefix = "exchangeProperty.") + @Metadata(supportFileReference = true) + private Map<String, String> exchangeProperties; + + public OnceEndpoint() { + } + + public OnceEndpoint(String endpointUri, Component component, String name) { + super(endpointUri, component); + this.name = name; + } + + @Override + public boolean isRemote() { + return false; + } + + @Override + public OnceComponent getComponent() { + return (OnceComponent) super.getComponent(); + } + + @Override + public Producer createProducer() throws Exception { + throw new RuntimeCamelException("Cannot produce to a OnceEndpoint: " + getEndpointUri()); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + Consumer answer = new OnceConsumer(this, processor); + configureConsumer(answer); + return answer; + } + + public String getName() { + return name; + } + + /** + * The logical name + */ + public void setName(String name) { + this.name = name; + } + + public long getDelay() { + return delay; + } + + /** + * The number of milliseconds to wait before triggering. + * <p/> + * The default value is 1000. Review Comment: if I'm not mistaken, this is the parameter which can be set to -1 to fire as soon as possible, if yes, i think it is worthy to mention it in the javadoc (and so the catalog) directly too ########## components/camel-once/src/main/java/org/apache/camel/component/once/OnceComponent.java: ########## @@ -0,0 +1,108 @@ +/* + * 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.once; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.camel.Endpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; +import org.apache.camel.util.PropertiesHelper; + +@Component("once") +public class OnceComponent extends DefaultComponent { + + @Metadata(label = "advanced", defaultValue = "1000") + private long delay = 1000; + + @Metadata(label = "advanced", defaultValue = "true") + private boolean languages = true; + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + OnceEndpoint answer = new OnceEndpoint(uri, this, remaining); + answer.setDelay(delay); + + Map<String, String> headers = getAndRemoveOrResolveReferenceParameter(parameters, "headers", Map.class); + Map<String, Object> map = PropertiesHelper.extractProperties(parameters, "header."); + if (map != null && !map.isEmpty()) { + if (headers == null) { + headers = new LinkedHashMap<>(); + } + for (Map.Entry<String, Object> me : map.entrySet()) { + headers.put(me.getKey(), me.getValue().toString()); + } + } + if (headers != null && !headers.isEmpty()) { + answer.setHeaders(headers); + } + Map<String, String> variables = getAndRemoveOrResolveReferenceParameter(parameters, "variables", Map.class); + map = PropertiesHelper.extractProperties(parameters, "variable."); + if (map != null && !map.isEmpty()) { + if (variables == null) { + variables = new LinkedHashMap<>(); + } + for (Map.Entry<String, Object> me : map.entrySet()) { + variables.put(me.getKey(), me.getValue().toString()); + } + } + if (variables != null && !variables.isEmpty()) { + answer.setVariables(variables); + } + Map<String, String> properties = getAndRemoveOrResolveReferenceParameter(parameters, "exchangeProperties", Map.class); + map = PropertiesHelper.extractProperties(parameters, "exchangeProperty."); + if (map != null && !map.isEmpty()) { + if (properties == null) { + properties = new LinkedHashMap<>(); Review Comment: what is the reason to use a LinkedHashMap instead of simple HashMap? ########## components/camel-once/src/generated/resources/META-INF/org/apache/camel/component/once/once.json: ########## @@ -0,0 +1,43 @@ +{ + "component": { + "kind": "component", + "name": "once", + "title": "Once", + "description": "Camel Once component", + "deprecated": false, + "firstVersion": "4.170.0", Review Comment: typo 4.170.0 -> 4.17.0 ########## dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/ComponentsBuilderFactory.java: ########## @@ -3553,6 +3553,19 @@ static Olingo2ComponentBuilderFactory.Olingo2ComponentBuilder olingo2() { static Olingo4ComponentBuilderFactory.Olingo4ComponentBuilder olingo4() { return Olingo4ComponentBuilderFactory.olingo4(); } + /** + * Once (camel-once) + * Camel Once component + * + * Category: core,scheduling + * Since: 4.170 Review Comment: typo 4.170 -> 4.17 ########## components/camel-once/src/main/docs/once-component.adoc: ########## @@ -0,0 +1,155 @@ += Once Component +:doctitle: Once +:shortname: once +:artifactid: camel-once +:description: Camel Once component +:since: 4.170 Review Comment: typo 4.170 -> 4.17 ########## catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/once.json: ########## @@ -0,0 +1,43 @@ +{ + "component": { + "kind": "component", + "name": "once", + "title": "Once", + "description": "Camel Once component", + "deprecated": false, + "firstVersion": "4.170.0", Review Comment: typo here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
