You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/12/07 08:43:15 UTC
[camel] branch main updated: (chores) replacing more inner classes with lambda (#8854)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new eeaca358505 (chores) replacing more inner classes with lambda (#8854)
eeaca358505 is described below
commit eeaca35850530db69db6a939ef4418f8c0aff38a
Author: Gilvan Filho <gi...@gmail.com>
AuthorDate: Wed Dec 7 05:43:09 2022 -0300
(chores) replacing more inner classes with lambda (#8854)
* (chores) camel-jaxb: replace inner class with lambda
* (chores) camel-jgroups: replace inner class with lambda
* (chores) camel-jmx: replace inner class with lambda
* (chores) camel-knative-http: replace inner class with lambda
* (chores) camel-metrics: replace inner class with lambda
---
.../camel/converter/jaxb/JaxbDataFormat.java | 17 +++------
.../camel/component/jgroups/JGroupsFilters.java | 27 ++++++--------
.../jgroups/cluster/JGroupsLockClusterView.java | 21 +++++------
.../apache/camel/component/jmx/JMXConsumer.java | 34 +++++++----------
.../knative/http/KnativeHttpConsumer.java | 10 ++---
.../component/knative/http/KnativeHttpSupport.java | 43 ++++++++++------------
.../MetricsMessageHistoryService.java | 8 +---
7 files changed, 66 insertions(+), 94 deletions(-)
diff --git a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
index 865d882cbcc..ef8d56a63f8 100644
--- a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
+++ b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/JaxbDataFormat.java
@@ -39,7 +39,6 @@ import javax.xml.bind.MarshalException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.ValidationEvent;
-import javax.xml.bind.ValidationEventHandler;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
@@ -571,11 +570,9 @@ public class JaxbDataFormat extends ServiceSupport
Unmarshaller unmarshaller = getContext().createUnmarshaller();
if (schema != null) {
unmarshaller.setSchema(cachedSchema);
- unmarshaller.setEventHandler(new ValidationEventHandler() {
- public boolean handleEvent(ValidationEvent event) {
- // continue if the severity is lower than the configured level
- return event.getSeverity() < getSchemaSeverityLevel();
- }
+ unmarshaller.setEventHandler((ValidationEvent event) -> {
+ // continue if the severity is lower than the configured level
+ return event.getSeverity() < getSchemaSeverityLevel();
});
}
@@ -586,11 +583,9 @@ public class JaxbDataFormat extends ServiceSupport
Marshaller marshaller = getContext().createMarshaller();
if (schema != null) {
marshaller.setSchema(cachedSchema);
- marshaller.setEventHandler(new ValidationEventHandler() {
- public boolean handleEvent(ValidationEvent event) {
- // continue if the severity is lower than the configured level
- return event.getSeverity() < getSchemaSeverityLevel();
- }
+ marshaller.setEventHandler((ValidationEvent event) -> {
+ // continue if the severity is lower than the configured level
+ return event.getSeverity() < getSchemaSeverityLevel();
});
}
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsFilters.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsFilters.java
index b6f4f673c75..3c46faea824 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsFilters.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/JGroupsFilters.java
@@ -49,22 +49,19 @@ public final class JGroupsFilters {
* @return predicate filtering out non-coordinator view messages.
*/
public static Predicate dropNonCoordinatorViews() {
- return new Predicate() {
- @Override
- public boolean matches(Exchange exchange) {
- Object body = exchange.getIn().getBody();
- LOG.debug("Filtering message {}.", body);
- if (body instanceof View) {
- View view = (View) body;
- Address coordinatorNodeAddress = view.getMembers().get(COORDINATOR_NODE_INDEX);
- Address channelAddress = exchange.getIn().getHeader(HEADER_JGROUPS_CHANNEL_ADDRESS, Address.class);
- LOG.debug("Comparing endpoint channel address {} against the coordinator node address {}.",
- channelAddress, coordinatorNodeAddress);
- return channelAddress.equals(coordinatorNodeAddress);
- }
- LOG.debug("Body {} is not an instance of org.jgroups.View . Skipping filter.", body);
- return false;
+ return (Exchange exchange) -> {
+ Object body = exchange.getIn().getBody();
+ LOG.debug("Filtering message {}.", body);
+ if (body instanceof View) {
+ View view = (View) body;
+ Address coordinatorNodeAddress = view.getMembers().get(COORDINATOR_NODE_INDEX);
+ Address channelAddress = exchange.getIn().getHeader(HEADER_JGROUPS_CHANNEL_ADDRESS, Address.class);
+ LOG.debug("Comparing endpoint channel address {} against the coordinator node address {}.",
+ channelAddress, coordinatorNodeAddress);
+ return channelAddress.equals(coordinatorNodeAddress);
}
+ LOG.debug("Body {} is not an instance of org.jgroups.View . Skipping filter.", body);
+ return false;
};
}
diff --git a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterView.java b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterView.java
index f584c313440..e9e8ca230b6 100644
--- a/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterView.java
+++ b/components/camel-jgroups/src/main/java/org/apache/camel/component/jgroups/cluster/JGroupsLockClusterView.java
@@ -93,18 +93,15 @@ public class JGroupsLockClusterView extends AbstractCamelClusterView {
final CamelContext context = ObjectHelper.notNull(getCamelContext(), "CamelContext");
executor = context.getExecutorServiceManager().newSingleThreadScheduledExecutor(this,
"JGroupsLockClusterView-" + getClusterService().getId() + "-" + lockName);
- executor.execute(new Runnable() {
- @Override
- public void run() {
- LOG.info(
- "Attempting to become master acquiring the lock for group: {} in JGroups cluster {} with configuration: {}",
- lockName, jgroupsClusterName, jgroupsConfig);
- lock.lock();
- isMaster = true;
- fireLeadershipChangedEvent(Optional.ofNullable(localMember));
- LOG.info("Became master by acquiring the lock for group: {} in JGroups cluster {} with configuration: {}",
- lockName, jgroupsClusterName, jgroupsConfig);
- }
+ executor.execute(() -> {
+ LOG.info(
+ "Attempting to become master acquiring the lock for group: {} in JGroups cluster {} with configuration: {}",
+ lockName, jgroupsClusterName, jgroupsConfig);
+ lock.lock();
+ isMaster = true;
+ fireLeadershipChangedEvent(Optional.ofNullable(localMember));
+ LOG.info("Became master by acquiring the lock for group: {} in JGroups cluster {} with configuration: {}",
+ lockName, jgroupsClusterName, jgroupsConfig);
});
}
diff --git a/components/camel-jmx/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java b/components/camel-jmx/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java
index b4bca494e37..2ddca7354c3 100644
--- a/components/camel-jmx/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java
+++ b/components/camel-jmx/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java
@@ -167,16 +167,13 @@ public class JMXConsumer extends DefaultConsumer implements NotificationListener
* Schedules execution of the doStart() operation to occur again after the reconnect delay
*/
protected void scheduleDelayedStart() {
- Runnable startRunnable = new Runnable() {
- @Override
- public void run() {
- try {
- doStart();
- } catch (Exception e) {
- LOG.error("An unrecoverable exception has occurred while starting the JMX consumer"
- + " for endpoint {}",
- URISupport.sanitizeUri(mJmxEndpoint.getEndpointUri()), e);
- }
+ Runnable startRunnable = () -> {
+ try {
+ doStart();
+ } catch (Exception e) {
+ LOG.error("An unrecoverable exception has occurred while starting the JMX consumer"
+ + " for endpoint {}",
+ URISupport.sanitizeUri(mJmxEndpoint.getEndpointUri()), e);
}
};
LOG.info("Delaying JMX consumer startup for endpoint {}. Trying again in {} seconds.",
@@ -214,16 +211,13 @@ public class JMXConsumer extends DefaultConsumer implements NotificationListener
* Schedules an attempt to re-initialize a lost connection after the reconnect delay
*/
protected void scheduleReconnect() {
- Runnable startRunnable = new Runnable() {
- @Override
- public void run() {
- try {
- initNetworkConnection();
- addNotificationListener();
- } catch (Exception e) {
- LOG.warn("Failed to reconnect to JMX server. >> {}", e.getMessage());
- scheduleReconnect();
- }
+ Runnable startRunnable = () -> {
+ try {
+ initNetworkConnection();
+ addNotificationListener();
+ } catch (Exception e) {
+ LOG.warn("Failed to reconnect to JMX server. >> {}", e.getMessage());
+ scheduleReconnect();
}
};
LOG.info("Delaying JMX consumer reconnection for endpoint {}. Trying again in {} seconds.",
diff --git a/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java b/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java
index 86c2c0116b9..eec36a5045b 100644
--- a/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java
+++ b/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java
@@ -24,7 +24,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.function.Predicate;
-import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
@@ -126,12 +125,9 @@ public class KnativeHttpConsumer extends DefaultConsumer {
}
// add body handler
- route.handler(new Handler<RoutingContext>() {
- @Override
- public void handle(RoutingContext event) {
- event.request().resume();
- bodyHandler.handle(event);
- }
+ route.handler((RoutingContext event) -> {
+ event.request().resume();
+ bodyHandler.handle(event);
});
// add knative handler
diff --git a/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpSupport.java b/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpSupport.java
index 706bf8384b6..9c040bafc4b 100644
--- a/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpSupport.java
+++ b/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpSupport.java
@@ -61,35 +61,32 @@ public final class KnativeHttpSupport {
() -> filters.put(entry.getKey(), entry.getValue()));
}
- return new Predicate<HttpServerRequest>() {
- @Override
- public boolean test(HttpServerRequest request) {
- if (filters.isEmpty()) {
- return true;
- }
-
- for (Map.Entry<String, String> entry : filters.entrySet()) {
- final List<String> values = request.headers().getAll(entry.getKey());
- if (values.isEmpty()) {
- return false;
- }
+ return (HttpServerRequest request) -> {
+ if (filters.isEmpty()) {
+ return true;
+ }
- String val = values.get(values.size() - 1);
- int idx = val.lastIndexOf(',');
+ for (Map.Entry<String, String> entry : filters.entrySet()) {
+ final List<String> values = request.headers().getAll(entry.getKey());
+ if (values.isEmpty()) {
+ return false;
+ }
- if (values.size() == 1 && idx != -1) {
- val = val.substring(idx + 1);
- val = val.trim();
- }
+ String val = values.get(values.size() - 1);
+ int idx = val.lastIndexOf(',');
- boolean matches = Objects.equals(entry.getValue(), val) || val.matches(entry.getValue());
- if (!matches) {
- return false;
- }
+ if (values.size() == 1 && idx != -1) {
+ val = val.substring(idx + 1);
+ val = val.trim();
}
- return true;
+ boolean matches = Objects.equals(entry.getValue(), val) || val.matches(entry.getValue());
+ if (!matches) {
+ return false;
+ }
}
+
+ return true;
};
}
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
index 70306be9372..d55dfa53876 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
@@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit;
import javax.management.MBeanServer;
import com.codahale.metrics.Metric;
-import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.jmx.JmxReporter;
import com.codahale.metrics.json.MetricsModule;
@@ -195,11 +194,8 @@ public final class MetricsMessageHistoryService extends ServiceSupport
@Override
public void reset() {
// remove all
- metricsRegistry.removeMatching(new MetricFilter() {
- @Override
- public boolean matches(String name, Metric metric) {
- return true;
- }
+ metricsRegistry.removeMatching((String name, Metric metric) -> {
+ return true;
});
}
}