Created
July 13, 2025 16:44
-
-
Save arleighdickerson/46d19ae095085db9418f4dbe18998578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.undertow.connector.ByteBufferPool; | |
import io.undertow.server.DefaultByteBufferPool; | |
import io.undertow.websockets.jsr.WebSocketDeploymentInfo; | |
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; | |
import org.springframework.boot.web.server.WebServerFactoryCustomizer; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> { | |
private static final int POOL_BUFFER_SIZE = 16384; | |
private static final boolean POOL_USE_DIRECT_BUFFERS = true; | |
@Override | |
public void customize(UndertowServletWebServerFactory factory) { | |
factory.addDeploymentInfoCustomizers(deploymentInfo -> { | |
deploymentInfo.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, createWebSocketDeploymentInfo()); | |
}); | |
} | |
private WebSocketDeploymentInfo createWebSocketDeploymentInfo() { | |
ByteBufferPool byteBufferPool = new DefaultByteBufferPool(POOL_USE_DIRECT_BUFFERS, POOL_BUFFER_SIZE); | |
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo(); | |
webSocketDeploymentInfo.setBuffers(byteBufferPool); | |
webSocketDeploymentInfo.setDispatchToWorkerThread(true); | |
return webSocketDeploymentInfo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment