import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
-import io.atomix.utils.serializer.Namespace;
+import io.atomix.utils.serializer.KryoJournalSerdesBuilder;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
* @return builder
*/
static Builder builder() {
- return Namespace.builder();
+ return new KryoJournalSerdesBuilder();
}
/**
*/
package io.atomix.utils.serializer;
-import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.esotericsoftware.kryo.Kryo;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.objenesis.strategy.StdInstantiatorStrategy;
/**
* Pool of Kryo instances, with classes pre-registered.
*/
-public final class Namespace implements JournalSerdes, KryoFactory, KryoPool {
+final class KryoJournalSerdes implements JournalSerdes, KryoFactory, KryoPool {
/**
* Default buffer size used for serialization.
*
*/
private static final int INITIAL_ID = 16;
- private static final String NO_NAME = "(no name)";
+ static final String NO_NAME = "(no name)";
- private static final Logger LOGGER = LoggerFactory.getLogger(Namespace.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(KryoJournalSerdes.class);
private final KryoPool kryoPool = new KryoPool.Builder(this).softReferences().build();
* @param registrationRequired whether registration is required
* @param friendlyName friendly name for the namespace
*/
- private Namespace(
+ KryoJournalSerdes(
final List<RegisteredType> registeredTypes,
final ClassLoader classLoader,
final String friendlyName) {
release(create());
}
- /**
- * Creates a new {@link Namespace} builder.
- *
- * @return builder
- */
- public static JournalSerdes.Builder builder() {
- return new Builder();
- }
-
@Override
public byte[] serialize(final Object obj) {
return serialize(obj, DEFAULT_BUFFER_SIZE);
}
return MoreObjects.toStringHelper(getClass()).add("registeredTypes", registeredTypes).toString();
}
-
- private static record RegisteredType(EntrySerializer<?> serializer, Class<?>[] types) {
- RegisteredType {
- requireNonNull(serializer);
- requireNonNull(types);
- }
- }
-
- private static final class Builder implements JournalSerdes.Builder {
- private final List<RegisteredType> types = new ArrayList<>();
- private ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-
- @Override
- public Builder register(final EntrySerdes<?> serdes, final Class<?>... classes) {
- types.add(new RegisteredType(new EntrySerializer<>(serdes), classes));
- return this;
- }
-
- @Override
- public Builder setClassLoader(final ClassLoader classLoader) {
- this.classLoader = requireNonNull(classLoader);
- return this;
- }
-
- @Override
- public JournalSerdes build() {
- return build(NO_NAME);
- }
-
- @Override
- public JournalSerdes build(final String friendlyName) {
- checkState(!types.isEmpty(), "No serializers registered");
- return new Namespace(types, classLoader, friendlyName);
- }
- }
}
--- /dev/null
+/*
+ * Copyright 2014-2021 Open Networking Foundation
+ * Copyright 2023 PANTHEON.tech, s.r.o.
+ *
+ * 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 io.atomix.utils.serializer;
+
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
+import io.atomix.storage.journal.JournalSerdes;
+import io.atomix.storage.journal.JournalSerdes.Builder;
+import io.atomix.storage.journal.JournalSerdes.EntrySerdes;
+import java.util.ArrayList;
+import java.util.List;
+
+public final class KryoJournalSerdesBuilder implements Builder {
+ private final List<RegisteredType> types = new ArrayList<>();
+ private ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+
+ @Override
+ public KryoJournalSerdesBuilder register(final EntrySerdes<?> serdes, final Class<?>... classes) {
+ types.add(new RegisteredType(new EntrySerializer<>(serdes), classes));
+ return this;
+ }
+
+ @Override
+ public KryoJournalSerdesBuilder setClassLoader(final ClassLoader classLoader) {
+ this.classLoader = requireNonNull(classLoader);
+ return this;
+ }
+
+ @Override
+ public JournalSerdes build() {
+ return build(KryoJournalSerdes.NO_NAME);
+ }
+
+ @Override
+ public JournalSerdes build(final String friendlyName) {
+ checkState(!types.isEmpty(), "No serializers registered");
+ return new KryoJournalSerdes(types, classLoader, friendlyName);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2023 PANTHEON.tech, s.r.o.
+ *
+ * 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 io.atomix.utils.serializer;
+
+import static java.util.Objects.requireNonNull;
+
+record RegisteredType(EntrySerializer<?> serializer, Class<?>[] types) {
+ RegisteredType {
+ requireNonNull(serializer);
+ requireNonNull(types);
+ }
+}