Skip to content

Commit

Permalink
Merge pull request #145 from pferraro/main
Browse files Browse the repository at this point in the history
Upgrade to wildfly-clustering 1.0.6.Final.
pferraro authored Mar 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 5b9851e + c2afa7d commit c326143
Showing 7 changed files with 95 additions and 132 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@
<version.org.springframework.session>3.2.1</version.org.springframework.session>
<version.org.infinispan>14.0.25.Final</version.org.infinispan>
<version.org.jboss.marshalling>2.1.4.Final</version.org.jboss.marshalling>
<version.org.wildfly.clustering>1.0.5.Final</version.org.wildfly.clustering>
<version.org.wildfly.clustering>1.0.6.Final</version.org.wildfly.clustering>

<!-- Test dependency versions -->
<version.org.apache.tomcat>10.1.19</version.org.apache.tomcat>
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@

import org.wildfly.clustering.cache.batch.Batch;
import org.wildfly.clustering.cache.batch.BatchContext;
import org.wildfly.clustering.session.OOBSession;
import org.wildfly.clustering.session.Session;
import org.wildfly.clustering.session.SessionManager;
import org.wildfly.clustering.session.user.User;
@@ -57,9 +56,6 @@ public String changeSessionId() {
oldSession.invalidate();
this.session = newSession;
} catch (IllegalStateException e) {
if (!oldSession.isValid()) {
oldSession.close();
}
newSession.invalidate();
throw e;
}
@@ -89,11 +85,6 @@ public <T> T getAttribute(String name) {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
return (T) session.getAttributes().getAttribute(name);
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -102,11 +93,6 @@ public Set<String> getAttributeNames() {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
return session.getAttributes().getAttributeNames();
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -115,11 +101,6 @@ public Instant getCreationTime() {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
return session.getMetaData().getCreationTime();
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -133,11 +114,6 @@ public Instant getLastAccessedTime() {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
return session.getMetaData().getLastAccessStartTime();
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -146,11 +122,6 @@ public Duration getMaxInactiveInterval() {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
return session.getMetaData().getTimeout();
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -159,11 +130,6 @@ public boolean isExpired() {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
return session.getMetaData().isExpired();
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -179,11 +145,6 @@ public void setAttribute(String name, Object value) {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
session.getAttributes().setAttribute(name, value);
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}

// N.B. org.springframework.session.web.http.HttpSessionAdapter already triggers HttpSessionBindingListener events
@@ -228,11 +189,6 @@ public void setMaxInactiveInterval(Duration duration) {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
session.getMetaData().setTimeout(duration);
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -241,11 +197,6 @@ public boolean isNew() {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
return session.getMetaData().isNew();
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -270,9 +221,6 @@ public void close() {
}
}
}
} finally {
// Switch to OOB session, in case this session is referenced outside the scope of this request
this.session = new OOBSession<>(this.manager, requestSession.getId(), null);
}
}
}
Original file line number Diff line number Diff line change
@@ -35,6 +35,10 @@ public void doHead(HttpServletRequest request, HttpServletResponse response) thr
HttpSession session = request.getSession(false);
if (session != null) {
response.setHeader(SmokeITParameters.SESSION_ID, session.getId());
AtomicInteger value = (AtomicInteger) session.getAttribute(SmokeITParameters.VALUE);
if (value != null) {
response.setIntHeader(SmokeITParameters.VALUE, value.get());
}
}
}

@@ -44,22 +48,18 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
response.setHeader(SmokeITParameters.SESSION_ID, session.getId());

AtomicInteger value = (AtomicInteger) session.getAttribute(SmokeITParameters.VALUE);
int result = 0;
if (value == null) {
value = new AtomicInteger(result);
value = new AtomicInteger(0);
session.setAttribute(SmokeITParameters.VALUE, value);
} else {
result = value.incrementAndGet();
}

response.setIntHeader(SmokeITParameters.VALUE, result);
response.setIntHeader(SmokeITParameters.VALUE, value.incrementAndGet());
}

@Override
public void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession(false);
if (session != null) {
response.setHeader(SmokeITParameters.SESSION_ID, session.getId());
session.invalidate();
}
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@

import org.wildfly.clustering.cache.batch.Batch;
import org.wildfly.clustering.cache.batch.BatchContext;
import org.wildfly.clustering.session.OOBSession;
import org.wildfly.clustering.session.Session;
import org.wildfly.clustering.session.SessionAttributes;
import org.wildfly.clustering.session.SessionManager;
@@ -91,9 +90,6 @@ public Mono<Void> changeSessionId() {
oldSession.invalidate();
this.session = newSession;
} catch (IllegalStateException e) {
if (!oldSession.isValid()) {
oldSession.close();
}
newSession.invalidate();
throw e;
}
@@ -103,7 +99,7 @@ public Mono<Void> changeSessionId() {

@Override
public Mono<Void> invalidate() {
return Mono.<Void>fromRunnable(this::invalidateSync).publishOn(Schedulers.boundedElastic());
return Mono.<Void>fromRunnable(this::invalidateSync).subscribeOn(Schedulers.boundedElastic());
}

private void invalidateSync() {
@@ -113,11 +109,6 @@ private void invalidateSync() {
if (this.batch != null) {
this.batch.close();
}
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

@@ -141,13 +132,11 @@ public void close() {
}
}
}
} finally {
// Switch to OOB session, in case this session is referenced outside the scope of this request
this.session = new OOBSession<>(this.manager, requestSession.getId(), null);
}
} else if (requestSession.isValid()) {
// Invalidate if session was never "started".
this.invalidateSync();
requestSession.close();
}
}

