final UpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
final WebSocketEngine.UpgradeInfo upgradeInfo = serverContainer.getWebSocketEngine().upgrade(upgradeRequest, upgradeResponse);
switch (upgradeInfo.getStatus()) {
case SUCCESS:
final Connection grizzlyConnection = ctx.getConnection();
write(ctx, upgradeRequest, upgradeResponse);
final org.glassfish.tyrus.spi.Connection connection = upgradeInfo.createConnection(new GrizzlyWriter(ctx.getConnection()), new org.glassfish.tyrus.spi.Connection.CloseListener() {
@Override
public void close(CloseReason reason) {
grizzlyConnection.close();
}
});
TYRUS_CONNECTION.set(grizzlyConnection, connection);
grizzlyConnection.addCloseListener(new CloseListener() {
@Override
public void onClosed(Closeable closeable, ICloseType type) throws IOException {
connection.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "Close detected on connection"));
// might not be necessary, connection is going to be recycled/freed anyway
TYRUS_CONNECTION.remove(grizzlyConnection);