Skip to content

Commit

Permalink
Merge pull request #3633 from ingef/feature/simplify-mina-stack
Browse files Browse the repository at this point in the history
simplify the mina stack by cumulating IoBuffers until there are enough
  • Loading branch information
thoniTUB authored Dec 13, 2024
2 parents 2718ab7 + 1ef6569 commit ef752fc
Show file tree
Hide file tree
Showing 28 changed files with 680 additions and 1,181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import java.util.Locale;

import com.bakdata.conquery.io.jackson.serializer.Object2IntMapMixin;
import com.bakdata.conquery.io.jackson.mixin.DefaultSocketSessionConfigMixIn;
import com.bakdata.conquery.io.jackson.mixin.Object2IntMapMixIn;
import com.bakdata.conquery.models.auth.permissions.ConqueryPermission;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerator;
Expand All @@ -19,6 +20,7 @@
import com.fasterxml.jackson.module.blackbird.BlackbirdModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import org.apache.mina.transport.socket.DefaultSocketSessionConfig;
import org.apache.shiro.authz.Permission;

public class Jackson {
Expand Down Expand Up @@ -72,7 +74,8 @@ public static <T extends ObjectMapper> T configure(T objectMapper) {
//.setAnnotationIntrospector(new RestrictingAnnotationIntrospector())
.setInjectableValues(new MutableInjectableValues())
.addMixIn(Permission.class, ConqueryPermission.class)
.addMixIn(Object2IntMap.class, Object2IntMapMixin.class);
.addMixIn(Object2IntMap.class, Object2IntMapMixIn.class)
.addMixIn(DefaultSocketSessionConfig.class, DefaultSocketSessionConfigMixIn.class);

return objectMapper;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
package com.bakdata.conquery.io.jackson;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.SequenceInputStream;

import com.bakdata.conquery.io.mina.ChunkedMessage;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.translate.JavaUnicodeEscaper;
import org.apache.mina.core.buffer.IoBuffer;

@Slf4j @UtilityClass
public class JacksonUtil {

public static String toJsonDebug(byte[] bytes) {
return toJsonDebug(IoBuffer.wrap(bytes));
}

public static String toJsonDebug(IoBuffer buffer) {
return toJsonDebug(stream(buffer));
}

/**
* Partially read and parse InputStream as Json, directly storing it into String, just for debugging purposes.
*/
Expand Down Expand Up @@ -72,7 +58,7 @@ public static String toJsonDebug(InputStream is) {
sb.append('"').append(value).append("\",");
break;
default:
sb.append(t.toString());
sb.append(t);
log.warn("I don't know how to handle {}", t);
break;
}
Expand All @@ -85,33 +71,4 @@ public static String toJsonDebug(InputStream is) {
return sb.toString();
}
}

public static InputStream stream(IoBuffer buffer) {
return new ByteArrayInputStream(
buffer.array(),
buffer.position() + buffer.arrayOffset(),
buffer.remaining()
);
}

public static InputStream stream(Iterable<IoBuffer> list) {
return new SequenceInputStream(
IteratorUtils.asEnumeration(
IteratorUtils.transformedIterator(
list.iterator(),
JacksonUtil::stream
)
)
);
}

public static String toJsonDebug(ChunkedMessage msg) {
return toJsonDebug(msg.createInputStream());
}

public static void expect(Class<?> parseTargetType, DeserializationContext ctxt, JsonToken token, JsonToken expected) throws JsonMappingException {
if (token != expected) {
ctxt.reportInputMismatch(parseTargetType, "Expected " + expected + " but found " + token);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bakdata.conquery.io.jackson.mixin;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.mina.transport.socket.DefaultSocketSessionConfig;

/**
* MixIn to suppress artificial properties of {@link DefaultSocketSessionConfig}.
*/
@JsonIgnoreProperties(value = {
"throughputCalculationIntervalInMillis",
"readerIdleTimeInMillis",
"writeTimeoutInMillis",
"writerIdleTimeInMillis",
"bothIdleTimeInMillis"
})
public class DefaultSocketSessionConfigMixIn extends DefaultSocketSessionConfig {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bakdata.conquery.io.jackson.serializer;
package com.bakdata.conquery.io.jackson.mixin;

import java.io.IOException;
import java.util.Map;
Expand All @@ -25,9 +25,9 @@
/**
* (De-)Serialization Mixin for {@link Object2IntMap}.
*/
@JsonDeserialize(using = Object2IntMapMixin.Deserializer.class)
@JsonDeserialize(using = Object2IntMapMixIn.Deserializer.class)
@Slf4j
public class Object2IntMapMixin {
public class Object2IntMapMixIn {

public static class Deserializer<K> extends StdDeserializer<Object2IntMap<K>> implements ContextualDeserializer {

Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit ef752fc

Please sign in to comment.