repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
|---|---|---|---|---|---|---|
null |
wildfly-main/clustering/web/spi/src/main/java/org/wildfly/clustering/web/session/Session.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.session;
/**
* Represents a web session.
* @author Paul Ferraro
*/
public interface Session<L> extends ImmutableSession, AutoCloseable {
/**
* {@inheritDoc}
*/
@Override
SessionMetaData getMetaData();
/**
* Invalidates this session.
* @throws IllegalStateException if this session was already invalidated.
*/
void invalidate();
/**
* {@inheritDoc}
*/
@Override
SessionAttributes getAttributes();
/**
* Indicates that the application thread is finished with this session.
* This method is intended to be invoked within the context of a batch.
*/
@Override
void close();
/**
* Returns the local context of this session.
* The local context is *not* replicated to other nodes in the cluster.
* @return a local context
*/
L getLocalContext();
}
| 1,929
| 30.639344
| 77
|
java
|
null |
wildfly-main/clustering/web/spi/src/main/java/org/wildfly/clustering/web/session/ImmutableSessionAttributes.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.session;
import java.util.Set;
/**
* Provides read-only access to a session's attributes.
* @author Paul Ferraro
*/
public interface ImmutableSessionAttributes {
/**
* Returns the names of the attributes of this session.
* @return a set of unique attribute names
*/
Set<String> getAttributeNames();
/**
* Retrieves the value of the specified attribute.
* @param name a unique attribute name
* @return the attribute value, or null if the attribute does not exist.
*/
Object getAttribute(String name);
}
| 1,617
| 35.772727
| 76
|
java
|
null |
wildfly-main/clustering/web/spi/src/main/java/org/wildfly/clustering/web/session/oob/OOBSession.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.session.oob;
import java.time.Duration;
import java.time.Instant;
import java.util.Set;
import org.wildfly.clustering.ee.Batch;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.Session;
import org.wildfly.clustering.web.session.SessionAttributes;
import org.wildfly.clustering.web.session.SessionManager;
import org.wildfly.clustering.web.session.SessionMetaData;
/**
* Out-of-band session implementation, for use outside the context of a request.
* @author Paul Ferraro
*/
public class OOBSession<L, B extends Batch> implements Session<L>, SessionMetaData, SessionAttributes {
private final SessionManager<L, B> manager;
private final String id;
private final L localContext;
public OOBSession(SessionManager<L, B> manager, String id, L localContext) {
this.manager = manager;
this.id = id;
this.localContext = localContext;
}
@Override
public String getId() {
return this.id;
}
@Override
public boolean isValid() {
try (B batch = this.manager.getBatcher().createBatch()) {
return this.manager.readSession(this.id) != null;
}
}
@Override
public SessionMetaData getMetaData() {
return this;
}
@Override
public void invalidate() {
try (B batch = this.manager.getBatcher().createBatch()) {
try (Session<L> session = this.manager.findSession(this.id)) {
if (session == null) {
throw new IllegalStateException();
}
session.invalidate();
}
}
}
@Override
public SessionAttributes getAttributes() {
return this;
}
@Override
public L getLocalContext() {
return this.localContext;
}
@Override
public void close() {
// OOB session have no concept of lifecycle
}
@Override
public boolean isNew() {
try (B batch = this.manager.getBatcher().createBatch()) {
ImmutableSession session = this.manager.readSession(this.id);
if (session == null) {
throw new IllegalStateException();
}
return session.getMetaData().isNew();
}
}
@Override
public boolean isExpired() {
try (B batch = this.manager.getBatcher().createBatch()) {
ImmutableSession session = this.manager.readSession(this.id);
if (session == null) {
throw new IllegalStateException();
}
return session.getMetaData().isExpired();
}
}
@Override
public Instant getCreationTime() {
try (B batch = this.manager.getBatcher().createBatch()) {
ImmutableSession session = this.manager.readSession(this.id);
if (session == null) {
throw new IllegalStateException();
}
return session.getMetaData().getCreationTime();
}
}
@Override
public Instant getLastAccessStartTime() {
try (B batch = this.manager.getBatcher().createBatch()) {
ImmutableSession session = this.manager.readSession(this.id);
if (session == null) {
throw new IllegalStateException();
}
return session.getMetaData().getLastAccessStartTime();
}
}
@Override
public Instant getLastAccessTime() {
try (B batch = this.manager.getBatcher().createBatch()) {
ImmutableSession session = this.manager.readSession(this.id);
if (session == null) {
throw new IllegalStateException();
}
return session.getMetaData().getLastAccessTime();
}
}
@Override
public Duration getTimeout() {
try (B batch = this.manager.getBatcher().createBatch()) {
ImmutableSession session = this.manager.readSession(this.id);
if (session == null) {
throw new IllegalStateException();
}
return session.getMetaData().getTimeout();
}
}
@Override
public void setLastAccess(Instant startTime, Instant endTime) {
throw new IllegalStateException();
}
@Override
public void setMaxInactiveInterval(Duration duration) {
try (B batch = this.manager.getBatcher().createBatch()) {
try (Session<L> session = this.manager.findSession(this.id)) {
if (session == null) {
throw new IllegalStateException();
}
session.getMetaData().setMaxInactiveInterval(duration);
}
}
}
@Override
public Set<String> getAttributeNames() {
try (B batch = this.manager.getBatcher().createBatch()) {
ImmutableSession session = this.manager.readSession(this.id);
if (session == null) {
throw new IllegalStateException();
}
return session.getAttributes().getAttributeNames();
}
}
@Override
public Object getAttribute(String name) {
try (B batch = this.manager.getBatcher().createBatch()) {
ImmutableSession session = this.manager.readSession(this.id);
if (session == null) {
throw new IllegalStateException();
}
return session.getAttributes().getAttribute(name);
}
}
@Override
public Object removeAttribute(String name) {
try (B batch = this.manager.getBatcher().createBatch()) {
try (Session<L> session = this.manager.findSession(this.id)) {
if (session == null) {
throw new IllegalStateException();
}
return session.getAttributes().removeAttribute(name);
}
}
}
@Override
public Object setAttribute(String name, Object value) {
try (B batch = this.manager.getBatcher().createBatch()) {
try (Session<L> session = this.manager.findSession(this.id)) {
if (session == null) {
throw new IllegalStateException();
}
return session.getAttributes().setAttribute(name, value);
}
}
}
}
| 7,353
| 31.684444
| 103
|
java
|
null |
wildfly-main/clustering/web/spi/src/main/java/org/wildfly/clustering/web/routing/RouteLocator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.routing;
/**
* Locates the route appropriate for a given session identifier.
* @author Paul Ferraro
*/
public interface RouteLocator {
/**
* Returns the route identifier most appropriate for the specified session identifier.
* @param sessionId a unique session identifier
* @return a unique instance identifier
*/
String locate(String sessionId);
}
| 1,439
| 39
| 90
|
java
|
null |
wildfly-main/clustering/web/api/src/main/java/org/wildfly/clustering/web/annotation/Immutable.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicates that an object is either explicitly or effectively immutable.
* @author Paul Ferraro
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Immutable {
}
| 1,434
| 37.783784
| 74
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/sso/CompositeSSOTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.wildfly.clustering.ee.Remover;
import org.wildfly.clustering.web.LocalContextFactory;
import org.wildfly.clustering.web.sso.SSO;
import org.wildfly.clustering.web.sso.Sessions;
public class CompositeSSOTestCase {
private final String id = "id";
private final String authentication = "auth";
private final Sessions<String, String> sessions = mock(Sessions.class);
private final AtomicReference<Object> localContext = new AtomicReference<>();
private final LocalContextFactory<Object> localContextFactory = mock(LocalContextFactory.class);
private final Remover<String> remover = mock(Remover.class);
private final SSO<String, String, String, Object> sso = new CompositeSSO<>(this.id, this.authentication, this.sessions, this.localContext, this.localContextFactory, this.remover);
@Test
public void getId() {
assertSame(this.id, this.sso.getId());
}
@Test
public void getAuthentication() {
assertSame(this.authentication, this.sso.getAuthentication());
}
@Test
public void getSessions() {
assertSame(this.sessions, this.sso.getSessions());
}
@Test
public void invalidate() {
this.sso.invalidate();
verify(this.remover).remove(this.id);
}
@SuppressWarnings("unchecked")
@Test
public void getLocalContext() {
Object expected = new Object();
when(this.localContextFactory.createLocalContext()).thenReturn(expected);
Object result = this.sso.getLocalContext();
assertSame(expected, result);
reset(this.localContextFactory);
result = this.sso.getLocalContext();
verifyNoInteractions(this.localContextFactory);
assertSame(expected, result);
}
}
| 2,976
| 33.616279
| 183
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/sso/AuthenticationEntryMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
/**
* Unit test for {@link AuthenticationEntryExternalizer}.
* @author Paul Ferraro
*/
public class AuthenticationEntryMarshallerTestCase {
@Test
public void test() throws IOException {
ProtoStreamTesterFactory.INSTANCE.<AuthenticationEntry<String, Object>>createTester().test(new AuthenticationEntry<>("username"), AuthenticationEntryMarshallerTestCase::assertEquals);
}
static void assertEquals(AuthenticationEntry<String, Object> entry1, AuthenticationEntry<String, Object> entry2) {
Assert.assertEquals(entry1.getAuthentication(), entry2.getAuthentication());
}
}
| 1,838
| 38.978261
| 191
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/sso/coarse/CoarseSessionsTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso.coarse;
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.wildfly.clustering.ee.Mutator;
import org.wildfly.clustering.web.sso.Sessions;
public class CoarseSessionsTestCase {
private Mutator mutator = mock(Mutator.class);
private Map<String, String> map = mock(Map.class);
private Sessions<String, String> sessions = new CoarseSessions<>(this.map, this.mutator);
@Test
public void getApplications() {
Set<String> expected = Collections.singleton("deployment");
when(this.map.keySet()).thenReturn(expected);
Set<String> result = this.sessions.getDeployments();
assertEquals(expected, result);
verify(this.mutator, never()).mutate();
}
@Test
public void getSession() {
String expected = "id";
String deployment = "deployment1";
String missingDeployment = "deployment2";
when(this.map.get(deployment)).thenReturn(expected);
when(this.map.get(missingDeployment)).thenReturn(null);
assertSame(expected, this.sessions.getSession(deployment));
assertNull(this.sessions.getSession(missingDeployment));
verify(this.mutator, never()).mutate();
}
@Test
public void addSession() {
String id = "id";
String deployment = "deployment";
when(this.map.put(deployment, id)).thenReturn(null);
this.sessions.addSession(deployment, id);
verify(this.mutator).mutate();
reset(this.map, this.mutator);
when(this.map.put(deployment, id)).thenReturn(id);
this.sessions.addSession(deployment, id);
verify(this.mutator, never()).mutate();
}
@Test
public void removeSession() {
String deployment = "deployment";
when(this.map.remove(deployment)).thenReturn("id");
this.sessions.removeSession(deployment);
verify(this.mutator).mutate();
reset(this.map, this.mutator);
when(this.map.remove(deployment)).thenReturn(null);
this.sessions.removeSession(deployment);
verify(this.mutator, never()).mutate();
}
}
| 3,300
| 30.141509
| 93
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/ConcurrentSessionManagerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.time.Duration;
import java.util.Collections;
import java.util.Set;
import java.util.function.Supplier;
import org.junit.Test;
import org.wildfly.clustering.ee.Batch;
import org.wildfly.clustering.ee.Batcher;
import org.wildfly.clustering.ee.cache.ConcurrentManager;
import org.wildfly.clustering.ee.cache.SimpleManager;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.Session;
import org.wildfly.clustering.web.session.SessionManager;
import org.wildfly.clustering.web.session.SessionMetaData;
/**
* Unit test for {@link ConcurrentSessionManager}.
* @author Paul Ferraro
*/
public class ConcurrentSessionManagerTestCase {
@SuppressWarnings("unchecked")
@Test
public void findSession() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, ConcurrentManager::new);
Session<Void> expected1 = mock(Session.class);
Session<Void> expected2 = mock(Session.class);
String id = "foo";
SessionMetaData metaData1 = mock(SessionMetaData.class);
SessionAttributes attributes1 = mock(SessionAttributes.class);
SessionMetaData metaData2 = mock(SessionMetaData.class);
SessionAttributes attributes2 = mock(SessionAttributes.class);
when(manager.findSession(id)).thenReturn(expected1, expected2);
when(expected1.getId()).thenReturn(id);
when(expected1.isValid()).thenReturn(true);
when(expected1.getAttributes()).thenReturn(attributes1);
when(expected1.getMetaData()).thenReturn(metaData1);
when(expected2.getId()).thenReturn(id);
when(expected2.isValid()).thenReturn(true);
when(expected2.getAttributes()).thenReturn(attributes2);
when(expected2.getMetaData()).thenReturn(metaData2);
try (Session<Void> session1 = subject.findSession(id)) {
assertNotNull(session1);
assertSame(id, session1.getId());
assertSame(metaData1, session1.getMetaData());
assertSame(attributes1, session1.getAttributes());
try (Session<Void> session2 = subject.findSession(id)) {
assertNotNull(session2);
// Should return the same session without invoking the manager
assertSame(session1, session2);
}
// Should not trigger Session.close() yet
verify(expected1, never()).close();
}
verify(expected1).close();
// Should use second session instance
try (Session<Void> session = subject.findSession(id)) {
assertNotNull(session);
assertSame(id, session.getId());
assertSame(metaData2, session.getMetaData());
assertSame(attributes2, session.getAttributes());
}
}
@SuppressWarnings("unchecked")
@Test
public void findInvalidSession() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, ConcurrentManager::new);
Session<Void> expected1 = mock(Session.class);
String id = "foo";
SessionMetaData metaData1 = mock(SessionMetaData.class);
SessionAttributes attributes1 = mock(SessionAttributes.class);
when(manager.findSession(id)).thenReturn(expected1, (Session<Void>) null);
when(expected1.getId()).thenReturn(id);
when(expected1.isValid()).thenReturn(true);
when(expected1.getAttributes()).thenReturn(attributes1);
when(expected1.getMetaData()).thenReturn(metaData1);
try (Session<Void> session1 = subject.findSession(id)) {
assertNotNull(session1);
assertSame(id, session1.getId());
assertSame(metaData1, session1.getMetaData());
assertSame(attributes1, session1.getAttributes());
session1.invalidate();
verify(expected1).invalidate();
verify(expected1).close();
Session<Void> session2 = subject.findSession(id);
assertNull(session2);
}
}
@SuppressWarnings("unchecked")
@Test
public void createSession() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, ConcurrentManager::new);
Session<Void> expected1 = mock(Session.class);
Session<Void> expected2 = mock(Session.class);
String id = "foo";
SessionMetaData metaData1 = mock(SessionMetaData.class);
SessionAttributes attributes1 = mock(SessionAttributes.class);
SessionMetaData metaData2 = mock(SessionMetaData.class);
SessionAttributes attributes2 = mock(SessionAttributes.class);
when(manager.createSession(id)).thenReturn(expected1, expected2);
when(expected1.getId()).thenReturn(id);
when(expected1.isValid()).thenReturn(true);
when(expected1.getAttributes()).thenReturn(attributes1);
when(expected1.getMetaData()).thenReturn(metaData1);
when(expected2.getId()).thenReturn(id);
when(expected2.isValid()).thenReturn(true);
when(expected2.getAttributes()).thenReturn(attributes2);
when(expected2.getMetaData()).thenReturn(metaData2);
try (Session<Void> session1 = subject.createSession(id)) {
assertNotNull(session1);
assertSame(id, session1.getId());
assertSame(metaData1, session1.getMetaData());
assertSame(attributes1, session1.getAttributes());
try (Session<Void> session2 = subject.findSession(id)) {
assertNotNull(session2);
// Should return the same session without invoking the manager
assertSame(session1, session2);
}
// Should not trigger Session.close() yet
verify(expected1, never()).close();
}
verify(expected1).close();
// Should use second session instance
try (Session<Void> session = subject.createSession(id)) {
assertNotNull(session);
assertSame(id, session.getId());
assertSame(metaData2, session.getMetaData());
assertSame(attributes2, session.getAttributes());
}
}
@Test
public void getIdentifierFactory() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
Supplier<String> expected = mock(Supplier.class);
when(manager.getIdentifierFactory()).thenReturn(expected);
Supplier<String> result = subject.getIdentifierFactory();
assertSame(expected, result);
}
@Test
public void start() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
subject.start();
verify(manager).start();
}
@Test
public void stop() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
subject.stop();
verify(manager).stop();
}
@Test
public void getActiveSessionCount() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
long expected = 1000L;
when(manager.getActiveSessionCount()).thenReturn(expected);
long result = subject.getActiveSessionCount();
assertEquals(expected, result);
}
@Test
public void getBatcher() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
Batcher<Batch> expected = mock(Batcher.class);
when(manager.getBatcher()).thenReturn(expected);
Batcher<Batch> result = subject.getBatcher();
assertSame(expected, result);
}
@Test
public void getActiveSessions() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
Set<String> expected = Collections.singleton("foo");
when(manager.getActiveSessions()).thenReturn(expected);
Set<String> result = subject.getActiveSessions();
assertSame(expected, result);
}
@Test
public void getLocalSessions() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
Set<String> expected = Collections.singleton("foo");
when(manager.getLocalSessions()).thenReturn(expected);
Set<String> result = subject.getLocalSessions();
assertSame(expected, result);
}
@Test
public void readSession() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
ImmutableSession expected = mock(ImmutableSession.class);
String id = "foo";
when(manager.readSession(id)).thenReturn(expected);
ImmutableSession result = subject.readSession(id);
assertSame(expected, result);
}
@Test
public void getStopTimeout() {
SessionManager<Void, Batch> manager = mock(SessionManager.class);
SessionManager<Void, Batch> subject = new ConcurrentSessionManager<>(manager, SimpleManager::new);
Duration expected = Duration.ofMinutes(1);
when(manager.getStopTimeout()).thenReturn(expected);
Duration result = subject.getStopTimeout();
assertSame(expected, result);
}
}
| 11,293
| 37.546075
| 110
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/CompositeSessionTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.wildfly.clustering.ee.Remover;
import org.wildfly.clustering.web.LocalContextFactory;
import org.wildfly.clustering.web.session.Session;
/**
* Unit test for {@link CompositeSession}.
*
* @author paul
*/
public class CompositeSessionTestCase {
private final String id = "session";
private final InvalidatableSessionMetaData metaData = mock(InvalidatableSessionMetaData.class);
private final SessionAttributes attributes = mock(SessionAttributes.class);
private final Remover<String> remover = mock(Remover.class);
private final LocalContextFactory<Object> localContextFactory = mock(LocalContextFactory.class);
private final AtomicReference<Object> localContextRef = new AtomicReference<>();
private final Session<Object> session = new CompositeSession<>(this.id, this.metaData, this.attributes, this.localContextRef, this.localContextFactory, this.remover);
@Test
public void getId() {
assertSame(this.id, this.session.getId());
}
@Test
public void getAttributes() {
assertSame(this.attributes, this.session.getAttributes());
}
@Test
public void getMetaData() {
assertSame(this.metaData, this.session.getMetaData());
}
@Test
public void invalidate() {
when(this.metaData.invalidate()).thenReturn(true);
this.session.invalidate();
verify(this.remover).remove(this.id);
reset(this.remover);
when(this.metaData.invalidate()).thenReturn(false);
this.session.invalidate();
verify(this.remover, never()).remove(this.id);
}
@Test
public void isValid() {
when(this.metaData.isValid()).thenReturn(true);
assertTrue(this.session.isValid());
when(this.metaData.isValid()).thenReturn(false);
assertFalse(this.session.isValid());
}
@Test
public void close() {
when(this.metaData.isValid()).thenReturn(true);
this.session.close();
verify(this.attributes).close();
verify(this.metaData).close();
reset(this.metaData, this.attributes);
// Verify that session is not mutated if invalid
when(this.metaData.isValid()).thenReturn(false);
this.session.close();
verify(this.attributes, never()).close();
verify(this.metaData, never()).close();
}
@SuppressWarnings("unchecked")
@Test
public void getLocalContext() {
Object expected = new Object();
when(this.localContextFactory.createLocalContext()).thenReturn(expected);
Object result = this.session.getLocalContext();
assertSame(expected, result);
reset(this.localContextFactory);
result = this.session.getLocalContext();
verifyNoInteractions(this.localContextFactory);
assertSame(expected, result);
}
}
| 4,071
| 30.323077
| 170
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/ImmutableSessionActivationNotifierTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import static org.mockito.Mockito.*;
import java.util.Map;
import java.util.TreeMap;
import java.util.function.Consumer;
import org.junit.After;
import org.junit.Test;
import org.mockito.Mockito;
import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider;
import org.wildfly.clustering.web.session.ImmutableSession;
/**
* @author Paul Ferraro
*/
public class ImmutableSessionActivationNotifierTestCase {
interface Session {
}
interface Context {
}
interface Listener {
}
private final HttpSessionActivationListenerProvider<Session, Context, Listener> provider = mock(HttpSessionActivationListenerProvider.class);
private final ImmutableSession session = mock(ImmutableSession.class);
private final Context context = mock(Context.class);
private final SessionAttributesFilter filter = mock(SessionAttributesFilter.class);
private final Listener listener1 = mock(Listener.class);
private final Listener listener2 = mock(Listener.class);
private final SessionActivationNotifier notifier = new ImmutableSessionActivationNotifier<>(this.provider, this.session, this.context, this.filter);
@After
public void destroy() {
Mockito.reset(this.session, this.provider);
}
@SuppressWarnings("unchecked")
@Test
public void test() {
Map<String, Listener> listeners = new TreeMap<>();
listeners.put("listener1", this.listener1);
listeners.put("listener2", this.listener2);
when(this.provider.getHttpSessionActivationListenerClass()).thenReturn(Listener.class);
when(this.filter.getAttributes(Listener.class)).thenReturn(listeners);
Session session = mock(Session.class);
Consumer<Session> prePassivateNotifier1 = mock(Consumer.class);
Consumer<Session> prePassivateNotifier2 = mock(Consumer.class);
Consumer<Session> postActivateNotifier1 = mock(Consumer.class);
Consumer<Session> postActivateNotifier2 = mock(Consumer.class);
when(this.provider.createHttpSession(same(this.session), same(this.context))).thenReturn(session);
when(this.provider.prePassivateNotifier(same(this.listener1))).thenReturn(prePassivateNotifier1);
when(this.provider.prePassivateNotifier(same(this.listener2))).thenReturn(prePassivateNotifier2);
when(this.provider.postActivateNotifier(same(this.listener1))).thenReturn(postActivateNotifier1);
when(this.provider.postActivateNotifier(same(this.listener2))).thenReturn(postActivateNotifier2);
// verify pre-passivate before post-activate is a no-op
this.notifier.prePassivate();
verify(prePassivateNotifier1, never()).accept(session);
verify(prePassivateNotifier2, never()).accept(session);
verify(postActivateNotifier1, never()).accept(session);
verify(postActivateNotifier2, never()).accept(session);
// verify initial post-activate
this.notifier.postActivate();
verify(prePassivateNotifier1, never()).accept(session);
verify(prePassivateNotifier2, never()).accept(session);
verify(postActivateNotifier1).accept(session);
verify(postActivateNotifier2).accept(session);
reset(postActivateNotifier1, postActivateNotifier2);
// verify subsequent post-activate is a no-op
this.notifier.postActivate();
verify(prePassivateNotifier1, never()).accept(session);
verify(prePassivateNotifier2, never()).accept(session);
verify(postActivateNotifier1, never()).accept(session);
verify(postActivateNotifier2, never()).accept(session);
// verify pre-passivate following post-activate
this.notifier.prePassivate();
verify(prePassivateNotifier1).accept(session);
verify(prePassivateNotifier2).accept(session);
verify(postActivateNotifier1, never()).accept(session);
verify(postActivateNotifier2, never()).accept(session);
reset(prePassivateNotifier1, prePassivateNotifier2);
// verify subsequent pre-passivate is a no-op
this.notifier.prePassivate();
verify(prePassivateNotifier1, never()).accept(session);
verify(prePassivateNotifier2, never()).accept(session);
verify(postActivateNotifier1, never()).accept(session);
verify(postActivateNotifier2, never()).accept(session);
// verify post-activate following pre-passivate
this.notifier.postActivate();
verify(prePassivateNotifier1, never()).accept(session);
verify(prePassivateNotifier2, never()).accept(session);
verify(postActivateNotifier1).accept(session);
verify(postActivateNotifier2).accept(session);
}
@Test
public void postActivate() {
Map<String, Listener> listeners = new TreeMap<>();
listeners.put("listener1", this.listener1);
listeners.put("listener2", this.listener2);
when(this.provider.getHttpSessionActivationListenerClass()).thenReturn(Listener.class);
when(this.filter.getAttributes(Listener.class)).thenReturn(listeners);
Session session = mock(Session.class);
Consumer<Session> notifier1 = mock(Consumer.class);
Consumer<Session> notifier2 = mock(Consumer.class);
when(this.provider.createHttpSession(same(this.session), same(this.context))).thenReturn(session);
when(this.provider.postActivateNotifier(same(this.listener1))).thenReturn(notifier1);
when(this.provider.postActivateNotifier(same(this.listener2))).thenReturn(notifier2);
this.notifier.postActivate();
verify(this.provider, never()).prePassivateNotifier(this.listener1);
verify(this.provider, never()).prePassivateNotifier(this.listener2);
verify(notifier1).accept(session);
verify(notifier2).accept(session);
}
}
| 6,927
| 41.503067
| 152
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/SessionCreationMetaDataEntryMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.marshalling.MarshallingTester;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
/**
* Unit test for {@link SessionCreationMetaDataEntryExternalizer}.
* @author Paul Ferraro
*/
public class SessionCreationMetaDataEntryMarshallerTestCase {
@Test
public void test() throws IOException {
MarshallingTester<SessionCreationMetaDataEntry<Object>> tester = ProtoStreamTesterFactory.INSTANCE.createTester();
SessionCreationMetaData metaData = new SimpleSessionCreationMetaData(Instant.now());
SessionCreationMetaDataEntry<Object> entry = new SessionCreationMetaDataEntry<>(metaData);
// Default max-inactive-interval
metaData.setTimeout(Duration.ofMinutes(30));
tester.test(entry, SessionCreationMetaDataEntryMarshallerTestCase::assertEquals);
// Custom max-inactive-interval
metaData.setTimeout(Duration.ofMinutes(10));
tester.test(entry, SessionCreationMetaDataEntryMarshallerTestCase::assertEquals);
}
static void assertEquals(SessionCreationMetaDataEntry<Object> entry1, SessionCreationMetaDataEntry<Object> entry2) {
// Compare only to millisecond precision
Assert.assertEquals(entry1.getMetaData().getCreationTime().toEpochMilli(), entry2.getMetaData().getCreationTime().toEpochMilli());
Assert.assertEquals(entry1.getMetaData().getTimeout(), entry2.getMetaData().getTimeout());
}
}
| 2,671
| 42.096774
| 138
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/CompositeSessionMetaDataTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.time.Duration;
import java.time.Instant;
import org.junit.Test;
import org.wildfly.clustering.web.session.SessionMetaData;
public class CompositeSessionMetaDataTestCase {
private final SessionCreationMetaData creationMetaData = mock(SessionCreationMetaData.class);
private final SessionAccessMetaData accessMetaData = mock(SessionAccessMetaData.class);
private final SessionMetaData metaData = new CompositeSessionMetaData(this.creationMetaData, this.accessMetaData);
@Test
public void isNew() {
when(this.creationMetaData.isNew()).thenReturn(true);
assertTrue(this.metaData.isNew());
when(this.creationMetaData.isNew()).thenReturn(false);
assertFalse(this.metaData.isNew());
}
@Test
public void isExpired() {
when(this.creationMetaData.getCreationTime()).thenReturn(Instant.now().minus(Duration.ofMinutes(10L)));
when(this.creationMetaData.getTimeout()).thenReturn(Duration.ofMinutes(10L));
when(this.accessMetaData.getSinceCreationDuration()).thenReturn(Duration.ofMinutes(5L));
when(this.accessMetaData.getLastAccessDuration()).thenReturn(Duration.ofSeconds(1));
assertFalse(this.metaData.isExpired());
when(this.creationMetaData.getTimeout()).thenReturn(Duration.ofMinutes(5L).minus(Duration.ofSeconds(1, 1)));
assertTrue(this.metaData.isExpired());
// Timeout of 0 means never expire
when(this.creationMetaData.getTimeout()).thenReturn(Duration.ZERO);
assertFalse(this.metaData.isExpired());
}
@Test
public void getCreationTime() {
Instant expected = Instant.now();
when(this.creationMetaData.getCreationTime()).thenReturn(expected);
Instant result = this.metaData.getCreationTime();
assertSame(expected, result);
}
@Test
public void getLastAccessStartTime() {
Instant now = Instant.now();
Duration sinceCreation = Duration.ofSeconds(10L);
when(this.creationMetaData.getCreationTime()).thenReturn(now.minus(sinceCreation));
when(this.accessMetaData.getSinceCreationDuration()).thenReturn(sinceCreation);
Instant result = this.metaData.getLastAccessStartTime();
assertEquals(now, result);
}
@Test
public void getLastAccessTime() {
Instant now = Instant.now();
Duration sinceCreation = Duration.ofSeconds(10L);
Duration lastAccess = Duration.ofSeconds(1L);
when(this.creationMetaData.getCreationTime()).thenReturn(now.minus(sinceCreation).minus(lastAccess));
when(this.accessMetaData.getSinceCreationDuration()).thenReturn(sinceCreation);
when(this.accessMetaData.getLastAccessDuration()).thenReturn(lastAccess);
Instant result = this.metaData.getLastAccessTime();
assertEquals(now, result);
}
@Test
public void getMaxInactiveInterval() {
Duration expected = Duration.ofMinutes(30L);
when(this.creationMetaData.getTimeout()).thenReturn(expected);
Duration result = this.metaData.getTimeout();
assertSame(expected, result);
}
@Test
public void setLastAccessedTime() {
// New session
Instant endTime = Instant.now();
Duration lastAccess = Duration.ofSeconds(1L);
Instant startTime = endTime.minus(lastAccess);
when(this.creationMetaData.getCreationTime()).thenReturn(startTime);
this.metaData.setLastAccess(startTime, endTime);
verify(this.accessMetaData).setLastAccessDuration(Duration.ZERO, lastAccess);
reset(this.creationMetaData, this.accessMetaData);
// Existing session
Duration sinceCreated = Duration.ofSeconds(10L);
when(this.creationMetaData.getCreationTime()).thenReturn(startTime.minus(sinceCreated));
this.metaData.setLastAccess(startTime, endTime);
verify(this.accessMetaData).setLastAccessDuration(sinceCreated, lastAccess);
}
@Test
public void setMaxInactiveInterval() {
Duration duration = Duration.ZERO;
this.metaData.setMaxInactiveInterval(duration);
verify(this.creationMetaData).setTimeout(duration);
}
}
| 5,618
| 34.339623
| 118
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/ImmutableSessionAttributesFilterTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
/**
* Unit test for {@link ImmutableSessionAttributesFilter}.
* @author Paul Ferraro
*/
public class ImmutableSessionAttributesFilterTestCase {
@Test
public void getListeners() {
ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
SessionAttributesFilter filter = new ImmutableSessionAttributesFilter(attributes);
Object object1 = new Object();
Object object2 = new Object();
Runnable listener1 = mock(Runnable.class);
Runnable listener2 = mock(Runnable.class);
when(attributes.getAttributeNames()).thenReturn(new HashSet<>(Arrays.asList("non-listener1", "non-listener2", "listener1", "listener2")));
when(attributes.getAttribute("non-listener1")).thenReturn(object1);
when(attributes.getAttribute("non-listener2")).thenReturn(object2);
when(attributes.getAttribute("listener1")).thenReturn(listener1);
when(attributes.getAttribute("listener2")).thenReturn(listener2);
Map<String, Runnable> result = filter.getAttributes(Runnable.class);
Assert.assertEquals(2, result.size());
Assert.assertTrue(result.toString(), result.containsKey("listener1"));
Assert.assertTrue(result.toString(), result.containsKey("listener2"));
Assert.assertSame(listener1, result.get("listener1"));
Assert.assertSame(listener2, result.get("listener2"));
}
}
| 2,722
| 40.892308
| 146
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/CompositeSessionFactoryTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.wildfly.clustering.web.LocalContextFactory;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
import org.wildfly.clustering.web.session.Session;
/**
* Unit test for {@link CompositeSessionFactory}.
*
* @author Paul Ferraro
*/
public class CompositeSessionFactoryTestCase {
private final SessionMetaDataFactory<CompositeSessionMetaDataEntry<Object>> metaDataFactory = mock(SessionMetaDataFactory.class);
private final SessionAttributesFactory<Object, Object> attributesFactory = mock(SessionAttributesFactory.class);
private final LocalContextFactory<Object> localContextFactory = mock(LocalContextFactory.class);
private final SessionFactory<Object, CompositeSessionMetaDataEntry<Object>, Object, Object> factory = new CompositeSessionFactory<>(this.metaDataFactory, this.attributesFactory, this.localContextFactory);
@Test
public void createValue() {
SessionCreationMetaData creationMetaData = mock(SessionCreationMetaData.class);
SessionAccessMetaData accessMetaData = mock(SessionAccessMetaData.class);
AtomicReference<Object> localContext = new AtomicReference<>();
CompositeSessionMetaDataEntry<Object> metaData = new CompositeSessionMetaDataEntry<>(creationMetaData, accessMetaData, localContext);
Object attributes = new Object();
String id = "id";
when(this.metaDataFactory.createValue(id, null)).thenReturn(metaData);
when(this.attributesFactory.createValue(id, null)).thenReturn(attributes);
Map.Entry<CompositeSessionMetaDataEntry<Object>, Object> result = this.factory.createValue(id, null);
assertNotNull(result);
assertSame(metaData, result.getKey());
assertSame(attributes, result.getValue());
}
@Test
public void findValue() {
String missingMetaDataSessionId = "no-meta-data";
String missingAttributesSessionId = "no-attributes";
String existingSessionId = "existing";
SessionCreationMetaData creationMetaData = mock(SessionCreationMetaData.class);
SessionAccessMetaData accessMetaData = mock(SessionAccessMetaData.class);
AtomicReference<Object> localContext = new AtomicReference<>();
CompositeSessionMetaDataEntry<Object> metaData = new CompositeSessionMetaDataEntry<>(creationMetaData, accessMetaData, localContext);
Object attributes = new Object();
when(this.metaDataFactory.findValue(missingMetaDataSessionId)).thenReturn(null);
when(this.metaDataFactory.findValue(missingAttributesSessionId)).thenReturn(metaData);
when(this.metaDataFactory.findValue(existingSessionId)).thenReturn(metaData);
when(this.attributesFactory.findValue(missingAttributesSessionId)).thenReturn(null);
when(this.attributesFactory.findValue(existingSessionId)).thenReturn(attributes);
Map.Entry<CompositeSessionMetaDataEntry<Object>, Object> missingMetaDataResult = this.factory.findValue(missingMetaDataSessionId);
Map.Entry<CompositeSessionMetaDataEntry<Object>, Object> missingAttributesResult = this.factory.findValue(missingAttributesSessionId);
Map.Entry<CompositeSessionMetaDataEntry<Object>, Object> existingSessionResult = this.factory.findValue(existingSessionId);
assertNull(missingMetaDataResult);
assertNull(missingAttributesResult);
assertNotNull(existingSessionResult);
assertSame(metaData, existingSessionResult.getKey());
assertSame(attributes, existingSessionResult.getValue());
}
@SuppressWarnings("unchecked")
@Test
public void remove() {
String id = "id";
when(this.metaDataFactory.remove(id)).thenReturn(false);
boolean removed = this.factory.remove(id);
verify(this.attributesFactory).remove(id);
assertFalse(removed);
reset(this.attributesFactory);
when(this.metaDataFactory.remove(id)).thenReturn(true);
removed = this.factory.remove(id);
verify(this.attributesFactory).remove(id);
assertTrue(removed);
}
@Test
public void getMetaDataFactory() {
assertSame(this.metaDataFactory, this.factory.getMetaDataFactory());
}
@Test
public void createSession() {
Map.Entry<CompositeSessionMetaDataEntry<Object>, Object> entry = mock(Map.Entry.class);
SessionCreationMetaData creationMetaData = mock(SessionCreationMetaData.class);
SessionAccessMetaData accessMetaData = mock(SessionAccessMetaData.class);
Object localContext = new Object();
CompositeSessionMetaDataEntry<Object> metaDataValue = new CompositeSessionMetaDataEntry<>(creationMetaData, accessMetaData, new AtomicReference<>(localContext));
Object attributesValue = new Object();
InvalidatableSessionMetaData metaData = mock(InvalidatableSessionMetaData.class);
SessionAttributes attributes = mock(SessionAttributes.class);
Object context = new Object();
String id = "id";
when(entry.getKey()).thenReturn(metaDataValue);
when(entry.getValue()).thenReturn(attributesValue);
when(this.metaDataFactory.createSessionMetaData(id, metaDataValue)).thenReturn(metaData);
when(this.attributesFactory.createSessionAttributes(same(id), same(attributesValue), same(metaData), same(context))).thenReturn(attributes);
Session<Object> result = this.factory.createSession(id, entry, context);
assertSame(id, result.getId());
assertSame(metaData, result.getMetaData());
assertSame(attributes, result.getAttributes());
assertSame(localContext, result.getLocalContext());
}
@Test
public void createImmutableSession() {
Map.Entry<CompositeSessionMetaDataEntry<Object>, Object> entry = mock(Map.Entry.class);
SessionCreationMetaData creationMetaData = mock(SessionCreationMetaData.class);
SessionAccessMetaData accessMetaData = mock(SessionAccessMetaData.class);
CompositeSessionMetaDataEntry<Object> metaDataValue = new CompositeSessionMetaDataEntry<>(creationMetaData, accessMetaData, null);
Object attributesValue = new Object();
ImmutableSessionMetaData metaData = mock(ImmutableSessionMetaData.class);
ImmutableSessionAttributes attributes = mock(ImmutableSessionAttributes.class);
String id = "id";
when(entry.getKey()).thenReturn(metaDataValue);
when(entry.getValue()).thenReturn(attributesValue);
when(this.metaDataFactory.createImmutableSessionMetaData(id, metaDataValue)).thenReturn(metaData);
when(this.attributesFactory.createImmutableSessionAttributes(id, attributesValue)).thenReturn(attributes);
ImmutableSession result = this.factory.createImmutableSession(id, entry);
assertSame(id, result.getId());
assertSame(metaData, result.getMetaData());
assertSame(attributes, result.getAttributes());
}
@Test
public void close() {
this.factory.close();
verify(this.metaDataFactory).close();
verify(this.attributesFactory).close();
}
}
| 8,497
| 45.437158
| 208
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/SessionAccessMetaDataMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.io.IOException;
import java.time.Duration;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.marshalling.MarshallingTester;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
/**
* Unit test for {@link SessionAccessMetaDataExternalizer}.
* @author Paul Ferraro
*/
public class SessionAccessMetaDataMarshallerTestCase {
@Test
public void test() throws IOException {
MarshallingTester<SimpleSessionAccessMetaData> tester = ProtoStreamTesterFactory.INSTANCE.createTester();
SimpleSessionAccessMetaData metaData = new SimpleSessionAccessMetaData();
// New session
metaData.setLastAccessDuration(Duration.ZERO, Duration.ofNanos(100_000_000));
tester.test(metaData, SessionAccessMetaDataMarshallerTestCase::assertEquals);
// Existing session, sub-second response time
metaData.setLastAccessDuration(Duration.ofSeconds(60 * 5), Duration.ofNanos(100_000_000));
tester.test(metaData, SessionAccessMetaDataMarshallerTestCase::assertEquals);
// Existing session, +1 second response time
metaData.setLastAccessDuration(Duration.ofSeconds(60 * 5), Duration.ofSeconds(1, 100_000_000));
tester.test(metaData, SessionAccessMetaDataMarshallerTestCase::assertEquals);
}
static void assertEquals(SimpleSessionAccessMetaData metaData1, SimpleSessionAccessMetaData metaData2) {
Assert.assertEquals(metaData1.getSinceCreationDuration(), metaData2.getSinceCreationDuration());
Assert.assertEquals(metaData1.getLastAccessDuration(), metaData2.getLastAccessDuration());
}
}
| 2,728
| 42.31746
| 113
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapFunctionMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.io.IOException;
import java.util.UUID;
import org.wildfly.clustering.ee.cache.function.MapPutFunction;
import org.wildfly.clustering.ee.cache.function.MapRemoveFunction;
import org.wildfly.clustering.marshalling.Tester;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Paul Ferraro
*/
public class SessionAttributeMapFunctionMarshallerTestCase {
@Test
public void testMapPutFunction() throws IOException {
Tester<MapPutFunction<String, UUID>> tester = ProtoStreamTesterFactory.INSTANCE.createTester();
tester.test(new ConcurrentSessionAttributeMapPutFunction("foo", UUID.randomUUID()), SessionAttributeMapFunctionMarshallerTestCase::assertEquals);
tester.test(new CopyOnWriteSessionAttributeMapPutFunction("foo", UUID.randomUUID()), SessionAttributeMapFunctionMarshallerTestCase::assertEquals);
}
@Test
public void testMapRemoveFunction() throws IOException {
Tester<MapRemoveFunction<String, UUID>> tester = ProtoStreamTesterFactory.INSTANCE.createTester();
tester.test(new ConcurrentSessionAttributeMapRemoveFunction("foo"), SessionAttributeMapFunctionMarshallerTestCase::assertEquals);
tester.test(new CopyOnWriteSessionAttributeMapRemoveFunction("foo"), SessionAttributeMapFunctionMarshallerTestCase::assertEquals);
}
static <K, V> void assertEquals(MapPutFunction<K, V> function1, MapPutFunction<K, V> function2) {
Assert.assertEquals(function1.getOperand(), function2.getOperand());
}
static <K, V> void assertEquals(MapRemoveFunction<K, V> function1, MapRemoveFunction<K, V> function2) {
Assert.assertEquals(function1.getOperand(), function2.getOperand());
}
}
| 2,866
| 44.507937
| 154
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/routing/NullRouteLocatorTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.routing;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.web.routing.RouteLocator;
/**
* @author Paul Ferraro
*/
public class NullRouteLocatorTestCase {
@Test
public void test() {
RouteLocator locator = new NullRouteLocator();
Assert.assertNull(locator.locate("abc123"));
}
}
| 1,405
| 33.292683
| 70
|
java
|
null |
wildfly-main/clustering/web/cache/src/test/java/org/wildfly/clustering/web/cache/routing/LocalRouteLocatorTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.routing;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.web.routing.RouteLocator;
/**
* @author Paul Ferraro
*/
public class LocalRouteLocatorTestCase {
@Test
public void test() {
String route = "route";
RouteLocator locator = new LocalRouteLocator(route);
String result = locator.locate("abc123");
Assert.assertSame(route, result);
}
}
| 1,482
| 34.309524
| 70
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/SessionIdentifierMarshaller.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import org.infinispan.protostream.descriptors.WireType;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter;
import org.wildfly.clustering.marshalling.protostream.ScalarMarshaller;
import org.wildfly.clustering.marshalling.spi.Marshaller;
import org.wildfly.clustering.web.IdentifierMarshallerProvider;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* Scalar marshaller for a session identifier.
* @author Paul Ferraro
*/
public enum SessionIdentifierMarshaller implements ScalarMarshaller<String> {
INSTANCE;
private final Marshaller<String, ByteBuffer> marshaller = loadMarshaller();
private static Marshaller<String, ByteBuffer> loadMarshaller() {
Iterator<IdentifierMarshallerProvider> providers = load(IdentifierMarshallerProvider.class).iterator();
if (!providers.hasNext()) {
throw new ServiceConfigurationError(IdentifierMarshallerProvider.class.getName());
}
return providers.next().getMarshaller();
}
private static <T> Iterable<T> load(Class<T> providerClass) {
PrivilegedAction<Iterable<T>> action = new PrivilegedAction<>() {
@Override
public Iterable<T> run() {
return ServiceLoader.load(providerClass, providerClass.getClassLoader());
}
};
return WildFlySecurityManager.doUnchecked(action);
}
@Override
public String readFrom(ProtoStreamReader reader) throws IOException {
return this.marshaller.read(reader.readByteBuffer());
}
@Override
public void writeTo(ProtoStreamWriter writer, String id) throws IOException {
ByteBuffer buffer = this.marshaller.write(id);
int offset = buffer.arrayOffset();
int length = buffer.limit() - offset;
writer.writeVarint32(length);
writer.writeRawBytes(buffer.array(), offset, length);
}
@Override
public Class<? extends String> getJavaClass() {
return String.class;
}
@Override
public WireType getWireType() {
return WireType.LENGTH_DELIMITED;
}
}
| 3,442
| 36.835165
| 111
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/SessionKeyMarshaller.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache;
import java.io.IOException;
import org.wildfly.clustering.ee.Key;
import org.wildfly.clustering.marshalling.protostream.FunctionalScalarMarshaller;
import org.wildfly.common.function.ExceptionFunction;
/**
* Generic marshaller for cache keys containing session identifiers.
* @author Paul Ferraro
*/
public class SessionKeyMarshaller<K extends Key<String>> extends FunctionalScalarMarshaller<K, String> {
public SessionKeyMarshaller(Class<K> targetClass, ExceptionFunction<String, K, IOException> resolver) {
super(targetClass, SessionIdentifierMarshaller.INSTANCE, Key::getId, resolver);
}
}
| 1,682
| 40.04878
| 107
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/SSOSerializationContextInitializer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer;
import org.wildfly.clustering.marshalling.protostream.FunctionalScalarMarshaller;
import org.wildfly.clustering.marshalling.protostream.Scalar;
/**
* @author Paul Ferraro
*/
@MetaInfServices(SerializationContextInitializer.class)
public class SSOSerializationContextInitializer extends AbstractSerializationContextInitializer {
@Override
public void registerMarshallers(SerializationContext context) {
context.registerMarshaller(new FunctionalScalarMarshaller<>(AuthenticationEntry.class, Scalar.ANY, AuthenticationEntry::getAuthentication, AuthenticationEntry::new));
}
}
| 1,922
| 43.72093
| 174
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/SSOFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso;
import java.util.Map;
import org.wildfly.clustering.ee.Creator;
import org.wildfly.clustering.ee.Locator;
import org.wildfly.clustering.ee.Remover;
import org.wildfly.clustering.web.sso.SSO;
/**
* Creates an {@link SSO} from its cache storage value.
* @author Paul Ferraro
* @param <V> the cache value type
*/
public interface SSOFactory<AV, SV, A, D, S, L> extends Creator<String, Map.Entry<AV, SV>, A>, Locator<String, Map.Entry<AV, SV>>, Remover<String> {
SSO<A, D, S, L> createSSO(String id, Map.Entry<AV, SV> value);
SessionsFactory<SV, D, S> getSessionsFactory();
}
| 1,657
| 39.439024
| 148
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/CompositeSSOManager.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso;
import java.util.Map;
import java.util.function.Supplier;
import org.wildfly.clustering.ee.Batcher;
import org.wildfly.clustering.ee.cache.IdentifierFactory;
import org.wildfly.clustering.ee.cache.tx.TransactionBatch;
import org.wildfly.clustering.web.sso.SSO;
import org.wildfly.clustering.web.sso.SSOManager;
import org.wildfly.clustering.web.sso.Sessions;
public class CompositeSSOManager<AV, SV, A, D, S, L> implements SSOManager<A, D, S, L, TransactionBatch> {
private final SSOFactory<AV, SV, A, D, S, L> factory;
private final Batcher<TransactionBatch> batcher;
private final IdentifierFactory<String> identifierFactory;
public CompositeSSOManager(SSOFactory<AV, SV, A, D, S, L> factory, IdentifierFactory<String> identifierFactory, Batcher<TransactionBatch> batcher) {
this.factory = factory;
this.batcher = batcher;
this.identifierFactory = identifierFactory;
}
@Override
public SSO<A, D, S, L> createSSO(String ssoId, A authentication) {
Map.Entry<AV, SV> value = this.factory.createValue(ssoId, authentication);
return this.factory.createSSO(ssoId, value);
}
@Override
public SSO<A, D, S, L> findSSO(String ssoId) {
Map.Entry<AV, SV> value = this.factory.findValue(ssoId);
return (value != null) ? this.factory.createSSO(ssoId, value) : null;
}
@Override
public Sessions<D, S> findSessionsContaining(S session) {
SessionsFactory<SV, D, S> factory = this.factory.getSessionsFactory();
Map.Entry<String, SV> entry = factory.findEntryContaining(session);
return (entry != null) ? factory.createSessions(entry.getKey(), entry.getValue()) : null;
}
@Override
public Batcher<TransactionBatch> getBatcher() {
return this.batcher;
}
@Override
public Supplier<String> getIdentifierFactory() {
return this.identifierFactory;
}
@Override
public void start() {
this.identifierFactory.start();
}
@Override
public void stop() {
this.identifierFactory.stop();
}
}
| 3,157
| 36.152941
| 152
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/SessionsFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso;
import java.util.Map;
import org.wildfly.clustering.ee.Creator;
import org.wildfly.clustering.ee.Locator;
import org.wildfly.clustering.ee.Remover;
import org.wildfly.clustering.web.sso.Sessions;
public interface SessionsFactory<V, D, S> extends Creator<String, V, Void>, Locator<String, V>, Remover<String> {
Sessions<D, S> createSessions(String ssoId, V value);
Map.Entry<String, V> findEntryContaining(S session);
}
| 1,501
| 39.594595
| 113
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/CompositeSSO.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso;
import java.util.concurrent.atomic.AtomicReference;
import org.wildfly.clustering.ee.Remover;
import org.wildfly.clustering.web.LocalContextFactory;
import org.wildfly.clustering.web.sso.SSO;
import org.wildfly.clustering.web.sso.Sessions;
public class CompositeSSO<A, D, S, L> implements SSO<A, D, S, L> {
private final String id;
private final A authentication;
private final Sessions<D, S> sessions;
private final AtomicReference<L> localContext;
private final LocalContextFactory<L> localContextFactory;
private final Remover<String> remover;
public CompositeSSO(String id, A authentication, Sessions<D, S> sessions, AtomicReference<L> localContext, LocalContextFactory<L> localContextFactory, Remover<String> remover) {
this.id = id;
this.authentication = authentication;
this.sessions = sessions;
this.localContext = localContext;
this.localContextFactory = localContextFactory;
this.remover = remover;
}
@Override
public String getId() {
return this.id;
}
@Override
public A getAuthentication() {
return this.authentication;
}
@Override
public Sessions<D, S> getSessions() {
return this.sessions;
}
@Override
public void invalidate() {
this.remover.remove(this.id);
}
@Override
public L getLocalContext() {
if (this.localContextFactory == null) return null;
L localContext = this.localContext.get();
if (localContext == null) {
localContext = this.localContextFactory.createLocalContext();
if (!this.localContext.compareAndSet(null, localContext)) {
return this.localContext.get();
}
}
return localContext;
}
}
| 2,860
| 34.320988
| 181
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/AuthenticationEntry.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso;
import java.util.concurrent.atomic.AtomicReference;
/**
* Cache entry that store authentication data plus any local context.
* @author Paul Ferraro
* @param <A> the identity type
* @param <L> the local context type
*/
public class AuthenticationEntry<V, L> {
private final V authentication;
private final AtomicReference<L> localContext = new AtomicReference<>();
public AuthenticationEntry(V authentication) {
this.authentication = authentication;
}
public V getAuthentication() {
return this.authentication;
}
public AtomicReference<L> getLocalContext() {
return this.localContext;
}
}
| 1,724
| 34.204082
| 76
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/coarse/SessionFilter.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso.coarse;
import java.util.Map;
import java.util.function.Predicate;
/**
* Selects SSO sessions entries containing the specified session.
* @author Paul Ferraro
* @param <K> the cache key type
* @param <D> the deployment type
* @param <S> the session type
*/
public class SessionFilter<K, D, S> implements Predicate<Map.Entry<K, Map<D, S>>> {
private final S session;
public SessionFilter(S session) {
this.session = session;
}
public S getSession() {
return this.session;
}
@Override
public boolean test(Map.Entry<K, Map<D, S>> entry) {
return entry.getValue().values().contains(this.session);
}
}
| 1,734
| 32.365385
| 83
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/coarse/CoarseSessions.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso.coarse;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.wildfly.clustering.ee.Mutator;
import org.wildfly.clustering.web.sso.Sessions;
public class CoarseSessions<D, S> implements Sessions<D, S> {
private final Map<D, S> sessions;
private final Mutator mutator;
public CoarseSessions(Map<D, S> sessions, Mutator mutator) {
this.sessions = sessions;
this.mutator = mutator;
}
@Override
public Set<D> getDeployments() {
return Collections.unmodifiableSet(this.sessions.keySet());
}
@Override
public S getSession(D deployment) {
return this.sessions.get(deployment);
}
@Override
public S removeSession(D deployment) {
S removed = this.sessions.remove(deployment);
if (removed != null) {
this.mutator.mutate();
}
return removed;
}
@Override
public boolean addSession(D deployment, S session) {
boolean added = this.sessions.put(deployment, session) == null;
if (added) {
this.mutator.mutate();
}
return added;
}
}
| 2,208
| 31.014493
| 71
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/sso/coarse/CoarseSSOSerializationContextInitializer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.sso.coarse;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer;
import org.wildfly.clustering.marshalling.protostream.FunctionalScalarMarshaller;
import org.wildfly.clustering.marshalling.protostream.Scalar;
/**
* @author Paul Ferraro
*/
@MetaInfServices(SerializationContextInitializer.class)
public class CoarseSSOSerializationContextInitializer extends AbstractSerializationContextInitializer {
@Override
public void registerMarshallers(SerializationContext context) {
context.registerMarshaller(new FunctionalScalarMarshaller<>(SessionFilter.class, Scalar.ANY, SessionFilter::getSession, SessionFilter::new));
}
}
| 1,910
| 43.44186
| 149
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/logging/Logger.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.logging;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
/**
* @author Paul Ferraro
*/
@MessageLogger(projectCode = "WFLYCLWEB", length = 4)
public interface Logger extends BasicLogger {
String ROOT_LOGGER_CATEGORY = "org.wildfly.clustering.web.cache";
Logger ROOT_LOGGER = org.jboss.logging.Logger.getMessageLogger(Logger.class, ROOT_LOGGER_CATEGORY);
@Message(id = 1, value = "Session %s is not valid")
IllegalStateException invalidSession(String sessionId);
}
| 1,638
| 38.97561
| 103
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ConcurrentSessionManager.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.wildfly.clustering.ee.Batch;
import org.wildfly.clustering.ee.Batcher;
import org.wildfly.clustering.ee.Manager;
import org.wildfly.clustering.ee.ManagerFactory;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.Session;
import org.wildfly.clustering.web.session.SessionAttributes;
import org.wildfly.clustering.web.session.SessionManager;
import org.wildfly.clustering.web.session.SessionMetaData;
import org.wildfly.common.function.Functions;
/**
* A concurrent session manager, that can share session references across concurrent threads.
* @author Paul Ferraro
*/
public class ConcurrentSessionManager<L, B extends Batch> implements SessionManager<L, B> {
private final SessionManager<L, B> manager;
private final Manager<String, Session<L>> concurrentManager;
public ConcurrentSessionManager(SessionManager<L, B> manager, ManagerFactory<String, Session<L>> concurrentManagerFactory) {
this.manager = manager;
this.concurrentManager = concurrentManagerFactory.apply(Functions.discardingConsumer(), new Consumer<Session<L>>() {
@Override
public void accept(Session<L> session) {
((ConcurrentSession<L>) session).closeSession();
}
});
}
@Override
public Session<L> findSession(String id) {
SessionManager<L, B> manager = this.manager;
Function<Runnable, Session<L>> factory = new Function<>() {
@Override
public ConcurrentSession<L> apply(Runnable closeTask) {
Session<L> session = manager.findSession(id);
return (session != null) ? new ConcurrentSession<>(session, closeTask) : null;
}
};
@SuppressWarnings("resource")
Session<L> session = this.concurrentManager.apply(id, factory);
// If session was invalidated by a concurrent thread, return null instead of an invalid session
// This will reduce the likelihood that a duplicate invalidation request (e.g. from a double-clicked logout) results in an ISE
if (session != null && !session.isValid()) {
session.close();
return null;
}
return session;
}
@Override
public Session<L> createSession(String id) {
SessionManager<L, B> manager = this.manager;
Function<Runnable, Session<L>> factory = new Function<>() {
@Override
public ConcurrentSession<L> apply(Runnable closeTask) {
Session<L> session = manager.createSession(id);
return new ConcurrentSession<>(session, closeTask);
}
};
return this.concurrentManager.apply(id, factory);
}
@Override
public Supplier<String> getIdentifierFactory() {
return this.manager.getIdentifierFactory();
}
@Override
public void start() {
this.manager.start();
}
@Override
public void stop() {
this.manager.stop();
}
@Override
public long getActiveSessionCount() {
return this.manager.getActiveSessionCount();
}
@Override
public Batcher<B> getBatcher() {
return this.manager.getBatcher();
}
@Override
public Set<String> getActiveSessions() {
return this.manager.getActiveSessions();
}
@Override
public Set<String> getLocalSessions() {
return this.manager.getLocalSessions();
}
@Override
public ImmutableSession readSession(String id) {
return this.manager.readSession(id);
}
@Override
public Duration getStopTimeout() {
return this.manager.getStopTimeout();
}
private static class ConcurrentSession<L> implements Session<L> {
private final Session<L> session;
private final Runnable closeTask;
ConcurrentSession(Session<L> session, Runnable closeTask) {
this.session = session;
this.closeTask = closeTask;
}
void closeSession() {
this.session.close();
}
@Override
public String getId() {
return this.session.getId();
}
@Override
public boolean isValid() {
return this.session.isValid();
}
@Override
public SessionMetaData getMetaData() {
return this.session.getMetaData();
}
@Override
public SessionAttributes getAttributes() {
return this.session.getAttributes();
}
@Override
public void invalidate() {
this.session.invalidate();
this.closeTask.run();
}
@Override
public void close() {
this.closeTask.run();
}
@Override
public L getLocalContext() {
return this.session.getLocalContext();
}
}
}
| 6,128
| 31.257895
| 134
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleImmutableSession.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
/**
* An immutable "snapshot" of a session which can be accessed outside the scope of a transaction.
* @author Paul Ferraro
*/
public class SimpleImmutableSession implements ImmutableSession {
private final String id;
private final boolean valid;
private final ImmutableSessionMetaData metaData;
private final ImmutableSessionAttributes attributes;
public SimpleImmutableSession(ImmutableSession session) {
this.id = session.getId();
this.valid = session.isValid();
this.metaData = new SimpleImmutableSessionMetaData(session.getMetaData());
this.attributes = new SimpleImmutableSessionAttributes(session.getAttributes());
}
@Override
public String getId() {
return this.id;
}
@Override
public boolean isValid() {
return this.valid;
}
@Override
public ImmutableSessionMetaData getMetaData() {
return this.metaData;
}
@Override
public ImmutableSessionAttributes getAttributes() {
return this.attributes;
}
}
| 2,324
| 34.227273
| 97
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleSessionCreationMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author Paul Ferraro
*/
public class SimpleSessionCreationMetaData implements SessionCreationMetaData {
private final Instant creationTime;
private volatile Duration timeout = Duration.ZERO;
private volatile boolean newSession;
private final AtomicBoolean valid = new AtomicBoolean(true);
public SimpleSessionCreationMetaData() {
// Only retain millisecond precision
this.creationTime = Instant.now().truncatedTo(ChronoUnit.MILLIS);
this.newSession = true;
}
public SimpleSessionCreationMetaData(Instant creationTime) {
this.creationTime = creationTime;
this.newSession = false;
}
@Override
public boolean isNew() {
return this.newSession;
}
@Override
public Instant getCreationTime() {
return this.creationTime;
}
@Override
public Duration getTimeout() {
return this.timeout;
}
@Override
public void setTimeout(Duration timeout) {
this.timeout = timeout;
}
@Override
public boolean isValid() {
return this.valid.get();
}
@Override
public boolean invalidate() {
return this.valid.compareAndSet(true, false);
}
@Override
public void close() {
this.newSession = false;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(this.getClass().getSimpleName()).append(" { ");
builder.append("created = ").append(this.creationTime);
builder.append(", timeout = ").append(this.timeout);
return builder.append(" }").toString();
}
}
| 2,841
| 29.234043
| 97
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ImmutableSessionAccessMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
/**
* Immutable view of the volatile aspects of a session's meta-data.
* @author Paul Ferraro
*/
public interface ImmutableSessionAccessMetaData {
/**
* Returns the duration of time between session creation and the start of the last access.
* @return the duration of time between session creation and the start of the last access.
*/
Duration getSinceCreationDuration();
/**
* Returns the duration of time between the start and of the last access.
* @return the duration of time between the start and of the last access.
*/
Duration getLastAccessDuration();
}
| 1,713
| 37.954545
| 94
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/CompositeSession.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.concurrent.atomic.AtomicReference;
import org.wildfly.clustering.ee.Remover;
import org.wildfly.clustering.web.LocalContextFactory;
import org.wildfly.clustering.web.session.Session;
import org.wildfly.clustering.web.session.SessionMetaData;
/**
* Generic session implementation - independent of cache mapping strategy.
* @author Paul Ferraro
*/
public class CompositeSession<L> extends CompositeImmutableSession implements Session<L> {
private final InvalidatableSessionMetaData metaData;
private final SessionAttributes attributes;
private final AtomicReference<L> localContext;
private final LocalContextFactory<L> localContextFactory;
private final Remover<String> remover;
public CompositeSession(String id, InvalidatableSessionMetaData metaData, SessionAttributes attributes, AtomicReference<L> localContext, LocalContextFactory<L> localContextFactory, Remover<String> remover) {
super(id, metaData, attributes);
this.metaData = metaData;
this.attributes = attributes;
this.localContext = localContext;
this.localContextFactory = localContextFactory;
this.remover = remover;
}
@Override
public SessionAttributes getAttributes() {
return this.attributes;
}
@Override
public boolean isValid() {
return this.metaData.isValid();
}
@Override
public void invalidate() {
if (this.metaData.invalidate()) {
this.remover.remove(this.getId());
}
}
@Override
public SessionMetaData getMetaData() {
return this.metaData;
}
@Override
public void close() {
if (this.metaData.isValid()) {
this.attributes.close();
this.metaData.close();
}
}
@Override
public L getLocalContext() {
if (this.localContextFactory == null) return null;
L localContext = this.localContext.get();
if (localContext == null) {
localContext = this.localContextFactory.createLocalContext();
if (!this.localContext.compareAndSet(null, localContext)) {
return this.localContext.get();
}
}
return localContext;
}
}
| 3,310
| 33.852632
| 211
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/DelegatingSessionManagerConfiguration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.SessionManagerConfiguration;
/**
* A {@link SessionManagerConfiguration} implementation that delegates to another {@link SessionManagerConfiguration}.
* @author Paul Ferraro
* @param <SC> the servlet context type
*/
public class DelegatingSessionManagerConfiguration<SC> implements SessionManagerConfiguration<SC> {
private final SessionManagerConfiguration<SC> configuration;
public DelegatingSessionManagerConfiguration(SessionManagerConfiguration<SC> configuration) {
this.configuration = configuration;
}
@Override
public Consumer<ImmutableSession> getExpirationListener() {
return this.configuration.getExpirationListener();
}
@Override
public Duration getTimeout() {
return this.configuration.getTimeout();
}
@Override
public SC getServletContext() {
return this.configuration.getServletContext();
}
@Override
public Supplier<String> getIdentifierFactory() {
return this.configuration.getIdentifierFactory();
}
}
| 2,307
| 34.507692
| 118
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ImmutableSessionCreationMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import java.time.Instant;
/**
* Immutable view of the more static aspects of a session's meta-data.
* @author Paul Ferraro
*/
public interface ImmutableSessionCreationMetaData {
/**
* Returns the time at which this session was created.
* @return the time at which this session was created
*/
Instant getCreationTime();
/**
* Returns the maximum duration of time this session may remain idle before it will be expired by the session manager.
* @return the maximum duration of time this session may remain idle before it will be expired by the session manager.
*/
Duration getTimeout();
}
| 1,740
| 37.688889
| 122
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionAccessMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
/**
* The volatile aspects of a session's meta-data.
* @author Paul Ferraro
*/
public interface SessionAccessMetaData extends ImmutableSessionAccessMetaData {
/**
* Sets the last accessed duration (since this session was created) and last request duration.
* @param sinceCreation the duration of time this session was created
* @param lastAccessDuration the duration of time this session was last accessed
*/
void setLastAccessDuration(Duration sinceCreation, Duration lastAccess);
}
| 1,619
| 39.5
| 98
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/CompositeSessionMetaDataEntry.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.concurrent.atomic.AtomicReference;
/**
* Wrapper for the components of a sessions's meta-data,
* @author Paul Ferraro
*/
public class CompositeSessionMetaDataEntry<L> {
private final SessionCreationMetaData creationMetaData;
private final SessionAccessMetaData accessMetaData;
private final AtomicReference<L> localContext;
public CompositeSessionMetaDataEntry(SessionCreationMetaDataEntry<L> creationMetaDataEntry, SessionAccessMetaData accessMetaData) {
this(creationMetaDataEntry.getMetaData(), accessMetaData, creationMetaDataEntry.getLocalContext());
}
public CompositeSessionMetaDataEntry(SessionCreationMetaData creationMetaData, SessionAccessMetaData accessMetaData, AtomicReference<L> localContext) {
this.creationMetaData = creationMetaData;
this.accessMetaData = accessMetaData;
this.localContext = localContext;
}
public SessionCreationMetaData getCreationMetaData() {
return this.creationMetaData;
}
public SessionAccessMetaData getAccessMetaData() {
return this.accessMetaData;
}
public AtomicReference<L> getLocalContext() {
return this.localContext;
}
}
| 2,279
| 38.310345
| 155
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionCreationMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
/**
* The more static aspects of a session's meta-data.
* @author Paul Ferraro
*/
public interface SessionCreationMetaData extends ImmutableSessionCreationMetaData, AutoCloseable {
/**
* Sets the maximum duration of time this session may remain idle before it will be expired by the session manager.
* @param a maximum duration of time this session may remain idle before it will be expired by the session manager.
*/
void setTimeout(Duration duration);
/**
* Indicates whether or not this session has been invalidated.
* @return true, if this session was invalidated, false otherwise.
*/
boolean isValid();
/**
* Invalidates this session.
* @return true, if this session was previous valid, false otherwise
*/
boolean invalidate();
/**
* Indicates whether or not this session was newly created.
* @return true, if this session was newly created, false otherwise.
*/
boolean isNew();
/**
* Signals the end of the transient lifecycle of this session, typically triggered at the end of a given request.
*/
@Override
void close();
}
| 2,254
| 35.370968
| 119
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/InvalidatableSessionMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.web.session.SessionMetaData;
/**
* @author Paul Ferraro
*/
public interface InvalidatableSessionMetaData extends SessionMetaData, AutoCloseable {
/**
* Indicates whether or not this session is still valid.
* @return true, if this session is valid, false otherwise
*/
boolean isValid();
/**
* Invalidates the session.
* @return true, if session was invalidated, false if it was already invalid.
*/
boolean invalidate();
/**
* Signals the end of the transient lifecycle of this session, typically triggered at the end of a given request.
*/
@Override
void close();
}
| 1,743
| 34.591837
| 117
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleImmutableSessionMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import java.time.Instant;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
/**
* An immutable "snapshot" of a session's meta-data which can be accessed outside the scope of a transaction.
* @author Paul Ferraro
*/
public class SimpleImmutableSessionMetaData implements ImmutableSessionMetaData {
private final boolean newSession;
private final Instant creationTime;
private final Instant lastAccessStartTime;
private final Instant lastAccessEndTime;
private final Duration timeout;
public SimpleImmutableSessionMetaData(ImmutableSessionMetaData metaData) {
this.newSession = metaData.isNew();
this.creationTime = metaData.getCreationTime();
this.lastAccessStartTime = metaData.getLastAccessStartTime();
this.lastAccessEndTime = metaData.getLastAccessTime();
this.timeout = metaData.getTimeout();
}
@Override
public boolean isNew() {
return this.newSession;
}
@Override
public Instant getCreationTime() {
return this.creationTime;
}
@Override
public Instant getLastAccessStartTime() {
return this.lastAccessStartTime;
}
@Override
public Instant getLastAccessTime() {
return this.lastAccessEndTime;
}
@Override
public Duration getTimeout() {
return this.timeout;
}
}
| 2,465
| 32.324324
| 109
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ImmutableSessionAttributesFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.ee.Locator;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
/**
* Factory for creating {@link ImmutableSessionAttributes} objects.
* @author Paul Ferraro
* @param <V> attributes cache entry type
*/
public interface ImmutableSessionAttributesFactory<V> extends Locator<String, V> {
ImmutableSessionAttributes createImmutableSessionAttributes(String id, V value);
}
| 1,500
| 40.694444
| 84
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionAttributesFactoryConfiguration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.ee.Immutability;
import org.wildfly.clustering.marshalling.spi.Marshaller;
import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider;
/**
* Configuration of a factory for creating a {@link SessionAttributes} object.
* @param <S> the HttpSession specification type
* @param <C> the ServletContext specification type
* @param <L> the HttpSessionActivationListener specification type
* @param <V> attributes cache entry type
* @param <SV> attributes serialized form type
* @author Paul Ferraro
*/
public interface SessionAttributesFactoryConfiguration<S, C, L, V, SV> {
Marshaller<V, SV> getMarshaller();
Immutability getImmutability();
HttpSessionActivationListenerProvider<S, C, L> getHttpSessionActivationListenerProvider();
}
| 1,875
| 42.627907
| 94
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionAttributesFilter.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.Map;
/**
* @author Paul Ferraro
*/
public interface SessionAttributesFilter {
/**
* Returns the attributes who values implement the specified type.
* @param <T> the target instanceof type
* @param targetClass a target class/interface.
* @return a map of session attribute names and values that are instances of the specified type.
*/
<T> Map<String, T> getAttributes(Class<T> targetClass);
}
| 1,520
| 38
| 100
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionAttributeActivationNotifier.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.function.BiConsumer;
/**
* @author Paul Ferraro
*/
public interface SessionAttributeActivationNotifier extends AutoCloseable {
BiConsumer<SessionAttributeActivationNotifier, Object> PRE_PASSIVATE = SessionAttributeActivationNotifier::prePassivate;
BiConsumer<SessionAttributeActivationNotifier, Object> POST_ACTIVATE = SessionAttributeActivationNotifier::postActivate;
/**
* Notifies the specified attribute that it will be passivated, if interested.
*/
void prePassivate(Object value);
/**
* Notifies the specified attribute that it was activated, if interested.
*/
void postActivate(Object value);
@Override
void close();
}
| 1,776
| 36.808511
| 124
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ImmutableSessionActivationNotifier.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider;
import org.wildfly.clustering.web.session.ImmutableSession;
/**
* Triggers activation/passivation events for all attributes of a session.
* @param <S> the HttpSession specification type
* @param <C> the ServletContext specification type
* @param <L> the HttpSessionActivationListener specification type
* @author Paul Ferraro
*/
public class ImmutableSessionActivationNotifier<S, C, L> implements SessionActivationNotifier {
private final HttpSessionActivationListenerProvider<S, C, L> provider;
private final ImmutableSession session;
private final C context;
private final SessionAttributesFilter filter;
private final AtomicBoolean active = new AtomicBoolean(false);
private final Function<L, Consumer<S>> prePassivateNotifier;
private final Function<L, Consumer<S>> postActivateNotifier;
public ImmutableSessionActivationNotifier(HttpSessionActivationListenerProvider<S, C, L> provider, ImmutableSession session, C context) {
this(provider, session, context, new ImmutableSessionAttributesFilter(session));
}
ImmutableSessionActivationNotifier(HttpSessionActivationListenerProvider<S, C, L> provider, ImmutableSession session, C context, SessionAttributesFilter filter) {
this.provider = provider;
this.session = session;
this.context = context;
this.filter = filter;
this.prePassivateNotifier = this.provider::prePassivateNotifier;
this.postActivateNotifier = this.provider::postActivateNotifier;
}
@Override
public void prePassivate() {
if (this.active.compareAndSet(true, false)) {
this.notify(this.prePassivateNotifier);
}
}
@Override
public void postActivate() {
if (this.active.compareAndSet(false, true)) {
this.notify(this.postActivateNotifier);
}
}
private void notify(Function<L, Consumer<S>> notifierFactory) {
Map<String, L> listeners = this.filter.getAttributes(this.provider.getHttpSessionActivationListenerClass());
if (!listeners.isEmpty()) {
S session = this.provider.createHttpSession(this.session, this.context);
for (L listener : listeners.values()) {
notifierFactory.apply(listener).accept(session);
}
}
}
}
| 3,611
| 40.517241
| 166
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/CompositeImmutableSession.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
/**
* Generic immutable session implementation - independent of cache mapping strategy.
* @author Paul Ferraro
*/
public class CompositeImmutableSession implements ImmutableSession {
private final String id;
private final ImmutableSessionMetaData metaData;
private final ImmutableSessionAttributes attributes;
public CompositeImmutableSession(String id, ImmutableSessionMetaData metaData, ImmutableSessionAttributes attributes) {
this.id = id;
this.metaData = metaData;
this.attributes = attributes;
}
@Override
public String getId() {
return this.id;
}
@Override
public boolean isValid() {
return true;
}
@Override
public ImmutableSessionAttributes getAttributes() {
return this.attributes;
}
@Override
public ImmutableSessionMetaData getMetaData() {
return this.metaData;
}
}
| 2,184
| 33.140625
| 123
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionCreationMetaDataEntryMarshaller.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import org.infinispan.protostream.descriptors.WireType;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter;
/**
* @author Paul Ferraro
*/
public class SessionCreationMetaDataEntryMarshaller implements ProtoStreamMarshaller<SessionCreationMetaDataEntry<Object>> {
private static final Instant DEFAULT_CREATION_TIME = Instant.EPOCH;
// Optimize for specification default
private static final Duration DEFAULT_TIMEOUT = Duration.ofMinutes(30L);
private static final int CREATION_TIME_INDEX = 1;
private static final int TIMEOUT_INDEX = 2;
@Override
public SessionCreationMetaDataEntry<Object> readFrom(ProtoStreamReader reader) throws IOException {
Instant creationTime = DEFAULT_CREATION_TIME;
Duration timeout = DEFAULT_TIMEOUT;
while (!reader.isAtEnd()) {
int tag = reader.readTag();
switch (WireType.getTagFieldNumber(tag)) {
case CREATION_TIME_INDEX:
creationTime = reader.readObject(Instant.class);
break;
case TIMEOUT_INDEX:
timeout = reader.readObject(Duration.class);
break;
default:
reader.skipField(tag);
}
}
SessionCreationMetaData metaData = new SimpleSessionCreationMetaData(creationTime);
metaData.setTimeout(timeout);
return new SessionCreationMetaDataEntry<>(metaData);
}
@Override
public void writeTo(ProtoStreamWriter writer, SessionCreationMetaDataEntry<Object> entry) throws IOException {
SessionCreationMetaData metaData = entry.getMetaData();
Instant creationTime = metaData.getCreationTime();
if (!creationTime.equals(DEFAULT_CREATION_TIME)) {
writer.writeObject(CREATION_TIME_INDEX, creationTime);
}
Duration timeout = metaData.getTimeout();
if (!timeout.equals(DEFAULT_TIMEOUT)) {
writer.writeObject(TIMEOUT_INDEX, timeout);
}
}
@SuppressWarnings("unchecked")
@Override
public Class<? extends SessionCreationMetaDataEntry<Object>> getJavaClass() {
return (Class<SessionCreationMetaDataEntry<Object>>) (Class<?>) SessionCreationMetaDataEntry.class;
}
}
| 3,601
| 39.47191
| 124
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleSessionAccessMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
/**
* @author Paul Ferraro
*/
public class SimpleSessionAccessMetaData implements SessionAccessMetaData {
private volatile Duration sinceCreation = Duration.ZERO;
private volatile Duration lastAccess = Duration.ZERO;
@Override
public Duration getSinceCreationDuration() {
return this.sinceCreation;
}
@Override
public Duration getLastAccessDuration() {
return this.lastAccess;
}
@Override
public void setLastAccessDuration(Duration sinceCreation, Duration lastAccess) {
this.sinceCreation = normalize(sinceCreation);
this.lastAccess = normalize(lastAccess);
}
private static Duration normalize(Duration duration) {
// Only retain millisecond precision, rounding up to nearest millisecond
Duration truncatedDuration = duration.truncatedTo(ChronoUnit.MILLIS);
return !duration.equals(truncatedDuration) ? truncatedDuration.plusMillis(1) : duration;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder(this.getClass().getSimpleName()).append(" { ");
builder.append("since-creation = ").append(this.sinceCreation);
builder.append(", last-access = ").append(this.lastAccess);
return builder.append("}").toString();
}
}
| 2,444
| 36.045455
| 97
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionAccessMetaDataMarshaller.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.io.IOException;
import java.time.Duration;
import org.infinispan.protostream.descriptors.WireType;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter;
/**
* @author Paul Ferraro
*/
public class SessionAccessMetaDataMarshaller implements ProtoStreamMarshaller<SimpleSessionAccessMetaData> {
// Optimize for new sessions
private static final Duration DEFAULT_SINCE_CREATION = Duration.ZERO;
// Optimize for sub-second request duration
private static final Duration DEFAULT_LAST_ACCESS = Duration.ofSeconds(1);
private static final int SINCE_CREATION_INDEX = 1;
private static final int LAST_ACCESS_INDEX = 2;
@Override
public SimpleSessionAccessMetaData readFrom(ProtoStreamReader reader) throws IOException {
Duration sinceCreation = DEFAULT_SINCE_CREATION;
Duration lastAccess = DEFAULT_LAST_ACCESS;
while (!reader.isAtEnd()) {
int tag = reader.readTag();
switch (WireType.getTagFieldNumber(tag)) {
case SINCE_CREATION_INDEX:
sinceCreation = reader.readObject(Duration.class);
break;
case LAST_ACCESS_INDEX:
lastAccess = reader.readObject(Duration.class);
break;
default:
reader.skipField(tag);
}
}
SimpleSessionAccessMetaData metaData = new SimpleSessionAccessMetaData();
metaData.setLastAccessDuration(sinceCreation, lastAccess);
return metaData;
}
@Override
public void writeTo(ProtoStreamWriter writer, SimpleSessionAccessMetaData metaData) throws IOException {
Duration sinceCreation = metaData.getSinceCreationDuration();
if (!sinceCreation.equals(DEFAULT_SINCE_CREATION)) {
writer.writeObject(SINCE_CREATION_INDEX, sinceCreation);
}
Duration lastAccess = metaData.getLastAccessDuration();
if (!lastAccess.equals(DEFAULT_LAST_ACCESS)) {
writer.writeObject(LAST_ACCESS_INDEX, lastAccess);
}
}
@Override
public Class<? extends SimpleSessionAccessMetaData> getJavaClass() {
return SimpleSessionAccessMetaData.class;
}
}
| 3,471
| 39.372093
| 108
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionAttributes.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
/**
* @author Paul Ferraro
*/
public interface SessionAttributes extends org.wildfly.clustering.web.session.SessionAttributes, AutoCloseable {
/**
* Signals the end of the transient lifecycle of this session, typically triggered at the end of a given request.
*/
@Override
void close();
}
| 1,388
| 38.685714
| 117
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ImmutableSessionAttributeActivationNotifier.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider;
import org.wildfly.clustering.web.session.ImmutableSession;
/**
* Triggers activation/passivation events for a single session attribute.
* @param <S> the HttpSession specification type
* @param <C> the ServletContext specification type
* @param <L> the HttpSessionActivationListener specification type
* @author Paul Ferraro
*/
public class ImmutableSessionAttributeActivationNotifier<S, C, L> implements SessionAttributeActivationNotifier {
private final Function<Supplier<L>, L> prePassivateListenerFactory;
private final Function<Supplier<L>, L> postActivateListenerFactory;
private final HttpSessionActivationListenerProvider<S, C, L> provider;
private final Function<L, Consumer<S>> prePassivateNotifier;
private final Function<L, Consumer<S>> postActivateNotifier;
private final S session;
private final Map<Supplier<L>, L> listeners = new ConcurrentHashMap<>();
public ImmutableSessionAttributeActivationNotifier(HttpSessionActivationListenerProvider<S, C, L> provider, ImmutableSession session, C context) {
this.provider = provider;
this.prePassivateNotifier = this.provider::prePassivateNotifier;
this.postActivateNotifier = this.provider::postActivateNotifier;
this.prePassivateListenerFactory = new HttpSessionActivationListenerFactory<>(provider, true);
this.postActivateListenerFactory = new HttpSessionActivationListenerFactory<>(provider, false);
this.session = provider.createHttpSession(session, context);
}
@Override
public void prePassivate(Object object) {
this.notify(object, this.prePassivateListenerFactory, this.prePassivateNotifier);
}
@Override
public void postActivate(Object object) {
this.notify(object, this.postActivateListenerFactory, this.postActivateNotifier);
}
private void notify(Object object, Function<Supplier<L>, L> listenerFactory, Function<L, Consumer<S>> notifierFactory) {
Class<L> listenerClass = this.provider.getHttpSessionActivationListenerClass();
if (listenerClass.isInstance(object)) {
Supplier<L> reference = new HttpSessionActivationListenerKey<>(listenerClass.cast(object));
L listener = this.listeners.computeIfAbsent(reference, listenerFactory);
notifierFactory.apply(listener).accept(this.session);
}
}
@Override
public void close() {
for (L listener : this.listeners.values()) {
this.provider.prePassivateNotifier(listener).accept(this.session);
}
this.listeners.clear();
}
/**
* Map key of a {@link HttpSessionActivationListener} that uses identity equality.
*/
private static class HttpSessionActivationListenerKey<L> implements Supplier<L> {
private final L listener;
HttpSessionActivationListenerKey(L listener) {
this.listener = listener;
}
@Override
public L get() {
return this.listener;
}
@Override
public int hashCode() {
return this.listener.hashCode();
}
@Override
public boolean equals(Object object) {
if (!(object instanceof HttpSessionActivationListenerKey)) return false;
@SuppressWarnings("unchecked")
HttpSessionActivationListenerKey<L> reference = (HttpSessionActivationListenerKey<L>) object;
return this.listener == reference.listener;
}
}
/**
* Factory for creating HttpSessionActivationListener values.
*/
private static class HttpSessionActivationListenerFactory<S, C, L> implements Function<Supplier<L>, L> {
private final HttpSessionActivationListenerProvider<S, C, L> provider;
private final boolean active;
HttpSessionActivationListenerFactory(HttpSessionActivationListenerProvider<S, C, L> provider, boolean active) {
this.provider = provider;
this.active = active;
}
@Override
public L apply(Supplier<L> reference) {
HttpSessionActivationListenerProvider<S, C, L> provider = this.provider;
L listener = reference.get();
// Prevents redundant session activation events for a given listener.
AtomicBoolean active = new AtomicBoolean(this.active);
Consumer<S> prePassivate = new Consumer<>() {
@Override
public void accept(S session) {
if (active.compareAndSet(true, false)) {
provider.prePassivateNotifier(listener).accept(session);
}
}
};
Consumer<S> postActivate = new Consumer<>() {
@Override
public void accept(S session) {
if (active.compareAndSet(false, true)) {
provider.postActivateNotifier(listener).accept(session);
}
}
};
return provider.createListener(prePassivate, postActivate);
}
}
}
| 6,468
| 40.735484
| 150
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ImmutableSessionAttributesFilter.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
/**
* @author Paul Ferraro
*/
public class ImmutableSessionAttributesFilter implements SessionAttributesFilter {
private final ImmutableSessionAttributes attributes;
public ImmutableSessionAttributesFilter(ImmutableSession session) {
this(session.getAttributes());
}
public ImmutableSessionAttributesFilter(ImmutableSessionAttributes attributes) {
this.attributes = attributes;
}
@Override
public <T> Map<String, T> getAttributes(Class<T> targetClass) {
Set<String> names = this.attributes.getAttributeNames();
if (names.isEmpty()) return Collections.emptyMap();
Map<String, T> result = new HashMap<>(names.size());
for (String name : names) {
Object attribute = this.attributes.getAttribute(name);
if (targetClass.isInstance(attribute)) {
result.put(name, targetClass.cast(attribute));
}
}
return Collections.unmodifiableMap(result);
}
}
| 2,300
| 36.112903
| 84
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SimpleImmutableSessionAttributes.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
/**
* An immutable "snapshot" of a session's attributes which can be accessed outside the scope of a transaction.
* @author Paul Ferraro
*/
public class SimpleImmutableSessionAttributes implements ImmutableSessionAttributes {
private final Map<String, Object> attributes;
public SimpleImmutableSessionAttributes(ImmutableSessionAttributes attributes) {
Map<String, Object> map = new HashMap<>();
for (String name: attributes.getAttributeNames()) {
map.put(name, attributes.getAttribute(name));
}
this.attributes = Collections.unmodifiableMap(map);
}
@Override
public Set<String> getAttributeNames() {
return this.attributes.keySet();
}
@Override
public Object getAttribute(String name) {
return this.attributes.get(name);
}
}
| 2,075
| 35.421053
| 110
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ImmutableSessionFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.Map;
import org.wildfly.clustering.ee.Locator;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
/**
* Factory for creating an {@link ImmutableSession}.
* @author Paul Ferraro
*/
public interface ImmutableSessionFactory<MV, AV> extends Locator<String, Map.Entry<MV, AV>>{
ImmutableSessionMetaDataFactory<MV> getMetaDataFactory();
ImmutableSessionAttributesFactory<AV> getAttributesFactory();
default ImmutableSession createImmutableSession(String id, Map.Entry<MV, AV> entry) {
ImmutableSessionMetaData metaData = this.getMetaDataFactory().createImmutableSessionMetaData(id, entry.getKey());
ImmutableSessionAttributes attributes = this.getAttributesFactory().createImmutableSessionAttributes(id, entry.getValue());
return this.createImmutableSession(id, metaData, attributes);
}
ImmutableSession createImmutableSession(String id, ImmutableSessionMetaData metaData, ImmutableSessionAttributes attributes);
}
| 2,199
| 44.833333
| 131
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/MutableSessionAccessMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import org.wildfly.clustering.ee.Mutator;
/**
* @author Paul Ferraro
*/
public class MutableSessionAccessMetaData implements SessionAccessMetaData {
private final SessionAccessMetaData metaData;
private final Mutator mutator;
public MutableSessionAccessMetaData(SessionAccessMetaData metaData, Mutator mutator) {
this.metaData = metaData;
this.mutator = mutator;
}
@Override
public Duration getSinceCreationDuration() {
return this.metaData.getSinceCreationDuration();
}
@Override
public Duration getLastAccessDuration() {
return this.metaData.getLastAccessDuration();
}
@Override
public void setLastAccessDuration(Duration sinceCreation, Duration lastAccess) {
this.metaData.setLastAccessDuration(sinceCreation, lastAccess);
this.mutator.mutate();
}
}
| 1,964
| 32.87931
| 90
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/CompositeImmutableSessionFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.Map;
import java.util.AbstractMap.SimpleImmutableEntry;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
/**
* Generic immutable session factory implementation - independent of cache mapping strategy.
* @author Paul Ferraro
*/
public class CompositeImmutableSessionFactory<V, L> implements ImmutableSessionFactory<CompositeSessionMetaDataEntry<L>, V> {
private final ImmutableSessionMetaDataFactory<CompositeSessionMetaDataEntry<L>> metaDataFactory;
private final ImmutableSessionAttributesFactory<V> attributesFactory;
public CompositeImmutableSessionFactory(ImmutableSessionMetaDataFactory<CompositeSessionMetaDataEntry<L>> metaDataFactory, ImmutableSessionAttributesFactory<V> attributesFactory) {
this.metaDataFactory = metaDataFactory;
this.attributesFactory = attributesFactory;
}
@Override
public Map.Entry<CompositeSessionMetaDataEntry<L>, V> findValue(String id) {
CompositeSessionMetaDataEntry<L> metaDataValue = this.metaDataFactory.findValue(id);
if (metaDataValue != null) {
V attributesValue = this.attributesFactory.findValue(id);
if (attributesValue != null) {
return new SimpleImmutableEntry<>(metaDataValue, attributesValue);
}
}
return null;
}
@Override
public Map.Entry<CompositeSessionMetaDataEntry<L>, V> tryValue(String id) {
CompositeSessionMetaDataEntry<L> metaDataValue = this.metaDataFactory.tryValue(id);
if (metaDataValue != null) {
V attributesValue = this.attributesFactory.tryValue(id);
if (attributesValue != null) {
return new SimpleImmutableEntry<>(metaDataValue, attributesValue);
}
}
return null;
}
@Override
public ImmutableSessionMetaDataFactory<CompositeSessionMetaDataEntry<L>> getMetaDataFactory() {
return this.metaDataFactory;
}
@Override
public ImmutableSessionAttributesFactory<V> getAttributesFactory() {
return this.attributesFactory;
}
@Override
public ImmutableSession createImmutableSession(String id, ImmutableSessionMetaData metaData, ImmutableSessionAttributes attributes) {
return new CompositeImmutableSession(id, metaData, attributes);
}
}
| 3,534
| 40.588235
| 184
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionBindingNotifier.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
/**
* Notifies attributes of a session implementing session binding listener.
* @author Paul Ferraro
*/
public interface SessionBindingNotifier {
/**
* Notifies all attributes that they are being unbound from a given session.
*/
void bound();
/**
* Notifies all attributes that they are being unbound from a given session.
*/
void unbound();
}
| 1,460
| 34.634146
| 80
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/CompositeSessionFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map;
import org.wildfly.clustering.web.LocalContextFactory;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
import org.wildfly.clustering.web.session.Session;
/**
* @param <C> the ServletContext specification type
* @param <V> the session attribute value type
* @param <L> the local context type
* @author Paul Ferraro
*/
public class CompositeSessionFactory<C, V, L> extends CompositeImmutableSessionFactory<V, L> implements SessionFactory<C, CompositeSessionMetaDataEntry<L>, V, L> {
private final SessionMetaDataFactory<CompositeSessionMetaDataEntry<L>> metaDataFactory;
private final SessionAttributesFactory<C, V> attributesFactory;
private final LocalContextFactory<L> localContextFactory;
public CompositeSessionFactory(SessionMetaDataFactory<CompositeSessionMetaDataEntry<L>> metaDataFactory, SessionAttributesFactory<C, V> attributesFactory, LocalContextFactory<L> localContextFactory) {
super(metaDataFactory, attributesFactory);
this.metaDataFactory = metaDataFactory;
this.attributesFactory = attributesFactory;
this.localContextFactory = localContextFactory;
}
@Override
public Map.Entry<CompositeSessionMetaDataEntry<L>, V> createValue(String id, SessionCreationMetaData creationMetaData) {
CompositeSessionMetaDataEntry<L> metaDataValue = this.metaDataFactory.createValue(id, creationMetaData);
if (metaDataValue == null) return null;
V attributesValue = this.attributesFactory.createValue(id, null);
return new SimpleImmutableEntry<>(metaDataValue, attributesValue);
}
@Override
public Map.Entry<CompositeSessionMetaDataEntry<L>, V> findValue(String id) {
CompositeSessionMetaDataEntry<L> metaDataValue = this.metaDataFactory.findValue(id);
if (metaDataValue != null) {
V attributesValue = this.attributesFactory.findValue(id);
if (attributesValue != null) {
return new SimpleImmutableEntry<>(metaDataValue, attributesValue);
}
// Purge obsolete meta data
this.metaDataFactory.purge(id);
}
return null;
}
@Override
public Map.Entry<CompositeSessionMetaDataEntry<L>, V> tryValue(String id) {
CompositeSessionMetaDataEntry<L> metaDataValue = this.metaDataFactory.tryValue(id);
if (metaDataValue != null) {
V attributesValue = this.attributesFactory.tryValue(id);
if (attributesValue != null) {
return new SimpleImmutableEntry<>(metaDataValue, attributesValue);
}
}
return null;
}
@Override
public boolean remove(String id) {
this.attributesFactory.remove(id);
return this.metaDataFactory.remove(id);
}
@Override
public boolean purge(String id) {
this.attributesFactory.purge(id);
return this.metaDataFactory.purge(id);
}
@Override
public SessionMetaDataFactory<CompositeSessionMetaDataEntry<L>> getMetaDataFactory() {
return this.metaDataFactory;
}
@Override
public SessionAttributesFactory<C, V> getAttributesFactory() {
return this.attributesFactory;
}
@Override
public Session<L> createSession(String id, Map.Entry<CompositeSessionMetaDataEntry<L>, V> entry, C context) {
CompositeSessionMetaDataEntry<L> key = entry.getKey();
InvalidatableSessionMetaData metaData = this.metaDataFactory.createSessionMetaData(id, key);
SessionAttributes attributes = this.attributesFactory.createSessionAttributes(id, entry.getValue(), metaData, context);
return new CompositeSession<>(id, metaData, attributes, key.getLocalContext(), this.localContextFactory, this);
}
@Override
public ImmutableSession createImmutableSession(String id, ImmutableSessionMetaData metaData, ImmutableSessionAttributes attributes) {
return new CompositeImmutableSession(id, metaData, attributes);
}
@Override
public void close() {
this.metaDataFactory.close();
this.attributesFactory.close();
}
}
| 5,391
| 41.125
| 204
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/MutableSessionCreationMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import java.time.Instant;
import org.wildfly.clustering.ee.Mutator;
/**
* @author Paul Ferraro
*/
public class MutableSessionCreationMetaData implements SessionCreationMetaData {
private final SessionCreationMetaData metaData;
private final Mutator mutator;
public MutableSessionCreationMetaData(SessionCreationMetaData metaData, Mutator mutator) {
this.metaData = metaData;
this.mutator = mutator;
}
@Override
public boolean isNew() {
return this.metaData.isNew();
}
@Override
public Instant getCreationTime() {
return this.metaData.getCreationTime();
}
@Override
public Duration getTimeout() {
return this.metaData.getTimeout();
}
@Override
public void setTimeout(Duration duration) {
if (!this.metaData.getTimeout().equals(duration)) {
this.metaData.setTimeout(duration);
this.mutator.mutate();
}
}
@Override
public boolean isValid() {
return this.metaData.isValid();
}
@Override
public boolean invalidate() {
return this.metaData.invalidate();
}
@Override
public void close() {
this.metaData.close();
}
}
| 2,328
| 27.753086
| 94
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionActivationNotifier.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
/**
* Notifies attributes of a session implementing session activation listener.
* @author Paul Ferraro
*/
public interface SessionActivationNotifier {
/**
* Notifies interested attributes that they will be passivated.
*/
void prePassivate();
/**
* Notifies interested attributes that they are were activated.
*/
void postActivate();
}
| 1,452
| 34.439024
| 77
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ImmutableSessionMetaDataFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.ee.Locator;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
/**
* @author Paul Ferraro
*/
public interface ImmutableSessionMetaDataFactory<V> extends Locator<String, V> {
ImmutableSessionMetaData createImmutableSessionMetaData(String id, V value);
}
| 1,382
| 39.676471
| 80
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionCreationMetaDataEntry.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.concurrent.atomic.AtomicReference;
/**
* Cache entry containing the session creation meta data and local context.
* @author Paul Ferraro
*/
public class SessionCreationMetaDataEntry<L> {
private final SessionCreationMetaData metaData;
private final AtomicReference<L> localContext;
public SessionCreationMetaDataEntry(SessionCreationMetaData metaData) {
this(metaData, new AtomicReference<>());
}
public SessionCreationMetaDataEntry(SessionCreationMetaData metaData, AtomicReference<L> localContext) {
this.metaData = metaData;
this.localContext = localContext;
}
public SessionCreationMetaData getMetaData() {
return this.metaData;
}
public AtomicReference<L> getLocalContext() {
return this.localContext;
}
@Override
public String toString() {
return this.metaData.toString();
}
}
| 1,984
| 33.824561
| 108
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/MarshalledValueSessionAttributesFactoryConfiguration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.ee.Immutability;
import org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValueFactory;
import org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller;
import org.wildfly.clustering.marshalling.spi.MarshalledValue;
import org.wildfly.clustering.marshalling.spi.MarshalledValueMarshaller;
import org.wildfly.clustering.marshalling.spi.Marshaller;
import org.wildfly.clustering.web.session.HttpSessionActivationListenerProvider;
import org.wildfly.clustering.web.session.SessionManagerFactoryConfiguration;
/**
* Configuration for a factory for creating {@link SessionAttributes} objects, based on marshalled values.
* @author Paul Ferraro
* @param <S> the HttpSession specification type
* @param <SC> the ServletContext specification type
* @param <AL> the HttpSessionAttributeListener specification type
* @param <V> the attributes value type
* @param <LC> the local context type
*/
public abstract class MarshalledValueSessionAttributesFactoryConfiguration<S, SC, AL, V, LC> implements SessionAttributesFactoryConfiguration<S, SC, AL, V, MarshalledValue<V, ByteBufferMarshaller>> {
private final Immutability immutability;
private final Marshaller<V, MarshalledValue<V, ByteBufferMarshaller>> marshaller;
private final HttpSessionActivationListenerProvider<S, SC, AL> provider;
protected MarshalledValueSessionAttributesFactoryConfiguration(SessionManagerFactoryConfiguration<S, SC, AL, LC> configuration) {
this.immutability = configuration.getImmutability();
this.marshaller = new MarshalledValueMarshaller<>(new ByteBufferMarshalledValueFactory(configuration.getMarshaller()));
this.provider = configuration.getSpecificationProvider();
}
@Override
public Marshaller<V, MarshalledValue<V, ByteBufferMarshaller>> getMarshaller() {
return this.marshaller;
}
@Override
public Immutability getImmutability() {
return this.immutability;
}
@Override
public HttpSessionActivationListenerProvider<S, SC, AL> getHttpSessionActivationListenerProvider() {
return this.provider;
}
}
| 3,208
| 46.191176
| 199
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/ValidSession.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.function.Consumer;
import org.wildfly.clustering.web.cache.logging.Logger;
import org.wildfly.clustering.web.session.ImmutableSession;
import org.wildfly.clustering.web.session.Session;
import org.wildfly.clustering.web.session.SessionAttributes;
import org.wildfly.clustering.web.session.SessionMetaData;
/**
* {@link Session} decorator whose methods throw an {@link IllegalStateException} if the session is not valid.
* @author Paul Ferraro
*/
public class ValidSession<L> implements Session<L> {
private final Session<L> session;
private final Consumer<ImmutableSession> closeTask;
public ValidSession(Session<L> session, Consumer<ImmutableSession> closeTask) {
this.session = session;
this.closeTask = closeTask;
}
private void validate() {
if (!this.session.isValid()) {
throw Logger.ROOT_LOGGER.invalidSession(this.getId());
}
}
@Override
public String getId() {
return this.session.getId();
}
@Override
public boolean isValid() {
return this.session.isValid();
}
@Override
public L getLocalContext() {
return this.session.getLocalContext();
}
@Override
public SessionMetaData getMetaData() {
this.validate();
return this.session.getMetaData();
}
@Override
public SessionAttributes getAttributes() {
this.validate();
return this.session.getAttributes();
}
@Override
public void invalidate() {
this.validate();
this.session.invalidate();
}
@Override
public void close() {
try {
this.session.close();
} finally {
this.closeTask.accept(this.session);
}
}
}
| 2,838
| 29.202128
| 110
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/CompositeSessionMetaData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.time.Duration;
import java.time.Instant;
/**
* Composite view of the meta data of a session, combining volatile and static aspects.
* @author Paul Ferraro
*/
public class CompositeSessionMetaData implements InvalidatableSessionMetaData {
private final SessionCreationMetaData creationMetaData;
private final SessionAccessMetaData accessMetaData;
public CompositeSessionMetaData(SessionCreationMetaData creationMetaData, SessionAccessMetaData accessMetaData) {
this.creationMetaData = creationMetaData;
this.accessMetaData = accessMetaData;
}
@Override
public boolean isNew() {
return this.creationMetaData.isNew();
}
@Override
public boolean isValid() {
return this.creationMetaData.isValid();
}
@Override
public boolean invalidate() {
return this.creationMetaData.invalidate();
}
@Override
public Instant getCreationTime() {
return this.creationMetaData.getCreationTime();
}
@Override
public Instant getLastAccessStartTime() {
return this.getCreationTime().plus(this.accessMetaData.getSinceCreationDuration());
}
@Override
public Instant getLastAccessTime() {
return this.getLastAccessStartTime().plus(this.accessMetaData.getLastAccessDuration());
}
@Override
public Duration getTimeout() {
return this.creationMetaData.getTimeout();
}
@Override
public void setLastAccess(Instant startTime, Instant endTime) {
Instant creationTime = this.creationMetaData.getCreationTime();
this.accessMetaData.setLastAccessDuration(!startTime.equals(creationTime) ? Duration.between(creationTime, startTime) : Duration.ZERO, Duration.between(startTime, endTime));
}
@Override
public void setMaxInactiveInterval(Duration duration) {
this.creationMetaData.setTimeout(duration.isNegative() ? Duration.ZERO : duration);
}
@Override
public void close() {
this.creationMetaData.close();
}
}
| 3,112
| 32.836957
| 181
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import java.util.Map;
import org.wildfly.clustering.ee.Creator;
import org.wildfly.clustering.ee.Remover;
import org.wildfly.clustering.web.session.Session;
/**
* Factory for creating sessions. Encapsulates the cache mapping strategy for sessions.
* @param <SC> the ServletContext specification type
* @param <MV> the meta-data value type
* @param <AV> the attributes value type
* @param <LC> the local context type
* @author Paul Ferraro
*/
public interface SessionFactory<SC, MV, AV, LC> extends ImmutableSessionFactory<MV, AV>, Creator<String, Map.Entry<MV, AV>, SessionCreationMetaData>, Remover<String>, AutoCloseable {
@Override
SessionMetaDataFactory<MV> getMetaDataFactory();
@Override
SessionAttributesFactory<SC, AV> getAttributesFactory();
Session<LC> createSession(String id, Map.Entry<MV, AV> entry, SC context);
@Override
void close();
}
| 1,965
| 39.122449
| 182
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionMetaDataFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.ee.Creator;
import org.wildfly.clustering.ee.Remover;
/**
* @author Paul Ferraro
*/
public interface SessionMetaDataFactory<V> extends ImmutableSessionMetaDataFactory<V>, Creator<String, V, SessionCreationMetaData>, Remover<String>, AutoCloseable {
InvalidatableSessionMetaData createSessionMetaData(String id, V value);
@Override
default void close() {
// Nothing to close
}
}
| 1,511
| 37.769231
| 164
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionSerializationContextInitializer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer;
/**
* @author Paul Ferraro
*/
@MetaInfServices(SerializationContextInitializer.class)
public class SessionSerializationContextInitializer extends AbstractSerializationContextInitializer {
@Override
public void registerMarshallers(SerializationContext context) {
context.registerMarshaller(new SessionCreationMetaDataEntryMarshaller());
context.registerMarshaller(new SessionAccessMetaDataMarshaller());
}
}
| 1,768
| 41.119048
| 101
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/SessionAttributesFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session;
import org.wildfly.clustering.ee.Creator;
import org.wildfly.clustering.ee.Remover;
import org.wildfly.clustering.web.session.ImmutableSessionMetaData;
/**
* Factory for creating a {@link SessionAttributes} object.
* @param <C> the ServletContext specification type
* @param <V> the marshalled value type
* @author Paul Ferraro
*/
public interface SessionAttributesFactory<C, V> extends ImmutableSessionAttributesFactory<V>, Creator<String, V, Void>, Remover<String>, AutoCloseable {
SessionAttributes createSessionAttributes(String id, V value, ImmutableSessionMetaData metaData, C context);
@Override
default void close() {
// Nothing to close
}
}
| 1,756
| 39.860465
| 152
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/ConcurrentSessionAttributeMapRemoveFunction.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.util.UUID;
import org.wildfly.clustering.ee.cache.function.ConcurrentMapRemoveFunction;
/**
* Concurrent {@link java.util.Map#remove(Object)} function for a session attribute.
* @author Paul Ferraro
*/
public class ConcurrentSessionAttributeMapRemoveFunction extends ConcurrentMapRemoveFunction<String, UUID> {
public ConcurrentSessionAttributeMapRemoveFunction(String attributeName) {
super(attributeName);
}
}
| 1,526
| 38.153846
| 108
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributes.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.io.IOException;
import java.io.NotSerializableException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import org.wildfly.clustering.ee.Immutability;
import org.wildfly.clustering.ee.MutatorFactory;
import org.wildfly.clustering.ee.UUIDFactory;
import org.wildfly.clustering.ee.cache.CacheProperties;
import org.wildfly.clustering.marshalling.spi.Marshaller;
import org.wildfly.clustering.web.cache.session.SessionAttributeActivationNotifier;
import org.wildfly.clustering.web.cache.session.SessionAttributes;
/**
* Exposes session attributes for fine granularity sessions.
* @author Paul Ferraro
*/
public class FineSessionAttributes<NK, K, V> implements SessionAttributes {
private final NK key;
private final Map<NK, Map<String, UUID>> namesCache;
private final Function<UUID, K> keyFactory;
private final Map<K, V> attributeCache;
private final Map<K, Optional<Object>> mutations = new HashMap<>();
private final Marshaller<Object, V> marshaller;
private final MutatorFactory<K, V> mutatorFactory;
private final Immutability immutability;
private final CacheProperties properties;
private final SessionAttributeActivationNotifier notifier;
private final AtomicReference<Map<String, UUID>> names;
public FineSessionAttributes(NK key, AtomicReference<Map<String, UUID>> names, Map<NK, Map<String, UUID>> namesCache, Function<UUID, K> keyFactory, Map<K, V> attributeCache, Marshaller<Object, V> marshaller, MutatorFactory<K, V> mutatorFactory, Immutability immutability, CacheProperties properties, SessionAttributeActivationNotifier notifier) {
this.key = key;
this.names = names;
this.namesCache = namesCache;
this.keyFactory = keyFactory;
this.attributeCache = attributeCache;
this.marshaller = marshaller;
this.mutatorFactory = mutatorFactory;
this.immutability = immutability;
this.properties = properties;
this.notifier = notifier;
}
@Override
public Object removeAttribute(String name) {
UUID attributeId = this.names.get().get(name);
if (attributeId == null) return null;
synchronized (this.mutations) {
this.setNames(this.namesCache.compute(this.key, this.properties.isTransactional() ? new CopyOnWriteSessionAttributeMapRemoveFunction(name) : new ConcurrentSessionAttributeMapRemoveFunction(name)));
K key = this.keyFactory.apply(attributeId);
Object result = this.read(this.attributeCache.remove(key));
if (result != null) {
this.mutations.remove(key);
if (this.properties.isPersistent()) {
this.notifier.postActivate(result);
}
}
return result;
}
}
@Override
public Object setAttribute(String name, Object attribute) {
if (attribute == null) {
return this.removeAttribute(name);
}
if (this.properties.isMarshalling() && !this.marshaller.isMarshallable(attribute)) {
throw new IllegalArgumentException(new NotSerializableException(attribute.getClass().getName()));
}
UUID attributeId = this.names.get().get(name);
synchronized (this.mutations) {
if (attributeId == null) {
UUID newAttributeId = UUIDFactory.INSECURE.get();
this.setNames(this.namesCache.compute(this.key, this.properties.isTransactional() ? new CopyOnWriteSessionAttributeMapPutFunction(name, newAttributeId) : new ConcurrentSessionAttributeMapPutFunction(name, newAttributeId)));
attributeId = this.names.get().get(name);
}
K key = this.keyFactory.apply(attributeId);
V value = this.write(attribute);
if (this.properties.isPersistent()) {
this.notifier.prePassivate(attribute);
}
Object result = this.read(this.attributeCache.put(key, value));
if (this.properties.isTransactional()) {
// Add an empty value to prevent any subsequent mutable getAttribute(...) from triggering a redundant mutation on close.
this.mutations.put(key, Optional.empty());
} else {
// If the object is mutable, we need to indicate trigger a mutation on close
if (this.immutability.test(attribute)) {
this.mutations.remove(key);
} else {
this.mutations.put(key, Optional.of(attribute));
}
}
if (this.properties.isPersistent()) {
this.notifier.postActivate(attribute);
if (result != attribute) {
this.notifier.postActivate(result);
}
}
return result;
}
}
@Override
public Object getAttribute(String name) {
UUID attributeId = this.names.get().get(name);
if (attributeId == null) return null;
synchronized (this.mutations) {
K key = this.keyFactory.apply(attributeId);
// Return mutable value if present, this preserves referential integrity when this member is not an owner.
Optional<Object> mutableValue = this.mutations.get(key);
if ((mutableValue != null) && mutableValue.isPresent()) {
return mutableValue.get();
}
Object result = this.read(this.attributeCache.get(key));
if (result != null) {
if (this.properties.isPersistent()) {
this.notifier.postActivate(result);
}
// If the object is mutable, we need to trigger a mutation on close
if (!this.immutability.test(result)) {
this.mutations.putIfAbsent(key, Optional.of(result));
}
}
return result;
}
}
@Override
public Set<String> getAttributeNames() {
return this.names.get().keySet();
}
@Override
public void close() {
synchronized (this.mutations) {
this.notifier.close();
for (Map.Entry<K, Optional<Object>> entry : this.mutations.entrySet()) {
Optional<Object> optional = entry.getValue();
if (optional.isPresent()) {
K key = entry.getKey();
V value = this.write(optional.get());
this.mutatorFactory.createMutator(key, value).mutate();
}
}
this.mutations.clear();
}
}
private void setNames(Map<String, UUID> names) {
this.names.set((names != null) ? Collections.unmodifiableMap(names) : Collections.emptyMap());
}
private V write(Object value) {
try {
return this.marshaller.write(value);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
private Object read(V value) {
try {
return this.marshaller.read(value);
} catch (IOException e) {
// This should not happen here, since attributes were pre-activated during session construction
throw new IllegalStateException(e);
}
}
}
| 8,584
| 38.562212
| 350
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntry.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.UUID;
/**
* {@link java.util.Map.Entry} for a session attribute.
* Used to optimize the marshalling of {@link java.util.Map#put(Object, Object)} functions.
* @author Paul Ferraro
*/
public class SessionAttributeMapEntry extends SimpleImmutableEntry<String, UUID> {
private static final long serialVersionUID = -6446474741366055972L;
public SessionAttributeMapEntry(String key, UUID value) {
super(key, value);
}
}
| 1,588
| 38.725
| 91
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineImmutableSessionAttributes.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import org.wildfly.clustering.marshalling.spi.Marshaller;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
/**
* Exposes session attributes for fine granularity sessions.
* @author Paul Ferraro
*/
public class FineImmutableSessionAttributes<K, V> implements ImmutableSessionAttributes {
private final AtomicReference<Map<String, UUID>> names;
private final Function<UUID, K> keyFactory;
private final Map<K, V> attributeCache;
private final Marshaller<Object, V> marshaller;
public FineImmutableSessionAttributes(AtomicReference<Map<String, UUID>> names, Function<UUID, K> keyFactory, Map<K, V> attributeCache, Marshaller<Object, V> marshaller) {
this.names = names;
this.keyFactory = keyFactory;
this.attributeCache = attributeCache;
this.marshaller = marshaller;
}
@Override
public Set<String> getAttributeNames() {
return this.names.get().keySet();
}
@Override
public Object getAttribute(String name) {
UUID attributeId = this.names.get().get(name);
if (attributeId == null) return null;
K key = this.keyFactory.apply(attributeId);
return this.read(this.attributeCache.get(key));
}
private Object read(V value) {
try {
return this.marshaller.read(value);
} catch (IOException e) {
// This should not happen here, since attributes were pre-activated when session was constructed
throw new IllegalStateException(e);
}
}
}
| 2,803
| 37.410959
| 175
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/ConcurrentSessionAttributeMapPutFunction.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.util.Map;
import java.util.UUID;
import org.wildfly.clustering.ee.cache.function.ConcurrentMapPutFunction;
/**
* Concurrent {@link Map#put(Object, Object)} function for a session attribute.
* @author Paul Ferraro
*/
public class ConcurrentSessionAttributeMapPutFunction extends ConcurrentMapPutFunction<String, UUID> {
public ConcurrentSessionAttributeMapPutFunction(String attributeName, UUID attributeId) {
super(new SessionAttributeMapEntry(attributeName, attributeId));
}
public ConcurrentSessionAttributeMapPutFunction(Map.Entry<String, UUID> operand) {
super(operand);
}
}
| 1,710
| 37.886364
| 102
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributesSerializationContextInitializer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer;
import org.wildfly.clustering.marshalling.protostream.FunctionalMarshaller;
import org.wildfly.clustering.marshalling.protostream.FunctionalScalarMarshaller;
import org.wildfly.clustering.marshalling.protostream.Scalar;
/**
* {@link SerializationContextInitializer} for this package.
* @author Paul Ferraro
*/
@MetaInfServices(SerializationContextInitializer.class)
public class FineSessionAttributesSerializationContextInitializer extends AbstractSerializationContextInitializer {
@Override
public void registerMarshallers(SerializationContext context) {
context.registerMarshaller(new FunctionalMarshaller<>(ConcurrentSessionAttributeMapPutFunction.class, SessionAttributeMapEntryMarshaller.INSTANCE, ConcurrentSessionAttributeMapPutFunction::getOperand, ConcurrentSessionAttributeMapPutFunction::new));
context.registerMarshaller(new FunctionalScalarMarshaller<>(ConcurrentSessionAttributeMapRemoveFunction.class, Scalar.STRING.cast(String.class), ConcurrentSessionAttributeMapRemoveFunction::getOperand, ConcurrentSessionAttributeMapRemoveFunction::new));
context.registerMarshaller(new FunctionalMarshaller<>(CopyOnWriteSessionAttributeMapPutFunction.class, SessionAttributeMapEntryMarshaller.INSTANCE, CopyOnWriteSessionAttributeMapPutFunction::getOperand, CopyOnWriteSessionAttributeMapPutFunction::new));
context.registerMarshaller(new FunctionalScalarMarshaller<>(CopyOnWriteSessionAttributeMapRemoveFunction.class, Scalar.STRING.cast(String.class), CopyOnWriteSessionAttributeMapRemoveFunction::getOperand, CopyOnWriteSessionAttributeMapRemoveFunction::new));
}
}
| 2,957
| 60.625
| 264
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/CopyOnWriteSessionAttributeMapRemoveFunction.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.util.UUID;
import org.wildfly.clustering.ee.cache.function.CopyOnWriteMapRemoveFunction;
/**
* Copy-on-write {@link java.util.Map#remove(Object)} function for a session attribute.
* @author Paul Ferraro
*/
public class CopyOnWriteSessionAttributeMapRemoveFunction extends CopyOnWriteMapRemoveFunction<String, UUID> {
public CopyOnWriteSessionAttributeMapRemoveFunction(String attributeName) {
super(attributeName);
}
}
| 1,533
| 38.333333
| 110
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeMapEntryMarshaller.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
import org.infinispan.protostream.descriptors.WireType;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter;
import org.wildfly.clustering.marshalling.protostream.util.UUIDBuilder;
import org.wildfly.clustering.marshalling.protostream.util.UUIDMarshaller;
/**
* {@link ProtoStreamMarshaller} for a session attribute map entry.
* @author Paul Ferraro
*/
public enum SessionAttributeMapEntryMarshaller implements ProtoStreamMarshaller<Map.Entry<String, UUID>> {
INSTANCE;
private static final int ATTRIBUTE_NAME_INDEX = 1;
private static final int ATTRIBUTE_ID_INDEX = 2;
@Override
public Map.Entry<String, UUID> readFrom(ProtoStreamReader reader) throws IOException {
String attributeName = null;
UUIDBuilder attributeIdBuilder = UUIDMarshaller.INSTANCE.getBuilder();
while (!reader.isAtEnd()) {
int tag = reader.readTag();
int index = WireType.getTagFieldNumber(tag);
if (index == ATTRIBUTE_NAME_INDEX) {
attributeName = reader.readString();
} else if (index >= ATTRIBUTE_ID_INDEX && index < ATTRIBUTE_ID_INDEX + UUIDMarshaller.INSTANCE.getFields()) {
attributeIdBuilder = UUIDMarshaller.INSTANCE.readField(reader, index - ATTRIBUTE_ID_INDEX, attributeIdBuilder);
} else {
reader.skipField(tag);
}
}
return new SessionAttributeMapEntry(attributeName, attributeIdBuilder.build());
}
@Override
public void writeTo(ProtoStreamWriter writer, Map.Entry<String, UUID> entry) throws IOException {
writer.writeString(ATTRIBUTE_NAME_INDEX, entry.getKey());
UUIDMarshaller.INSTANCE.writeFields(writer, ATTRIBUTE_ID_INDEX, entry.getValue());
}
@Override
public Class<? extends SessionAttributeMapEntry> getJavaClass() {
return SessionAttributeMapEntry.class;
}
}
| 3,216
| 41.893333
| 127
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/CopyOnWriteSessionAttributeMapPutFunction.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.util.Map;
import java.util.UUID;
import org.wildfly.clustering.ee.cache.function.CopyOnWriteMapPutFunction;
/**
* Copy-on-write {@link Map#put(Object, Object)} function for a session attribute.
* @author Paul Ferraro
*/
public class CopyOnWriteSessionAttributeMapPutFunction extends CopyOnWriteMapPutFunction<String, UUID> {
public CopyOnWriteSessionAttributeMapPutFunction(String attributeName, UUID attributeId) {
super(new SessionAttributeMapEntry(attributeName, attributeId));
}
public CopyOnWriteSessionAttributeMapPutFunction(Map.Entry<String, UUID> operand) {
super(operand);
}
}
| 1,718
| 38.068182
| 104
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/SessionAttributeKey.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.fine;
import java.util.UUID;
import org.wildfly.clustering.ee.Key;
/**
* A key for session attribute entries, identified via session identifier and attribute identifier.
* @author Paul Ferraro
*/
public interface SessionAttributeKey extends Key<String>, Comparable<SessionAttributeKey> {
UUID getAttributeId();
@Override
default int compareTo(SessionAttributeKey key) {
int result = this.getId().compareTo(key.getId());
return (result == 0) ? this.getAttributeId().compareTo(key.getAttributeId()) : result;
}
}
| 1,624
| 36.790698
| 99
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseImmutableSessionAttributes.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.coarse;
import java.util.Map;
import java.util.Set;
import org.wildfly.clustering.web.session.ImmutableSessionAttributes;
/**
* Exposes session attributes for a coarse granularity session.
* @author Paul Ferraro
*/
public class CoarseImmutableSessionAttributes implements ImmutableSessionAttributes {
private final Map<String, Object> attributes;
public CoarseImmutableSessionAttributes(Map<String, Object> attributes) {
this.attributes = attributes;
}
@Override
public Set<String> getAttributeNames() {
return this.attributes.keySet();
}
@Override
public Object getAttribute(String name) {
return this.attributes.get(name);
}
}
| 1,770
| 34.42
| 85
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/coarse/CoarseSessionAttributes.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.session.coarse;
import java.io.NotSerializableException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.wildfly.clustering.ee.Immutability;
import org.wildfly.clustering.ee.Mutator;
import org.wildfly.clustering.ee.cache.CacheProperties;
import org.wildfly.clustering.marshalling.spi.Marshallability;
import org.wildfly.clustering.web.cache.session.SessionActivationNotifier;
import org.wildfly.clustering.web.cache.session.SessionAttributes;
/**
* Exposes session attributes for a coarse granularity session.
* @author Paul Ferraro
*/
public class CoarseSessionAttributes extends CoarseImmutableSessionAttributes implements SessionAttributes {
private final Map<String, Object> attributes;
private final Mutator mutator;
private final Marshallability marshallability;
private final Immutability immutability;
private final CacheProperties properties;
private final SessionActivationNotifier notifier;
private final AtomicBoolean dirty = new AtomicBoolean(false);
public CoarseSessionAttributes(Map<String, Object> attributes, Mutator mutator, Marshallability marshallability, Immutability immutability, CacheProperties properties, SessionActivationNotifier notifier) {
super(attributes);
this.attributes = attributes;
this.mutator = mutator;
this.marshallability = marshallability;
this.immutability = immutability;
this.properties = properties;
this.notifier = notifier;
if (this.notifier != null) {
this.notifier.postActivate();
}
}
@Override
public Object removeAttribute(String name) {
Object value = this.attributes.remove(name);
if (value != null) {
this.dirty.set(true);
}
return value;
}
@Override
public Object setAttribute(String name, Object value) {
if (value == null) {
return this.removeAttribute(name);
}
if (this.properties.isMarshalling() && !this.marshallability.isMarshallable(value)) {
throw new IllegalArgumentException(new NotSerializableException(value.getClass().getName()));
}
Object old = this.attributes.put(name, value);
// Always trigger mutation, even if this is an immutable object that was previously retrieved via getAttribute(...)
this.dirty.set(true);
return old;
}
@Override
public Object getAttribute(String name) {
Object value = this.attributes.get(name);
if (!this.immutability.test(value)) {
this.dirty.set(true);
}
return value;
}
@Override
public void close() {
if (this.notifier != null) {
this.notifier.prePassivate();
}
if (this.dirty.compareAndSet(true, false)) {
this.mutator.mutate();
}
}
}
| 3,952
| 37.378641
| 209
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/routing/LocalRouteLocator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.routing;
import org.wildfly.clustering.web.routing.RouteLocator;
/**
* Route locator that always returns the route of the local member.
* @author Paul Ferraro
*/
public class LocalRouteLocator implements RouteLocator {
private final String route;
public LocalRouteLocator(String route) {
this.route = route;
}
@Override
public String locate(String sessionId) {
return this.route;
}
}
| 1,497
| 33.045455
| 70
|
java
|
null |
wildfly-main/clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/routing/NullRouteLocator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.cache.routing;
import org.wildfly.clustering.web.routing.RouteLocator;
/**
* Route locator that always returns {@code null}.
* @author Paul Ferraro
*/
public class NullRouteLocator implements RouteLocator {
@Override
public String locate(String sessionId) {
return null;
}
}
| 1,360
| 34.815789
| 70
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/TestIdentifierSerializerProvider.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod;
import java.nio.ByteBuffer;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.marshalling.spi.Marshaller;
import org.wildfly.clustering.web.IdentifierMarshaller;
import org.wildfly.clustering.web.IdentifierMarshallerProvider;
/**
* @author Paul Ferraro
*/
@MetaInfServices(IdentifierMarshallerProvider.class)
public class TestIdentifierSerializerProvider implements IdentifierMarshallerProvider {
@Override
public Marshaller<String, ByteBuffer> getMarshaller() {
return IdentifierMarshaller.ISO_LATIN_1;
}
}
| 1,617
| 36.627907
| 87
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/SessionCreationMetaDataKeyMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.session;
import java.io.IOException;
import org.junit.Test;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
/**
* Unit test for {@link SessionCreationMetaDataKeyResolver}.
* @author Paul Ferraro
*/
public class SessionCreationMetaDataKeyMarshallerTestCase {
@Test
public void test() throws IOException {
SessionCreationMetaDataKey key = new SessionCreationMetaDataKey("ABC123");
ProtoStreamTesterFactory.INSTANCE.createTester().test(key);
}
}
| 1,576
| 36.547619
| 82
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/SessionAccessMetaDataKeyMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.session;
import java.io.IOException;
import org.junit.Test;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
/**
* Unit test for {@link SessionAccessMetaDataKeyResolver}.
* @author Paul Ferraro
*/
public class SessionAccessMetaDataKeyMarshallerTestCase {
@Test
public void test() throws IOException {
SessionAccessMetaDataKey key = new SessionAccessMetaDataKey("test");
ProtoStreamTesterFactory.INSTANCE.createTester().test(key);
}
}
| 1,566
| 36.309524
| 79
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeKeyMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.session.fine;
import java.io.IOException;
import java.util.UUID;
import org.junit.Test;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
/**
* Unit test for {@link SessionAttributeKeyResolver}.
* @author Paul Ferraro
*/
public class SessionAttributeKeyMarshallerTestCase {
@Test
public void test() throws IOException {
SessionAttributeKey key = new SessionAttributeKey("test", UUID.randomUUID());
ProtoStreamTesterFactory.INSTANCE.createTester().test(key);
}
}
| 1,593
| 36.069767
| 85
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/fine/SessionAttributeNamesKeyMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.session.fine;
import java.io.IOException;
import org.junit.Test;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
/**
* Unit test for {@link SessionAttributeNamesKeyResolver}.
* @author Paul Ferraro
*/
public class SessionAttributeNamesKeyMarshallerTestCase {
@Test
public void test() throws IOException {
SessionAttributeNamesKey key = new SessionAttributeNamesKey("test");
ProtoStreamTesterFactory.INSTANCE.createTester().test(key);
}
}
| 1,571
| 36.428571
| 79
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/test/java/org/wildfly/clustering/web/hotrod/session/coarse/SessionAttributesKeyMarshallerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.session.coarse;
import java.io.IOException;
import org.junit.Test;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory;
/**
* Unit test for {@link SessionAttributesKeyExternalizer}.
* @author Paul Ferraro
*/
public class SessionAttributesKeyMarshallerTestCase {
@Test
public void test() throws IOException {
SessionAttributesKey key = new SessionAttributesKey("test");
ProtoStreamTesterFactory.INSTANCE.createTester().test(key);
}
}
| 1,561
| 36.190476
| 79
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/sso/SSOSerializationContextInitializer.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.sso;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer;
import org.wildfly.clustering.web.cache.SessionKeyMarshaller;
/**
* @author Paul Ferraro
*/
@MetaInfServices(SerializationContextInitializer.class)
public class SSOSerializationContextInitializer extends AbstractSerializationContextInitializer {
@Override
public void registerMarshallers(SerializationContext context) {
context.registerMarshaller(new SessionKeyMarshaller<>(AuthenticationKey.class, AuthenticationKey::new));
}
}
| 1,779
| 41.380952
| 112
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/sso/HotRodSSOFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.sso;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import org.infinispan.client.hotrod.RemoteCache;
import org.wildfly.clustering.marshalling.spi.Marshaller;
import org.wildfly.clustering.web.LocalContextFactory;
import org.wildfly.clustering.web.cache.sso.AuthenticationEntry;
import org.wildfly.clustering.web.cache.sso.CompositeSSO;
import org.wildfly.clustering.web.cache.sso.SSOFactory;
import org.wildfly.clustering.web.cache.sso.SessionsFactory;
import org.wildfly.clustering.web.hotrod.logging.Logger;
import org.wildfly.clustering.web.sso.SSO;
import org.wildfly.clustering.web.sso.Sessions;
/**
* @author Paul Ferraro
*/
public class HotRodSSOFactory<AV, SV, A, D, S, L> implements SSOFactory<Map.Entry<A, AtomicReference<L>>, SV, A, D, S, L> {
private final SessionsFactory<SV, D, S> sessionsFactory;
private final RemoteCache<AuthenticationKey, AuthenticationEntry<AV, L>> cache;
private final Marshaller<A, AV> marshaller;
private final LocalContextFactory<L> localContextFactory;
public HotRodSSOFactory(RemoteCache<AuthenticationKey, AuthenticationEntry<AV, L>> cache, Marshaller<A, AV> marshaller, LocalContextFactory<L> localContextFactory, SessionsFactory<SV, D, S> sessionsFactory) {
this.cache = cache;
this.marshaller = marshaller;
this.localContextFactory = localContextFactory;
this.sessionsFactory = sessionsFactory;
}
@Override
public SSO<A, D, S, L> createSSO(String id, Map.Entry<Map.Entry<A, AtomicReference<L>>, SV> value) {
Map.Entry<A, AtomicReference<L>> authenticationEntry = value.getKey();
Sessions<D, S> sessions = this.sessionsFactory.createSessions(id, value.getValue());
return new CompositeSSO<>(id, authenticationEntry.getKey(), sessions, authenticationEntry.getValue(), this.localContextFactory, this);
}
@Override
public Map.Entry<Map.Entry<A, AtomicReference<L>>, SV> createValue(String id, A authentication) {
try {
AuthenticationEntry<AV, L> entry = new AuthenticationEntry<>(this.marshaller.write(authentication));
this.cache.put(new AuthenticationKey(id), entry);
SV sessions = this.sessionsFactory.createValue(id, null);
return new AbstractMap.SimpleImmutableEntry<>(new AbstractMap.SimpleImmutableEntry<>(authentication, entry.getLocalContext()), sessions);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
public Map.Entry<Map.Entry<A, AtomicReference<L>>, SV> findValue(String id) {
AuthenticationEntry<AV, L> entry = this.cache.get(new AuthenticationKey(id));
if (entry != null) {
SV sessions = this.sessionsFactory.findValue(id);
if (sessions != null) {
try {
A authentication = this.marshaller.read(entry.getAuthentication());
return new AbstractMap.SimpleImmutableEntry<>(new AbstractMap.SimpleImmutableEntry<>(authentication, entry.getLocalContext()), sessions);
} catch (IOException e) {
Logger.ROOT_LOGGER.failedToActivateAuthentication(e, id);
this.remove(id);
}
}
}
return null;
}
@Override
public boolean remove(String id) {
this.cache.remove(new AuthenticationKey(id));
this.sessionsFactory.remove(id);
return true;
}
@Override
public SessionsFactory<SV, D, S> getSessionsFactory() {
return this.sessionsFactory;
}
}
| 4,723
| 43.149533
| 212
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/sso/HotRodSSOManagerFactoryConfiguration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.sso;
import org.infinispan.client.hotrod.RemoteCache;
/**
* @author Paul Ferraro
*/
public interface HotRodSSOManagerFactoryConfiguration {
<K, V> RemoteCache<K, V> getRemoteCache();
}
| 1,259
| 37.181818
| 70
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/sso/HotRodSSOManagerFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.sso;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import org.wildfly.clustering.ee.Batcher;
import org.wildfly.clustering.ee.cache.IdentifierFactory;
import org.wildfly.clustering.ee.cache.SimpleIdentifierFactory;
import org.wildfly.clustering.ee.cache.tx.TransactionBatch;
import org.wildfly.clustering.ee.hotrod.tx.HotRodBatcher;
import org.wildfly.clustering.marshalling.spi.ByteBufferMarshalledValueFactory;
import org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller;
import org.wildfly.clustering.marshalling.spi.MarshalledValue;
import org.wildfly.clustering.marshalling.spi.MarshalledValueMarshaller;
import org.wildfly.clustering.marshalling.spi.Marshaller;
import org.wildfly.clustering.web.cache.sso.CompositeSSOManager;
import org.wildfly.clustering.web.cache.sso.SSOFactory;
import org.wildfly.clustering.web.cache.sso.SessionsFactory;
import org.wildfly.clustering.web.hotrod.sso.coarse.CoarseSessionsFactory;
import org.wildfly.clustering.web.sso.SSOManager;
import org.wildfly.clustering.web.sso.SSOManagerConfiguration;
import org.wildfly.clustering.web.sso.SSOManagerFactory;
/**
* @author Paul Ferraro
*/
public class HotRodSSOManagerFactory<A, D, S> implements SSOManagerFactory<A, D, S, TransactionBatch> {
private final HotRodSSOManagerFactoryConfiguration configuration;
public HotRodSSOManagerFactory(HotRodSSOManagerFactoryConfiguration configuration) {
this.configuration = configuration;
}
@Override
public <L> SSOManager<A, D, S, L, TransactionBatch> createSSOManager(SSOManagerConfiguration<L> config) {
SessionsFactory<Map<D, S>, D, S> sessionsFactory = new CoarseSessionsFactory<>(this.configuration.getRemoteCache());
Marshaller<A, MarshalledValue<A, ByteBufferMarshaller>> marshaller = new MarshalledValueMarshaller<>(new ByteBufferMarshalledValueFactory(config.getMarshaller()));
SSOFactory<Map.Entry<A, AtomicReference<L>>, Map<D, S>, A, D, S, L> factory = new HotRodSSOFactory<>(this.configuration.getRemoteCache(), marshaller, config.getLocalContextFactory(), sessionsFactory);
IdentifierFactory<String> identifierFactory = new SimpleIdentifierFactory<>(config.getIdentifierFactory());
Batcher<TransactionBatch> batcher = new HotRodBatcher(this.configuration.getRemoteCache());
return new CompositeSSOManager<>(factory, identifierFactory, batcher);
}
}
| 3,480
| 50.955224
| 208
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/sso/AuthenticationKey.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.sso;
import org.wildfly.clustering.ee.hotrod.RemoteCacheKey;
/**
* @author Paul Ferraro
*/
public class AuthenticationKey extends RemoteCacheKey<String> {
public AuthenticationKey(String id) {
super(id);
}
}
| 1,295
| 35
| 70
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/sso/coarse/SessionsFilter.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.sso.coarse;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* Filter/mapper that handles filtering and casting for cache entries containing SSO sessions.
* @author Paul Ferraro
*/
public class SessionsFilter<D, S> implements Predicate<Map.Entry<?, ?>>, Function<Map.Entry<?, ?>, Map.Entry<CoarseSessionsKey, Map<D, S>>> {
@SuppressWarnings("unchecked")
@Override
public Map.Entry<CoarseSessionsKey, Map<D, S>> apply(Map.Entry<?, ?> entry) {
return (Map.Entry<CoarseSessionsKey, Map<D, S>>) entry;
}
@Override
public boolean test(Map.Entry<?, ?> entry) {
return (entry.getKey() instanceof CoarseSessionsKey);
}
}
| 1,780
| 37.717391
| 141
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/sso/coarse/CoarseSessionsFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.sso.coarse;
import java.util.AbstractMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
import org.infinispan.client.hotrod.Flag;
import org.infinispan.client.hotrod.RemoteCache;
import org.wildfly.clustering.ee.Mutator;
import org.wildfly.clustering.ee.hotrod.RemoteCacheEntryMutator;
import org.wildfly.clustering.web.cache.sso.SessionsFactory;
import org.wildfly.clustering.web.cache.sso.coarse.CoarseSessions;
import org.wildfly.clustering.web.cache.sso.coarse.SessionFilter;
import org.wildfly.clustering.web.sso.Sessions;
/**
* @author Paul Ferraro
*/
public class CoarseSessionsFactory<D, S> implements SessionsFactory<Map<D, S>, D, S> {
private final SessionsFilter<D, S> filter = new SessionsFilter<>();
private final RemoteCache<CoarseSessionsKey, Map<D, S>> cache;
public CoarseSessionsFactory(RemoteCache<CoarseSessionsKey, Map<D, S>> cache) {
this.cache = cache;
}
@Override
public Sessions<D, S> createSessions(String ssoId, Map<D, S> value) {
CoarseSessionsKey key = new CoarseSessionsKey(ssoId);
Mutator mutator = new RemoteCacheEntryMutator<>(this.cache, key, value);
return new CoarseSessions<>(value, mutator);
}
@Override
public Map<D, S> createValue(String id, Void context) {
Map<D, S> sessions = new ConcurrentHashMap<>();
this.cache.put(new CoarseSessionsKey(id), sessions);
return sessions;
}
@Override
public Map<D, S> findValue(String id) {
return this.cache.get(new CoarseSessionsKey(id));
}
@Override
public Map.Entry<String, Map<D, S>> findEntryContaining(S session) {
SessionFilter<CoarseSessionsKey, D, S> filter = new SessionFilter<>(session);
// Erase type to handle compilation issues with generics
// Our filter will handle type safety and casting
@SuppressWarnings("rawtypes")
RemoteCache cache = this.cache;
try (Stream<Map.Entry<?, ?>> stream = cache.entrySet().stream()) {
Map.Entry<CoarseSessionsKey, Map<D, S>> entry = stream.filter(this.filter).map(this.filter).filter(filter).findAny().orElse(null);
return (entry != null) ? new AbstractMap.SimpleImmutableEntry<>(entry.getKey().getId(), entry.getValue()) : null;
}
}
@Override
public boolean remove(String id) {
return this.cache.withFlags(Flag.FORCE_RETURN_VALUE).remove(new CoarseSessionsKey(id)) != null;
}
}
| 3,568
| 39.556818
| 142
|
java
|
null |
wildfly-main/clustering/web/hotrod/src/main/java/org/wildfly/clustering/web/hotrod/sso/coarse/CoarseSessionsKey.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.web.hotrod.sso.coarse;
import org.wildfly.clustering.ee.hotrod.RemoteCacheKey;
/**
* @author Paul Ferraro
*/
public class CoarseSessionsKey extends RemoteCacheKey<String> {
public CoarseSessionsKey(String id) {
super(id);
}
}
| 1,302
| 35.194444
| 70
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.