Fixed - codec classLoader wasn't used in TasksRunnerService. #1310

pull/1336/head
Nikita 7 years ago
parent d754bec54f
commit ac79efe2af

@ -150,4 +150,9 @@ public class LocalCachedMessageCodec implements Codec {
return encoder;
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
}

@ -0,0 +1,53 @@
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.client.codec;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
/**
*
* @author Nikita Koksharov
*
*/
public abstract class BaseCodec implements Codec {
@Override
public Decoder<Object> getMapValueDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapValueEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getMapKeyDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapKeyEncoder() {
return getValueEncoder();
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
}

@ -81,4 +81,9 @@ public class BitSetCodec implements Codec {
throw new UnsupportedOperationException();
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
}

@ -29,7 +29,7 @@ import io.netty.buffer.ByteBufAllocator;
* @author Nikita Koksharov
*
*/
public class ByteArrayCodec implements Codec {
public class ByteArrayCodec extends BaseCodec {
public static final ByteArrayCodec INSTANCE = new ByteArrayCodec();
@ -62,24 +62,4 @@ public class ByteArrayCodec implements Codec {
return encoder;
}
@Override
public Decoder<Object> getMapValueDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapValueEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getMapKeyDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapKeyEncoder() {
return getValueEncoder();
}
}

@ -70,5 +70,12 @@ public interface Codec {
* @return encoder
*/
Encoder getValueEncoder();
/**
* Returns class loader object used to load classes used in decoding process
*
* @return class loader
*/
ClassLoader getClassLoader();
}

@ -102,4 +102,9 @@ public class MapScanCodec implements Codec {
return delegate.getMapKeyEncoder();
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
}

@ -78,4 +78,9 @@ public class ScanCodec implements Codec {
return delegate.getMapKeyEncoder();
}
@Override
public ClassLoader getClassLoader() {
return delegate.getClassLoader();
}
}

@ -31,7 +31,7 @@ import io.netty.util.CharsetUtil;
* @author Nikita Koksharov
*
*/
public class StringCodec implements Codec {
public class StringCodec extends BaseCodec {
public static final StringCodec INSTANCE = new StringCodec();
@ -81,24 +81,4 @@ public class StringCodec implements Codec {
return encoder;
}
@Override
public Decoder<Object> getMapValueDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapValueEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getMapKeyDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapKeyEncoder() {
return getValueEncoder();
}
}

@ -71,4 +71,9 @@ public class CompositeCodec implements Codec {
return valueCodec.getValueEncoder();
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
}

@ -20,7 +20,7 @@ import java.io.IOException;
import org.nustaq.serialization.FSTConfiguration;
import org.nustaq.serialization.FSTObjectInput;
import org.nustaq.serialization.FSTObjectOutput;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
@ -39,7 +39,7 @@ import io.netty.buffer.ByteBufOutputStream;
* @author Nikita Koksharov
*
*/
public class FstCodec implements Codec {
public class FstCodec extends BaseCodec {
private final FSTConfiguration config;
@ -94,26 +94,6 @@ public class FstCodec implements Codec {
}
};
@Override
public Decoder<Object> getMapValueDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapValueEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getMapKeyDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapKeyEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
@ -123,5 +103,14 @@ public class FstCodec implements Codec {
public Encoder getValueEncoder() {
return encoder;
}
@Override
public ClassLoader getClassLoader() {
if (config.getClassLoader() != null) {
return config.getClassLoader();
}
return super.getClassLoader();
}
}

@ -21,7 +21,7 @@ import java.io.OutputStream;
import javax.xml.datatype.XMLGregorianCalendar;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
@ -32,6 +32,7 @@ import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.MapperFeature;
@ -55,7 +56,7 @@ import io.netty.buffer.ByteBufOutputStream;
* @author Nikita Koksharov
*
*/
public class JsonJacksonCodec implements Codec {
public class JsonJacksonCodec extends BaseCodec {
public static final JsonJacksonCodec INSTANCE = new JsonJacksonCodec();
@ -155,45 +156,36 @@ public class JsonJacksonCodec implements Codec {
objectMapper.registerModule(new DefenceModule());
objectMapper.setSerializationInclusion(Include.NON_NULL);
objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY).withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
objectMapper.setVisibility(objectMapper.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN);
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class);
}
@Override
public Decoder<Object> getMapValueDecoder() {
return decoder;
}
@Override
public Encoder getMapValueEncoder() {
return encoder;
}
@Override
public Decoder<Object> getMapKeyDecoder() {
public Decoder<Object> getValueDecoder() {
return decoder;
}
@Override
public Encoder getMapKeyEncoder() {
public Encoder getValueEncoder() {
return encoder;
}
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
}
public ClassLoader getClassLoader() {
if (mapObjectMapper.getTypeFactory().getClassLoader() != null) {
return mapObjectMapper.getTypeFactory().getClassLoader();
}
@Override
public Encoder getValueEncoder() {
return encoder;
return super.getClassLoader();
}
public ObjectMapper getObjectMapper() {

@ -21,7 +21,7 @@ import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
@ -40,13 +40,15 @@ import io.netty.buffer.ByteBufOutputStream;
* @author Nikita Koksharov
*
*/
public class KryoCodec implements Codec {
public class KryoCodec extends BaseCodec {
public interface KryoPool {
Kryo get();
void yield(Kryo kryo);
ClassLoader getClassLoader();
}
@ -90,6 +92,11 @@ public class KryoCodec implements Codec {
return kryo;
}
@Override
public ClassLoader getClassLoader() {
return classLoader;
}
}
public class RedissonKryoCodecException extends RuntimeException {
@ -171,26 +178,6 @@ public class KryoCodec implements Codec {
this.kryoPool = kryoPool;
}
@Override
public Decoder<Object> getMapValueDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapValueEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getMapKeyDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapKeyEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
@ -200,5 +187,13 @@ public class KryoCodec implements Codec {
public Encoder getValueEncoder() {
return encoder;
}
@Override
public ClassLoader getClassLoader() {
if (kryoPool.getClassLoader() != null) {
return kryoPool.getClassLoader();
}
return super.getClassLoader();
}
}

@ -18,6 +18,7 @@ package org.redisson.codec;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.codec.Codec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
@ -41,7 +42,7 @@ import net.jpountz.lz4.LZ4SafeDecompressor;
* @author Nikita Koksharov
*
*/
public class LZ4Codec implements Codec {
public class LZ4Codec extends BaseCodec {
private static final int DECOMPRESSION_HEADER_SIZE = Integer.SIZE / 8;
private final LZ4Factory factory = LZ4Factory.fastestInstance();
@ -108,26 +109,6 @@ public class LZ4Codec implements Codec {
}
};
@Override
public Decoder<Object> getMapValueDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapValueEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getMapKeyDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapKeyEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getValueDecoder() {
return decoder;

@ -104,4 +104,9 @@ public class MapCacheEventCodec implements Codec {
return key;
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
}

@ -113,5 +113,13 @@ public class SerializationCodec implements Codec {
public Encoder getValueEncoder() {
return encoder;
}
@Override
public ClassLoader getClassLoader() {
if (classLoader != null) {
return classLoader;
}
return getClass().getClassLoader();
}
}

@ -17,6 +17,7 @@ package org.redisson.codec;
import java.io.IOException;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.codec.Codec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
@ -36,7 +37,7 @@ import io.netty.handler.codec.compression.Snappy;
* @author Nikita Koksharov
*
*/
public class SnappyCodec implements Codec {
public class SnappyCodec extends BaseCodec {
private static final ThreadLocal<Snappy> snappyDecoder = new ThreadLocal<Snappy>() {
protected Snappy initialValue() {
@ -110,26 +111,6 @@ public class SnappyCodec implements Codec {
}
};
@Override
public Decoder<Object> getMapValueDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapValueEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getMapKeyDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapKeyEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
@ -140,4 +121,9 @@ public class SnappyCodec implements Codec {
return encoder;
}
@Override
public ClassLoader getClassLoader() {
return innerCodec.getClassLoader();
}
}

@ -48,6 +48,7 @@ public class TasksRunnerService implements RemoteExecutorService {
private final ClassLoaderDelegator classLoader = new ClassLoaderDelegator();
private final Codec codec;
private final ClassLoader codecClassLoader;
private final String name;
private final CommandExecutor commandExecutor;
@ -68,6 +69,7 @@ public class TasksRunnerService implements RemoteExecutorService {
this.responses = responses;
try {
this.codecClassLoader = codec.getClassLoader();
this.codec = codec.getClass().getConstructor(ClassLoader.class).newInstance(classLoader);
} catch (Exception e) {
throw new IllegalStateException("Unable to initialize codec with ClassLoader parameter", e);
@ -166,7 +168,7 @@ public class TasksRunnerService implements RemoteExecutorService {
try {
buf.writeBytes(state);
RedissonClassLoader cl = new RedissonClassLoader(getClass().getClassLoader());
RedissonClassLoader cl = new RedissonClassLoader(codecClassLoader);
cl.loadClass(className, classBody);
classLoader.setCurrentClassLoader(cl);
@ -199,7 +201,7 @@ public class TasksRunnerService implements RemoteExecutorService {
try {
buf.writeBytes(state);
RedissonClassLoader cl = new RedissonClassLoader(getClass().getClassLoader());
RedissonClassLoader cl = new RedissonClassLoader(codecClassLoader);
cl.loadClass(className, classBody);
classLoader.setCurrentClassLoader(cl);

@ -106,5 +106,10 @@ public class JCacheEventCodec implements Codec {
public Encoder getValueEncoder() {
throw new UnsupportedOperationException();
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
}

@ -17,14 +17,14 @@ package org.redisson;
import java.io.IOException;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
import io.netty.buffer.ByteBuf;
public class ErrorsCodec implements Codec {
public class ErrorsCodec extends BaseCodec {
public static final ErrorsCodec INSTANCE = new ErrorsCodec();
@ -55,24 +55,4 @@ public class ErrorsCodec implements Codec {
return encoder;
}
@Override
public Decoder<Object> getMapValueDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapValueEncoder() {
return getValueEncoder();
}
@Override
public Decoder<Object> getMapKeyDecoder() {
return getValueDecoder();
}
@Override
public Encoder getMapKeyEncoder() {
return getValueEncoder();
}
}

Loading…
Cancel
Save