Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.opensearch.migrations.replay;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

import org.opensearch.migrations.replay.datahandlers.IPacketFinalizingConsumer;
Expand All @@ -15,11 +17,12 @@

@Slf4j
public class PacketToTransformingHttpHandlerFactory
implements
PacketConsumerFactory<TransformedOutputAndResult<ByteBufList>> {
implements PacketConsumerFactory<TransformedOutputAndResult<ByteBufList>>, AutoCloseable {

// Using ThreadLocal to ensure thread safety with the json transformers which will be reused
private final ThreadLocal<IJsonTransformer> localJsonTransformer;
private final Set<AutoCloseable> closeableResources = ConcurrentHashMap.newKeySet();

// The authTransformerFactory is ThreadSafe and getAuthTransformer will be called for every request
private final IAuthTransformerFactory authTransformerFactory;

Expand All @@ -43,4 +46,12 @@ public IPacketFinalizingConsumer<TransformedOutputAndResult<ByteBufList>> create
httpTransactionContext
);
}

@Override
public void close() throws Exception {
for (AutoCloseable resource : closeableResources) {
resource.close();
}
localJsonTransformer.remove();
}
}
Loading