This is an automated email from the ASF dual-hosted git repository. ebourg pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit d3e9253e4d20f416f9f73b64c4169f9b15ca1e94 Author: Emmanuel Bourg <ebo...@apache.org> AuthorDate: Wed Dec 2 01:16:12 2020 +0100 Replace Runnable inner classes with lambda expressions --- java/org/apache/catalina/core/StandardServer.java | 14 +--- java/org/apache/catalina/servlets/CGIServlet.java | 7 +- .../apache/catalina/tribes/group/GroupChannel.java | 8 +- .../interceptors/MessageDispatchInterceptor.java | 8 +- .../interceptors/StaticMembershipInterceptor.java | 11 +-- .../tribes/membership/McastServiceImpl.java | 91 ++++++++++------------ .../membership/StaticMembershipProvider.java | 34 ++++---- .../membership/cloud/CloudMembershipProvider.java | 34 ++++---- .../tribes/transport/nio/NioReplicationTask.java | 46 +++++------ java/org/apache/coyote/AbstractProtocol.java | 20 ++--- java/org/apache/tomcat/util/net/Nio2Endpoint.java | 21 +++-- 11 files changed, 112 insertions(+), 182 deletions(-) diff --git a/java/org/apache/catalina/core/StandardServer.java b/java/org/apache/catalina/core/StandardServer.java index cfbdc09..1ac8676 100644 --- a/java/org/apache/catalina/core/StandardServer.java +++ b/java/org/apache/catalina/core/StandardServer.java @@ -933,12 +933,7 @@ public final class StandardServer extends LifecycleMBeanBase implements Server { if (periodicEventDelay > 0) { monitorFuture = getUtilityExecutor().scheduleWithFixedDelay( - new Runnable() { - @Override - public void run() { - startPeriodicLifecycleEvent(); - } - }, 0, 60, TimeUnit.SECONDS); + () -> startPeriodicLifecycleEvent(), 0, 60, TimeUnit.SECONDS); } } @@ -954,12 +949,7 @@ public final class StandardServer extends LifecycleMBeanBase implements Server { } } periodicLifecycleEventFuture = getUtilityExecutor().scheduleAtFixedRate( - new Runnable() { - @Override - public void run() { - fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null); - } - }, periodicEventDelay, periodicEventDelay, TimeUnit.SECONDS); + () -> fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null), periodicEventDelay, periodicEventDelay, TimeUnit.SECONDS); } } diff --git a/java/org/apache/catalina/servlets/CGIServlet.java b/java/org/apache/catalina/servlets/CGIServlet.java index e24c871..98672ad 100644 --- a/java/org/apache/catalina/servlets/CGIServlet.java +++ b/java/org/apache/catalina/servlets/CGIServlet.java @@ -1666,12 +1666,7 @@ public final class CGIServlet extends HttpServlet { (new InputStreamReader(proc.getErrorStream())); final BufferedReader stdErrRdr = commandsStdErr ; - errReaderThread = new Thread() { - @Override - public void run () { - sendToLog(stdErrRdr); - } - }; + errReaderThread = new Thread(() -> sendToLog(stdErrRdr)); errReaderThread.start(); InputStream cgiHeaderStream = diff --git a/java/org/apache/catalina/tribes/group/GroupChannel.java b/java/org/apache/catalina/tribes/group/GroupChannel.java index 1bb558a..abd9303 100644 --- a/java/org/apache/catalina/tribes/group/GroupChannel.java +++ b/java/org/apache/catalina/tribes/group/GroupChannel.java @@ -476,13 +476,7 @@ public class GroupChannel extends ChannelInterceptorBase ownExecutor = true; } super.start(svc); - monitorFuture = utilityExecutor.scheduleWithFixedDelay( - new Runnable() { - @Override - public void run() { - startHeartbeat(); - } - }, 0, 60, TimeUnit.SECONDS); + monitorFuture = utilityExecutor.scheduleWithFixedDelay(this::startHeartbeat, 0, 60, TimeUnit.SECONDS); } protected void startHeartbeat() { diff --git a/java/org/apache/catalina/tribes/group/interceptors/MessageDispatchInterceptor.java b/java/org/apache/catalina/tribes/group/interceptors/MessageDispatchInterceptor.java index ef869a6..18b9775 100644 --- a/java/org/apache/catalina/tribes/group/interceptors/MessageDispatchInterceptor.java +++ b/java/org/apache/catalina/tribes/group/interceptors/MessageDispatchInterceptor.java @@ -97,13 +97,7 @@ public class MessageDispatchInterceptor extends ChannelInterceptorBase public boolean addToQueue(final ChannelMessage msg, final Member[] destination, final InterceptorPayload payload) { - Runnable r = new Runnable() { - @Override - public void run() { - sendAsyncData(msg, destination, payload); - } - }; - executor.execute(r); + executor.execute(() -> sendAsyncData(msg, destination, payload)); return true; } diff --git a/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java b/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java index cd8e9e2..c7c70c8 100644 --- a/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java +++ b/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java @@ -159,13 +159,10 @@ public class StaticMembershipInterceptor extends ChannelInterceptorBase final ChannelInterceptorBase base = this; ScheduledExecutorService executor = getChannel().getUtilityExecutor(); for (final Member member : members) { - Runnable r = new Runnable() { - @Override - public void run() { - base.memberAdded(member); - if (getfirstInterceptor().getMember(member) != null) { - sendLocalMember(new Member[]{member}); - } + Runnable r = () -> { + base.memberAdded(member); + if (getfirstInterceptor().getMember(member) != null) { + sendLocalMember(new Member[]{member}); } }; executor.execute(r); diff --git a/java/org/apache/catalina/tribes/membership/McastServiceImpl.java b/java/org/apache/catalina/tribes/membership/McastServiceImpl.java index 27e4121..dc00496 100644 --- a/java/org/apache/catalina/tribes/membership/McastServiceImpl.java +++ b/java/org/apache/catalina/tribes/membership/McastServiceImpl.java @@ -368,30 +368,24 @@ public class McastServiceImpl extends MembershipProviderBase { if (Arrays.equals(m.getCommand(), Member.SHUTDOWN_PAYLOAD)) { if (log.isDebugEnabled()) log.debug("Member has shutdown:" + m); membership.removeMember(m); - t = new Runnable() { - @Override - public void run() { - String name = Thread.currentThread().getName(); - try { - Thread.currentThread().setName("Membership-MemberDisappeared"); - service.memberDisappeared(m); - }finally { - Thread.currentThread().setName(name); - } + t = () -> { + String name = Thread.currentThread().getName(); + try { + Thread.currentThread().setName("Membership-MemberDisappeared"); + service.memberDisappeared(m); + }finally { + Thread.currentThread().setName(name); } }; } else if (membership.memberAlive(m)) { if (log.isDebugEnabled()) log.debug("Mcast add member " + m); - t = new Runnable() { - @Override - public void run() { - String name = Thread.currentThread().getName(); - try { - Thread.currentThread().setName("Membership-MemberAdded"); - service.memberAdded(m); - }finally { - Thread.currentThread().setName(name); - } + t = () -> { + String name = Thread.currentThread().getName(); + try { + Thread.currentThread().setName("Membership-MemberAdded"); + service.memberAdded(m); + }finally { + Thread.currentThread().setName(name); } }; } //end if @@ -413,30 +407,27 @@ public class McastServiceImpl extends MembershipProviderBase { log.debug("Unable to decode message.",ise); } } - Runnable t = new Runnable() { - @Override - public void run() { - String name = Thread.currentThread().getName(); - try { - Thread.currentThread().setName("Membership-MemberAdded"); - for (ChannelData datum : data) { - try { - if (datum != null && !member.equals(datum.getAddress())) { - msgservice.messageReceived(datum); - } - } catch (Throwable t) { - if (t instanceof ThreadDeath) { - throw (ThreadDeath) t; - } - if (t instanceof VirtualMachineError) { - throw (VirtualMachineError) t; - } - log.error(sm.getString("mcastServiceImpl.unableReceive.broadcastMessage"), t); + Runnable t = () -> { + String name = Thread.currentThread().getName(); + try { + Thread.currentThread().setName("Membership-MemberAdded"); + for (ChannelData datum : data) { + try { + if (datum != null && !member.equals(datum.getAddress())) { + msgservice.messageReceived(datum); + } + } catch (Throwable t1) { + if (t1 instanceof ThreadDeath) { + throw (ThreadDeath) t1; } + if (t1 instanceof VirtualMachineError) { + throw (VirtualMachineError) t1; + } + log.error(sm.getString("mcastServiceImpl.unableReceive.broadcastMessage"), t1); } - }finally { - Thread.currentThread().setName(name); } + }finally { + Thread.currentThread().setName(name); } }; executor.execute(t); @@ -451,17 +442,13 @@ public class McastServiceImpl extends MembershipProviderBase { if (log.isDebugEnabled()) log.debug("Mcast expire member " + member); try { - Runnable t = new Runnable() { - @Override - public void run() { - String name = Thread.currentThread().getName(); - try { - Thread.currentThread().setName("Membership-MemberExpired"); - service.memberDisappeared(member); - } finally { - Thread.currentThread().setName(name); - } - + Runnable t = () -> { + String name = Thread.currentThread().getName(); + try { + Thread.currentThread().setName("Membership-MemberExpired"); + service.memberDisappeared(member); + } finally { + Thread.currentThread().setName(name); } }; executor.execute(t); diff --git a/java/org/apache/catalina/tribes/membership/StaticMembershipProvider.java b/java/org/apache/catalina/tribes/membership/StaticMembershipProvider.java index 4bd09f1..155cf29 100644 --- a/java/org/apache/catalina/tribes/membership/StaticMembershipProvider.java +++ b/java/org/apache/catalina/tribes/membership/StaticMembershipProvider.java @@ -157,16 +157,13 @@ public class StaticMembershipProvider extends MembershipProviderBase implements protected void memberAdded(Member member) { Member mbr = setupMember(member); if(membership.memberAlive(mbr)) { - Runnable r = new Runnable() { - @Override - public void run(){ - String name = Thread.currentThread().getName(); - try { - Thread.currentThread().setName("StaticMembership-memberAdded"); - membershipListener.memberAdded(mbr); - } finally { - Thread.currentThread().setName(name); - } + Runnable r = () -> { + String name = Thread.currentThread().getName(); + try { + Thread.currentThread().setName("StaticMembership-memberAdded"); + membershipListener.memberAdded(mbr); + } finally { + Thread.currentThread().setName(name); } }; executor.execute(r); @@ -175,16 +172,13 @@ public class StaticMembershipProvider extends MembershipProviderBase implements protected void memberDisappeared(Member member) { membership.removeMember(member); - Runnable r = new Runnable() { - @Override - public void run(){ - String name = Thread.currentThread().getName(); - try { - Thread.currentThread().setName("StaticMembership-memberDisappeared"); - membershipListener.memberDisappeared(member); - } finally { - Thread.currentThread().setName(name); - } + Runnable r = () -> { + String name = Thread.currentThread().getName(); + try { + Thread.currentThread().setName("StaticMembership-memberDisappeared"); + membershipListener.memberDisappeared(member); + } finally { + Thread.currentThread().setName(name); } }; executor.execute(r); diff --git a/java/org/apache/catalina/tribes/membership/cloud/CloudMembershipProvider.java b/java/org/apache/catalina/tribes/membership/cloud/CloudMembershipProvider.java index 22f9a95..3c6315d 100644 --- a/java/org/apache/catalina/tribes/membership/cloud/CloudMembershipProvider.java +++ b/java/org/apache/catalina/tribes/membership/cloud/CloudMembershipProvider.java @@ -131,16 +131,13 @@ public abstract class CloudMembershipProvider extends MembershipProviderBase imp if (log.isDebugEnabled()) { log.debug("Member added: " + member); } - Runnable r = new Runnable() { - @Override - public void run(){ - String name = Thread.currentThread().getName(); - try { - Thread.currentThread().setName("CloudMembership-memberAdded"); - membershipListener.memberAdded(member); - } finally { - Thread.currentThread().setName(name); - } + Runnable r = () -> { + String name = Thread.currentThread().getName(); + try { + Thread.currentThread().setName("CloudMembership-memberAdded"); + membershipListener.memberAdded(member); + } finally { + Thread.currentThread().setName(name); } }; executor.execute(r); @@ -152,16 +149,13 @@ public abstract class CloudMembershipProvider extends MembershipProviderBase imp if (log.isDebugEnabled()) { log.debug("Member disappeared: " + member); } - Runnable r = new Runnable() { - @Override - public void run(){ - String name = Thread.currentThread().getName(); - try { - Thread.currentThread().setName("CloudMembership-memberDisappeared"); - membershipListener.memberDisappeared(member); - } finally { - Thread.currentThread().setName(name); - } + Runnable r = () -> { + String name = Thread.currentThread().getName(); + try { + Thread.currentThread().setName("CloudMembership-memberDisappeared"); + membershipListener.memberDisappeared(member); + } finally { + Thread.currentThread().setName(name); } }; executor.execute(r); diff --git a/java/org/apache/catalina/tribes/transport/nio/NioReplicationTask.java b/java/org/apache/catalina/tribes/transport/nio/NioReplicationTask.java index 221d691..0cb3bbd 100644 --- a/java/org/apache/catalina/tribes/transport/nio/NioReplicationTask.java +++ b/java/org/apache/catalina/tribes/transport/nio/NioReplicationTask.java @@ -252,27 +252,24 @@ public class NioReplicationTask extends AbstractRxTask { log.trace("Adding key for read event:"+key); reader.finish(); //register our OP_READ interest - Runnable r = new Runnable() { - @Override - public void run() { - try { - if (key.isValid()) { - // cycle the selector so this key is active again - key.selector().wakeup(); - // resume interest in OP_READ, OP_WRITE - int resumeOps = key.interestOps() | SelectionKey.OP_READ; - key.interestOps(resumeOps); - if ( log.isTraceEnabled() ) - log.trace("Registering key for read:"+key); - } - } catch (CancelledKeyException ckx ) { - NioReceiver.cancelledKey(key); + Runnable r = () -> { + try { + if (key.isValid()) { + // cycle the selector so this key is active again + key.selector().wakeup(); + // resume interest in OP_READ, OP_WRITE + int resumeOps = key.interestOps() | SelectionKey.OP_READ; + key.interestOps(resumeOps); if ( log.isTraceEnabled() ) - log.trace("CKX Cancelling key:"+key); - - } catch (Exception x) { - log.error(sm.getString("nioReplicationTask.error.register.key", key),x); + log.trace("Registering key for read:"+key); } + } catch (CancelledKeyException ckx ) { + NioReceiver.cancelledKey(key); + if ( log.isTraceEnabled() ) + log.trace("CKX Cancelling key:"+key); + + } catch (Exception x) { + log.error(sm.getString("nioReplicationTask.error.register.key", key),x); } }; receiver.addEvent(r); @@ -287,14 +284,11 @@ public class NioReplicationTask extends AbstractRxTask { reader.setCancelled(true); reader.finish(); } - Runnable cx = new Runnable() { - @Override - public void run() { - if ( log.isTraceEnabled() ) - log.trace("Cancelling key:"+key); + Runnable cx = () -> { + if ( log.isTraceEnabled() ) + log.trace("Cancelling key:"+key); - NioReceiver.cancelledKey(key); - } + NioReceiver.cancelledKey(key); }; receiver.addEvent(cx); } diff --git a/java/org/apache/coyote/AbstractProtocol.java b/java/org/apache/coyote/AbstractProtocol.java index 089a07c..61dcffa 100644 --- a/java/org/apache/coyote/AbstractProtocol.java +++ b/java/org/apache/coyote/AbstractProtocol.java @@ -602,12 +602,9 @@ public abstract class AbstractProtocol<S> implements ProtocolHandler, endpoint.start(); monitorFuture = getUtilityExecutor().scheduleWithFixedDelay( - new Runnable() { - @Override - public void run() { - if (!isPaused()) { - startAsyncTimeout(); - } + () -> { + if (!isPaused()) { + startAsyncTimeout(); } }, 0, 60, TimeUnit.SECONDS); } @@ -629,13 +626,10 @@ public abstract class AbstractProtocol<S> implements ProtocolHandler, } } timeoutFuture = getUtilityExecutor().scheduleAtFixedRate( - new Runnable() { - @Override - public void run() { - long now = System.currentTimeMillis(); - for (Processor processor : waitingProcessors) { - processor.timeoutAsync(now); - } + () -> { + long now = System.currentTimeMillis(); + for (Processor processor : waitingProcessors) { + processor.timeoutAsync(now); } }, 1, 1, TimeUnit.SECONDS); } diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java b/java/org/apache/tomcat/util/net/Nio2Endpoint.java index 5775473..56d7295 100644 --- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java +++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java @@ -206,19 +206,16 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS acceptor.stop(10); // Use the executor to avoid binding the main thread if something bad // occurs and unbind will also wait for a bit for it to complete - getExecutor().execute(new Runnable() { - @Override - public void run() { - // Then close all active connections if any remain - try { - for (SocketWrapperBase<Nio2Channel> wrapper : getConnections()) { - wrapper.close(); - } - } catch (Throwable t) { - ExceptionUtils.handleThrowable(t); - } finally { - allClosed = true; + getExecutor().execute(() -> { + // Then close all active connections if any remain + try { + for (SocketWrapperBase<Nio2Channel> wrapper : getConnections()) { + wrapper.close(); } + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); + } finally { + allClosed = true; } }); if (nioChannels != null) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org