提交 32242d5e 编写于 作者: N Nikita Koksharov

Improvement - MarshallingCodec and JsonJacksonCodec warmup added

上级 674a1cce
......@@ -111,7 +111,17 @@ public class JsonJacksonCodec extends BaseCodec {
public JsonJacksonCodec(ClassLoader classLoader, JsonJacksonCodec codec) {
this(createObjectMapper(classLoader, codec.mapObjectMapper.copy()));
}
private void warmup() {
try {
ByteBuf d = getValueEncoder().encode("testValue");
getValueDecoder().decode(d, null);
d.release();
} catch (IOException e) {
e.printStackTrace();
}
}
protected static ObjectMapper createObjectMapper(ClassLoader classLoader, ObjectMapper om) {
TypeFactory tf = TypeFactory.defaultInstance().withClassLoader(classLoader);
om.setTypeFactory(tf);
......@@ -122,6 +132,7 @@ public class JsonJacksonCodec extends BaseCodec {
this.mapObjectMapper = mapObjectMapper.copy();
init(this.mapObjectMapper);
initTypeInclusion(this.mapObjectMapper);
warmup();
}
protected void initTypeInclusion(ObjectMapper mapObjectMapper) {
......
......@@ -194,6 +194,7 @@ public class MarshallingCodec extends BaseCodec {
this(Protocol.RIVER, null);
configuration.setClassResolver(new SimpleClassResolver(classLoader));
this.classLoader = classLoader;
warmup();
}
public MarshallingCodec(ClassLoader classLoader, MarshallingCodec codec) {
......@@ -211,6 +212,7 @@ public class MarshallingCodec extends BaseCodec {
config.setVersion(codec.configuration.getVersion());
this.configuration = config;
this.classLoader = classLoader;
warmup();
}
public MarshallingCodec(Protocol protocol, MarshallingConfiguration configuration) {
......@@ -222,8 +224,19 @@ public class MarshallingCodec extends BaseCodec {
configuration = createConfig();
}
this.configuration = configuration;
warmup();
}
private void warmup() {
try {
ByteBuf d = getValueEncoder().encode("testValue");
getValueDecoder().decode(d, null);
d.release();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册