Implement non-behavior changing fixes.
Format source code. Edit Javadoc.
This commit is contained in:
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.session.data.gemfire.serialization.data;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.geode.DataSerializer;
|
||||
@@ -30,7 +30,13 @@ import org.springframework.session.data.gemfire.serialization.SerializationExcep
|
||||
import org.springframework.session.data.gemfire.serialization.SessionSerializer;
|
||||
|
||||
/**
|
||||
* The {@link AbstractDataSerializableSessionSerializer} class...
|
||||
* The {@link AbstractDataSerializableSessionSerializer} class is an abstract base class encapsulating and implementing
|
||||
* operations common to all Apache Geode/Pivotal GemFire {@link DataSerializer} and Spring Session
|
||||
* {@link SessionSerializer} implementations.
|
||||
*
|
||||
* This class is also an implementation of the {@literal Template Software Design Pattern}, providing a default
|
||||
* implementations of the {@link DataSerializer#toData(Object, DataOutput)} and {@link DataSerializer#fromData(DataInput)}
|
||||
* methods.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.io.DataInput
|
||||
@@ -44,16 +50,33 @@ public abstract class AbstractDataSerializableSessionSerializer<T> extends DataS
|
||||
|
||||
protected static final boolean DEFAULT_ALLOW_JAVA_SERIALIZATION = true;
|
||||
|
||||
/**
|
||||
* Returns the identifier for this {@link DataSerializer}.
|
||||
*
|
||||
* @return the identifier for this {@link DataSerializer}.
|
||||
*/
|
||||
@Override
|
||||
public int getId() {
|
||||
return 0x0A11ACE5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Class types} supported and handled by this {@link DataSerializer} during de/serialization.
|
||||
*
|
||||
* @return the {@link Class types} supported and handled by this {@link DataSerializer} during de/serialization.
|
||||
* @see java.lang.Class
|
||||
*/
|
||||
@Override
|
||||
public Class<?>[] getSupportedClasses() {
|
||||
return new Class[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether Java Serialization is allowed during de/serialization when using this {@link DataSerializer}.
|
||||
*
|
||||
* @return a boolean value indicating whether Java Serialization is allowed during de/serialization
|
||||
* when using this {@link DataSerializer}.
|
||||
*/
|
||||
protected boolean allowJavaSerialization() {
|
||||
return DEFAULT_ALLOW_JAVA_SERIALIZATION;
|
||||
}
|
||||
@@ -85,18 +108,20 @@ public abstract class AbstractDataSerializableSessionSerializer<T> extends DataS
|
||||
}
|
||||
|
||||
public <T> T deserializeObject(DataInput in) throws ClassNotFoundException, IOException {
|
||||
return DataSerializer.readObject(in);
|
||||
return readObject(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean canSerialize(Class<?> type) {
|
||||
return stream(nullSafeArray(getSupportedClasses(), Class.class))
|
||||
|
||||
return Arrays.stream(nullSafeArray(getSupportedClasses(), Class.class))
|
||||
.filter(it -> type != null)
|
||||
.anyMatch(supportedClass -> supportedClass.isAssignableFrom(type));
|
||||
}
|
||||
|
||||
protected <T> T safeRead(DataInput in, DataInputReader<T> reader) {
|
||||
|
||||
try {
|
||||
return reader.doRead(in);
|
||||
}
|
||||
@@ -106,6 +131,7 @@ public abstract class AbstractDataSerializableSessionSerializer<T> extends DataS
|
||||
}
|
||||
|
||||
protected void safeWrite(DataOutput out, DataOutputWriter writer) {
|
||||
|
||||
try {
|
||||
writer.doWrite(out);
|
||||
}
|
||||
@@ -114,10 +140,12 @@ public abstract class AbstractDataSerializableSessionSerializer<T> extends DataS
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface DataInputReader<T> {
|
||||
T doRead(DataInput in) throws ClassNotFoundException, IOException;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface DataOutputWriter {
|
||||
void doWrite(DataOutput out) throws IOException;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.geode.DataSerializer;
|
||||
|
||||
import org.springframework.session.Session;
|
||||
import org.springframework.session.data.gemfire.serialization.SessionSerializer;
|
||||
import org.springframework.session.data.gemfire.serialization.data.AbstractDataSerializableSessionSerializer;
|
||||
@@ -35,9 +37,10 @@ import org.springframework.session.data.gemfire.serialization.data.AbstractDataS
|
||||
* framework.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.io.DataInput
|
||||
* @see java.io.DataOutput
|
||||
* @see org.apache.geode.DataSerializer
|
||||
* @see org.springframework.session.Session
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.DeltaCapableGemFireSessionAttributes
|
||||
* @see org.springframework.session.data.gemfire.serialization.SessionSerializer
|
||||
* @see org.springframework.session.data.gemfire.serialization.data.AbstractDataSerializableSessionSerializer
|
||||
* @since 2.0.0
|
||||
@@ -46,22 +49,40 @@ import org.springframework.session.data.gemfire.serialization.data.AbstractDataS
|
||||
public class DataSerializableSessionAttributesSerializer
|
||||
extends AbstractDataSerializableSessionSerializer<GemFireSessionAttributes> {
|
||||
|
||||
/**
|
||||
* Register custom Spring Session {@link DataSerializer DataSerializers} with Apache Geode/Pivotal GemFire
|
||||
* to handle de/serialization of Spring Session, {@link Session} attribute types.
|
||||
*
|
||||
* @see org.apache.geode.DataSerializer#register(Class)
|
||||
*/
|
||||
public static void register() {
|
||||
register(DataSerializableSessionAttributesSerializer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier for this {@link DataSerializer}.
|
||||
*
|
||||
* @return the identifier for this {@link DataSerializer}.
|
||||
*/
|
||||
@Override
|
||||
public int getId() {
|
||||
return 0x8192ACE5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Class types} supported and handled by this {@link DataSerializer} during de/serialization.
|
||||
*
|
||||
* @return the {@link Class types} supported and handled by this {@link DataSerializer} during de/serialization.
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.DeltaCapableGemFireSessionAttributes
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSessionAttributes
|
||||
* @see java.lang.Class
|
||||
*/
|
||||
@Override
|
||||
public Class<?>[] getSupportedClasses() {
|
||||
return asArray(GemFireSessionAttributes.class, DeltaCapableGemFireSessionAttributes.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
//@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
|
||||
public void serialize(GemFireSessionAttributes sessionAttributes, DataOutput out) {
|
||||
|
||||
synchronized (sessionAttributes) {
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.geode.DataSerializer;
|
||||
|
||||
import org.springframework.session.Session;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.DeltaCapableGemFireSession;
|
||||
import org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSession;
|
||||
@@ -41,7 +43,10 @@ import org.springframework.util.StringUtils;
|
||||
* @author John Blum
|
||||
* @see java.io.DataInput
|
||||
* @see java.io.DataOutput
|
||||
* @see org.apache.geode.DataSerializer
|
||||
* @see org.springframework.session.Session
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.GemFireSession
|
||||
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository.DeltaCapableGemFireSession
|
||||
* @see org.springframework.session.data.gemfire.serialization.SessionSerializer
|
||||
* @see org.springframework.session.data.gemfire.serialization.data.AbstractDataSerializableSessionSerializer
|
||||
* @since 2.0.0
|
||||
@@ -49,23 +54,42 @@ import org.springframework.util.StringUtils;
|
||||
@SuppressWarnings("unused")
|
||||
public class DataSerializableSessionSerializer extends AbstractDataSerializableSessionSerializer<GemFireSession> {
|
||||
|
||||
/**
|
||||
* Register custom Spring Session {@link DataSerializer DataSerializers} with Apache Geode/Pivotal GemFire
|
||||
* to handle de/serialization of Spring Session, {@link Session} and {@link Session} attribute types.
|
||||
*
|
||||
* @see org.springframework.session.data.gemfire.serialization.data.provider.DataSerializableSessionAttributesSerializer#register()
|
||||
* @see org.apache.geode.DataSerializer#register(Class)
|
||||
*/
|
||||
public static void register() {
|
||||
register(DataSerializableSessionSerializer.class);
|
||||
DataSerializableSessionAttributesSerializer.register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier for this {@link DataSerializer}.
|
||||
*
|
||||
* @return the identifier for this {@link DataSerializer}.
|
||||
*/
|
||||
@Override
|
||||
public int getId() {
|
||||
return 0x4096ACE5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Class types} supported and handled by this {@link DataSerializer} during de/serialization.
|
||||
*
|
||||
* @return the {@link Class types} supported and handled by this {@link DataSerializer} during de/serialization.
|
||||
* @see DeltaCapableGemFireSession
|
||||
* @see GemFireSession
|
||||
* @see java.lang.Class
|
||||
*/
|
||||
@Override
|
||||
public Class<?>[] getSupportedClasses() {
|
||||
return asArray(GemFireSession.class, DeltaCapableGemFireSession.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
//@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
|
||||
public void serialize(GemFireSession session, DataOutput out) {
|
||||
|
||||
synchronized (session) {
|
||||
@@ -77,7 +101,7 @@ public class DataSerializableSessionSerializer extends AbstractDataSerializableS
|
||||
|
||||
String principalName = session.getPrincipalName();
|
||||
|
||||
int length = (StringUtils.hasText(principalName) ? principalName.length() : 0);
|
||||
int length = StringUtils.hasText(principalName) ? principalName.length() : 0;
|
||||
|
||||
safeWrite(out, output -> output.writeInt(length));
|
||||
|
||||
@@ -85,10 +109,10 @@ public class DataSerializableSessionSerializer extends AbstractDataSerializableS
|
||||
safeWrite(out, output -> output.writeUTF(principalName));
|
||||
}
|
||||
|
||||
safeWrite(out, output -> serializeObject(session.getAttributes(), out));
|
||||
safeWrite(out, output -> serializeObject(session.getAttributes(), output));
|
||||
|
||||
session.clearDelta();
|
||||
session.getAttributes().clearDelta();
|
||||
session.clearDelta();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user