Skip to content

Commit

Permalink
PR cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Aug 14, 2023
1 parent 59a49b4 commit 63d971e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
Expand All @@ -40,7 +39,7 @@ public class ZstdCompressor implements Compressor {
*
* @opensearch.api - requires BWC support
*/
public static final String NAME = new String(HEADER, StandardCharsets.UTF_8);
public static final String NAME = "ZSTD";

private static final int LEVEL = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import org.opensearch.compress.ZstdCompressor;
import org.opensearch.core.compress.Compressor;
import org.opensearch.core.compress.CompressorRegistry;
import org.opensearch.core.compress.spi.CompressorProvider;

import java.util.AbstractMap.SimpleEntry;
import java.util.List;

/**
Expand All @@ -23,8 +23,9 @@
public class CompressionProvider implements CompressorProvider {

/** Returns the concrete {@link Compressor}s provided by the compress library */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<CompressorRegistry.Entry> getCompressors() {
return List.of(new CompressorRegistry.Entry(ZstdCompressor.NAME, new ZstdCompressor()));
public List<SimpleEntry<String, Compressor>> getCompressors() {
return List.of(new SimpleEntry(ZstdCompressor.NAME, new ZstdCompressor()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opensearch.core.xcontent.MediaTypeRegistry;

import java.io.IOException;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
Expand All @@ -39,40 +40,14 @@ public final class CompressorRegistry {
private CompressorRegistry() {}

static {
ArrayList<Entry> compressors = new ArrayList<>();
ArrayList<SimpleEntry<String, Compressor>> compressors = new ArrayList<>();
for (CompressorProvider provider : ServiceLoader.load(CompressorProvider.class, CompressorProvider.class.getClassLoader())) {
compressors.addAll(provider.getCompressors());
}
registeredCompressors = Map.copyOf(compressors.stream().collect(Collectors.toMap(Entry::getName, Entry::getCompressor)));
registeredCompressors = Map.copyOf(compressors.stream().collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)));
NONE = registeredCompressors.get(NoneCompressor.NAME);
}

/**
* An entry for registering a concrete {@link Compressor} identified by a unique String key
*
* @opensearch.api
* @opensearch.experimental
*/
public static class Entry {
/** a unique key name to identify the compressor; this is typically the Compressor's Header as a string */
private String name;
/** the compressor to register */
private Compressor compressor;

public Entry(final String name, final Compressor compressor) {
this.name = name;
this.compressor = compressor;
}

public String getName() {
return this.name;
}

public Compressor getCompressor() {
return compressor;
}
}

/**
* Returns the default compressor
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
package org.opensearch.core.compress.spi;

import org.opensearch.core.compress.Compressor;
import org.opensearch.core.compress.CompressorRegistry;

import java.util.AbstractMap;
import java.util.List;

/**
Expand All @@ -26,5 +26,5 @@
*/
public interface CompressorProvider {
/** Extensions that implement their own concrete {@link Compressor}s provide them through this interface method*/
List<CompressorRegistry.Entry> getCompressors();
List<AbstractMap.SimpleEntry<String, Compressor>> getCompressors();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
package org.opensearch.core.compress.spi;

import org.opensearch.core.compress.Compressor;
import org.opensearch.core.compress.CompressorRegistry;
import org.opensearch.core.compress.NoneCompressor;

import java.util.AbstractMap.SimpleEntry;
import java.util.List;

/**
Expand All @@ -22,8 +22,9 @@
*/
public class DefaultCompressorProvider implements CompressorProvider {
/** Returns the default {@link Compressor}s provided by the core library */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<CompressorRegistry.Entry> getCompressors() {
return List.of(new CompressorRegistry.Entry(NoneCompressor.NAME, new NoneCompressor()));
public List<SimpleEntry<String, Compressor>> getCompressors() {
return List.of(new SimpleEntry(NoneCompressor.NAME, new NoneCompressor()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import org.opensearch.common.compress.DeflateCompressor;
import org.opensearch.core.compress.Compressor;
import org.opensearch.core.compress.CompressorRegistry;
import org.opensearch.core.compress.spi.CompressorProvider;

import java.util.AbstractMap.SimpleEntry;
import java.util.List;

/**
Expand All @@ -27,8 +27,9 @@
@Deprecated
public class ServerCompressorProvider implements CompressorProvider {
/** Returns the concrete {@link Compressor}s provided by the server module */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<CompressorRegistry.Entry> getCompressors() {
return List.of(new CompressorRegistry.Entry(DeflateCompressor.NAME, new DeflateCompressor()));
public List<SimpleEntry<String, Compressor>> getCompressors() {
return List.of(new SimpleEntry(DeflateCompressor.NAME, new DeflateCompressor()));
}
}

0 comments on commit 63d971e

Please sign in to comment.