ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/websocket/server/WsWriteTimeout.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/websocket/server/WsWriteTimeout.java
Status
scanned
Type
file
Name
WsWriteTimeout.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3837 (3.7 KB)
MD5
2a3d737d4f1f07ec88d8aeee7192648c
SHA1
90fc3c3df241d781c1e7b5ed205b011c4b53fd58
SHA256
aaa4b80d35d5a78a5d377134a4dedf4bd75869c4aebf10a592fe2b143a4bbcb1
SHA512

      
    
SHA1_git
0c3e69db897b97f177f4f88fd46c3a95433ff128
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
WsWriteTimeout.java | 3.7 KB |

/* * 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.tomcat.websocket.server; import java.util.Comparator; import java.util.Set; import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.atomic.AtomicInteger; import org.apache.tomcat.websocket.BackgroundProcess; import org.apache.tomcat.websocket.BackgroundProcessManager; /** * Provides timeouts for asynchronous web socket writes. On the server side we only have access to * {@link jakarta.servlet.ServletOutputStream} and {@link jakarta.servlet.ServletInputStream} so there is no way to set * a timeout for writes to the client. */ public class WsWriteTimeout implements BackgroundProcess { /** * Note: The comparator imposes orderings that are inconsistent with equals */ private final Set<WsRemoteEndpointImplServer> endpoints = new ConcurrentSkipListSet<>(Comparator.comparingLong(WsRemoteEndpointImplServer::getTimeoutExpiry)); private final AtomicInteger count = new AtomicInteger(0); private int backgroundProcessCount = 0; private volatile int processPeriod = 1; @Override public void backgroundProcess() { // This method gets called once a second. backgroundProcessCount++; if (backgroundProcessCount >= processPeriod) { backgroundProcessCount = 0; long now = System.currentTimeMillis(); for (WsRemoteEndpointImplServer endpoint : endpoints) { if (endpoint.getTimeoutExpiry() < now) { // Background thread, not the thread that triggered the // write so no need to use a dispatch endpoint.onTimeout(false); } else { // Endpoints are ordered by timeout expiry so if this point // is reached there is no need to check the remaining // endpoints break; } } } } @Override public void setProcessPeriod(int period) { this.processPeriod = period; } /** * {@inheritDoc} The default value is 1 which means asynchronous write timeouts are processed every 1 second. */ @Override public int getProcessPeriod() { return processPeriod; } public void register(WsRemoteEndpointImplServer endpoint) { boolean result = endpoints.add(endpoint); if (result) { int newCount = count.incrementAndGet(); if (newCount == 1) { BackgroundProcessManager.getInstance().register(this); } } } public void unregister(WsRemoteEndpointImplServer endpoint) { boolean result = endpoints.remove(endpoint); if (result) { int newCount = count.decrementAndGet(); if (newCount == 0) { BackgroundProcessManager.getInstance().unregister(this); } } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
31.48
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9