@@ -262,11 +251,6 @@ private <R> R apply(Function<Session<Void>, R> function) {
Session<Void> session = this.session;
try (BatchContext context = this.resumeBatch()) {
return function.apply(session);
} catch (IllegalStateException e) {
if (!session.isValid()) {
session.close();
}
throw e;
}
}

Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
package org.wildfly.clustering.spring.web;

import java.util.Iterator;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
import java.util.function.BiFunction;
import java.util.function.Function;
@@ -54,17 +53,15 @@ private Mono<SpringWebSession> getSession(BiFunction<SessionManager<Void, B>, St
B batch = batcher.createBatch();
try {
Mono<Session<Void>> result = Mono.fromCompletionStage(function.apply(this.manager, id));
// CompletionStage<Session<Void>> future = function.apply(this.manager, id);
B suspendedBatch = batcher.suspendBatch();
Supplier<Mono<Session<Void>>> creator = () -> {
try (BatchContext context = this.manager.getBatcher().resumeBatch(suspendedBatch)) {
return Mono.fromCompletionStage(this.manager.createSessionAsync(this.manager.getIdentifierFactory().get())).publishOn(Schedulers.boundedElastic());
return Mono.fromCompletionStage(this.manager.createSessionAsync(this.manager.getIdentifierFactory().get())).subscribeOn(Schedulers.boundedElastic());
}
};
return result.flatMap(session -> Optional.ofNullable(session).map(Mono::just).orElseGet(creator))
.flatMap(session -> Mono.just(new DistributableWebSession<>(this.manager, session, suspendedBatch)));
// return Mono.fromCompletionStage(future.thenCompose(session -> Optional.ofNullable(session).map(CompletableFuture::completedStage).orElseGet(creator))
// .thenApply(session -> new DistributableWebSession<>(this.manager, session, suspendedBatch)));
return result.switchIfEmpty(Mono.defer(creator)).map(session -> new DistributableWebSession<>(this.manager, session, suspendedBatch));
// return result.flatMap(session -> Optional.ofNullable(session).map(Mono::just).orElseGet(creator))
// .map(session -> new DistributableWebSession<>(this.manager, session, suspendedBatch));
} catch (RuntimeException | Error e) {
try (BatchContext context = batcher.resumeBatch(batch)) {
batch.discard();
@@ -82,7 +79,7 @@ private Mono<Void> close(ServerWebExchange exchange, SpringWebSession session) {
this.identifierResolver.setSessionId(exchange, session.getId());
}

return Mono.<Void>fromRunnable(session::close).publishOn(Schedulers.boundedElastic());
return Mono.<Void>fromRunnable(session::close).subscribeOn(Schedulers.boundedElastic());
}

private String requestedSessionId(ServerWebExchange exchange) {
Loading

0 comments on commit c326143

Please sign in to comment.