Skip to content

Commit

Permalink
catch exception
Browse files Browse the repository at this point in the history
  • Loading branch information
karsonto committed Aug 19, 2024
1 parent e676df9 commit a541c0a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.servicecomb.foundation.common.utils;

import java.util.function.Consumer;

public class LambdaUtils {

public static <T> Consumer<T> ignoreException(Consumer<T> consumer) {
return item -> {
try {
consumer.accept(item);
} catch (Throwable e) {
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.apache.servicecomb.foundation.common.cache.VersionedCache;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.utils.LambdaUtils;
import org.apache.servicecomb.registry.api.Discovery;
import org.apache.servicecomb.registry.api.DiscoveryInstance;
import org.apache.servicecomb.registry.api.LifeCycle;
Expand Down Expand Up @@ -318,7 +319,7 @@ public List<? extends DiscoveryInstance> findServiceInstances(String application

@Override
public void destroy() {
discoveryList.forEach(LifeCycle::destroy);
discoveryList.forEach(LambdaUtils.ignoreException(LifeCycle::destroy));
task.shutdownNow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import org.apache.servicecomb.foundation.common.utils.LambdaUtils;
import org.apache.servicecomb.registry.api.LifeCycle;
import org.apache.servicecomb.registry.api.MicroserviceInstanceStatus;
import org.apache.servicecomb.registry.api.Registration;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void addEndpoint(String endpoint) {
}

public void destroy() {
registrationList.forEach(LifeCycle::destroy);
registrationList.forEach(LambdaUtils.ignoreException(LifeCycle::destroy));
}

public void run() {
Expand Down

0 comments on commit a541c0a

Please sign in to comment.