"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "clustering/web/cache/src/main/java/org/wildfly/clustering/web/cache/session/fine/FineSessionAttributes.java" between
wildfly-21.0.0.Final-src.zip and wildfly-21.0.1.Final-src.zip

About: WildFly is an application server with a standards-compliant, fast and lightweight implementation of the Java Enterprise Edition 7 Platform specifications (formerly known as JBoss community version). Sources.

FineSessionAttributes.java  (wildfly-21.0.0.Final-src):FineSessionAttributes.java  (wildfly-21.0.1.Final-src)
skipping to change at line 27 skipping to change at line 27
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free * License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/ */
package org.wildfly.clustering.web.cache.session.fine; package org.wildfly.clustering.web.cache.session.fine;
import java.io.IOException; import java.io.IOException;
import java.io.NotSerializableException; import java.io.NotSerializableException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function; import java.util.function.Function;
import org.wildfly.clustering.ee.Immutability; import org.wildfly.clustering.ee.Immutability;
import org.wildfly.clustering.ee.MutatorFactory; import org.wildfly.clustering.ee.MutatorFactory;
import org.wildfly.clustering.ee.cache.CacheProperties; import org.wildfly.clustering.ee.cache.CacheProperties;
import org.wildfly.clustering.ee.cache.function.ConcurrentMapPutFunction; import org.wildfly.clustering.ee.cache.function.ConcurrentMapPutFunction;
import org.wildfly.clustering.ee.cache.function.ConcurrentMapRemoveFunction; import org.wildfly.clustering.ee.cache.function.ConcurrentMapRemoveFunction;
import org.wildfly.clustering.ee.cache.function.CopyOnWriteMapPutFunction; import org.wildfly.clustering.ee.cache.function.CopyOnWriteMapPutFunction;
import org.wildfly.clustering.ee.cache.function.CopyOnWriteMapRemoveFunction; import org.wildfly.clustering.ee.cache.function.CopyOnWriteMapRemoveFunction;
skipping to change at line 55 skipping to change at line 55
/** /**
* Exposes session attributes for fine granularity sessions. * Exposes session attributes for fine granularity sessions.
* @author Paul Ferraro * @author Paul Ferraro
*/ */
public class FineSessionAttributes<NK, K, V> implements SessionAttributes { public class FineSessionAttributes<NK, K, V> implements SessionAttributes {
private final NK key; private final NK key;
private final Map<NK, Map<String, UUID>> namesCache; private final Map<NK, Map<String, UUID>> namesCache;
private final Function<UUID, K> keyFactory; private final Function<UUID, K> keyFactory;
private final Map<K, V> attributeCache; private final Map<K, V> attributeCache;
private final Map<K, Optional<Object>> mutations = new ConcurrentHashMap<>() ; private final Map<K, Optional<Object>> mutations = new HashMap<>();
private final Marshaller<Object, V> marshaller; private final Marshaller<Object, V> marshaller;
private final MutatorFactory<K, V> mutatorFactory; private final MutatorFactory<K, V> mutatorFactory;
private final Immutability immutability; private final Immutability immutability;
private final CacheProperties properties; private final CacheProperties properties;
private final SessionAttributeActivationNotifier notifier; private final SessionAttributeActivationNotifier notifier;
private volatile Map<String, UUID> names; private volatile Map<String, UUID> names;
public FineSessionAttributes(NK key, Map<String, UUID> names, Map<NK, Map<St ring, UUID>> namesCache, Function<UUID, K> keyFactory, Map<K, V> attributeCache, Marshaller<Object, V> marshaller, MutatorFactory<K, V> mutatorFactory, Immutabi lity immutability, CacheProperties properties, SessionAttributeActivationNotifie r notifier) { public FineSessionAttributes(NK key, Map<String, UUID> names, Map<NK, Map<St ring, UUID>> namesCache, Function<UUID, K> keyFactory, Map<K, V> attributeCache, Marshaller<Object, V> marshaller, MutatorFactory<K, V> mutatorFactory, Immutabi lity immutability, CacheProperties properties, SessionAttributeActivationNotifie r notifier) {
this.key = key; this.key = key;
skipping to change at line 82 skipping to change at line 82
this.immutability = immutability; this.immutability = immutability;
this.properties = properties; this.properties = properties;
this.notifier = notifier; this.notifier = notifier;
} }
@Override @Override
public Object removeAttribute(String name) { public Object removeAttribute(String name) {
UUID attributeId = this.names.get(name); UUID attributeId = this.names.get(name);
if (attributeId == null) return null; if (attributeId == null) return null;
this.setNames(this.namesCache.compute(this.key, this.properties.isTransa synchronized (this.mutations) {
ctional() ? new CopyOnWriteMapRemoveFunction<>(name) : new ConcurrentMapRemoveFu this.setNames(this.namesCache.compute(this.key, this.properties.isTr
nction<>(name))); ansactional() ? new CopyOnWriteMapRemoveFunction<>(name) : new ConcurrentMapRemo
veFunction<>(name)));
K key = this.keyFactory.apply(attributeId); K key = this.keyFactory.apply(attributeId);
Object result = this.read(this.attributeCache.remove(key));
if (result != null) { Object result = this.read(this.attributeCache.remove(key));
this.mutations.remove(key); if (result != null) {
if (this.properties.isPersistent()) { this.mutations.remove(key);
this.notifier.postActivate(result);
if (this.properties.isPersistent()) {
this.notifier.postActivate(result);
}
} }
return result;
} }
return result;
} }
@Override @Override
public Object setAttribute(String name, Object attribute) { public Object setAttribute(String name, Object attribute) {
if (attribute == null) { if (attribute == null) {
return this.removeAttribute(name); return this.removeAttribute(name);
} }
if (this.properties.isMarshalling() && !this.marshaller.isMarshallable(a ttribute)) { if (this.properties.isMarshalling() && !this.marshaller.isMarshallable(a ttribute)) {
throw new IllegalArgumentException(new NotSerializableException(attr ibute.getClass().getName())); throw new IllegalArgumentException(new NotSerializableException(attr ibute.getClass().getName()));
} }
UUID attributeId = this.names.get(name); UUID attributeId = this.names.get(name);
if (attributeId == null) {
UUID newAttributeId = createUUID();
this.setNames(this.namesCache.compute(this.key, this.properties.isTr
ansactional() ? new CopyOnWriteMapPutFunction<>(name, newAttributeId) : new Conc
urrentMapPutFunction<>(name, newAttributeId)));
attributeId = this.names.get(name);
}
K key = this.keyFactory.apply(attributeId); synchronized (this.mutations) {
V value = this.write(attribute); if (attributeId == null) {
UUID newAttributeId = createUUID();
this.setNames(this.namesCache.compute(this.key, this.properties.
isTransactional() ? new CopyOnWriteMapPutFunction<>(name, newAttributeId) : new
ConcurrentMapPutFunction<>(name, newAttributeId)));
attributeId = this.names.get(name);
}
if (this.properties.isPersistent()) { K key = this.keyFactory.apply(attributeId);
this.notifier.prePassivate(attribute); V value = this.write(attribute);
}
Object result = this.read(this.attributeCache.put(key, value)); if (this.properties.isPersistent()) {
this.notifier.prePassivate(attribute);
}
if (this.properties.isPersistent()) { Object result = this.read(this.attributeCache.put(key, value));
this.notifier.postActivate(attribute);
if (result != attribute) { if (this.properties.isTransactional()) {
this.notifier.postActivate(result); // Add an empty value to prevent any subsequent mutable getAttri
bute(...) 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 mutat
ion on close
if (this.immutability.test(attribute)) {
this.mutations.remove(key);
} else {
this.mutations.put(key, Optional.of(attribute));
}
} }
}
if (this.properties.isTransactional()) { if (this.properties.isPersistent()) {
// Add an empty value to prevent any subsequent mutable getAttribute this.notifier.postActivate(attribute);
(...) from triggering a redundant mutation on close.
this.mutations.put(key, Optional.empty()); if (result != attribute) {
} else { this.notifier.postActivate(result);
// 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));
} }
return result;
} }
return result;
} }
@Override @Override
public Object getAttribute(String name) { public Object getAttribute(String name) {
UUID attributeId = this.names.get(name); UUID attributeId = this.names.get(name);
if (attributeId == null) return null; if (attributeId == null) return null;
K key = this.keyFactory.apply(attributeId); synchronized (this.mutations) {
K key = this.keyFactory.apply(attributeId);
// Return mutable value if present, this preserves referential integrity // Return mutable value if present, this preserves referential integ
when this member is not an owner. rity when this member is not an owner.
Optional<Object> mutableValue = this.mutations.get(key); Optional<Object> mutableValue = this.mutations.get(key);
if ((mutableValue != null) && mutableValue.isPresent()) { if ((mutableValue != null) && mutableValue.isPresent()) {
return mutableValue.get(); return mutableValue.get();
} }
V value = this.attributeCache.get(key); Object result = this.read(this.attributeCache.get(key));
Object result = this.read(value); if (result != null) {
if (result != null) { if (this.properties.isPersistent()) {
if (this.properties.isPersistent()) { this.notifier.postActivate(result);
this.notifier.postActivate(result); }
}
// If the object is mutable, we need to trigger a mutation on cl
// If the object is mutable, we need to trigger a mutation on close ose
if (!this.immutability.test(result)) { if (!this.immutability.test(result)) {
this.mutations.putIfAbsent(key, Optional.of(result)); this.mutations.putIfAbsent(key, Optional.of(result));
}
} }
return result;
} }
return result;
} }
@Override @Override
public Set<String> getAttributeNames() { public Set<String> getAttributeNames() {
return this.names.keySet(); return this.names.keySet();
} }
@Override @Override
public void close() { public void close() {
this.notifier.close(); this.notifier.close();
synchronized (this.mutations) {
for (Map.Entry<K, Optional<Object>> entry : this.mutations.entrySet()) { for (Map.Entry<K, Optional<Object>> entry : this.mutations.entrySet(
Optional<Object> optional = entry.getValue(); )) {
if (optional.isPresent()) { Optional<Object> optional = entry.getValue();
K key = entry.getKey(); if (optional.isPresent()) {
V value = this.write(optional.get()); K key = entry.getKey();
this.mutatorFactory.createMutator(key, value).mutate(); V value = this.write(optional.get());
this.mutatorFactory.createMutator(key, value).mutate();
}
} }
this.mutations.clear();
} }
this.mutations.clear();
} }
private void setNames(Map<String, UUID> names) { private void setNames(Map<String, UUID> names) {
this.names = (names != null) ? Collections.unmodifiableMap(names) : Coll ections.emptyMap(); this.names = (names != null) ? Collections.unmodifiableMap(names) : Coll ections.emptyMap();
} }
private V write(Object value) { private V write(Object value) {
try { try {
return this.marshaller.write(value); return this.marshaller.write(value);
} catch (IOException e) { } catch (IOException e) {
 End of changes. 24 change blocks. 
69 lines changed or deleted 81 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)