Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -50,6 +50,11 @@ static <T, B extends StableBridgeAPI<T>> B fromInternal(final T delegate, final
* An {@code ProxyInternal<INTERNAL>} is an implementation of {@code StableBridgeAPI<INTERNAL>} that
* proxies calls to a delegate that is an actual {@code INTERNAL}.
*
* <p>
* implementations are intended to be <em>opaque</em> to consumers of this library,
* and should <em>NOT</em> have public constructors.
* </p>
*
* @param <INTERNAL>
*/
abstract class ProxyInternal<INTERNAL> implements StableBridgeAPI<INTERNAL> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.logstashbridge.common;

import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.logstashbridge.StableBridgeAPI;

/**
* A {@link StableBridgeAPI} for {@link ProjectId}
*/
public interface ProjectIdBridge extends StableBridgeAPI<ProjectId> {
String id();

static ProjectIdBridge fromInternal(final ProjectId projectId) {
return new ProxyInternal(projectId);
}

static ProjectIdBridge fromId(final String id) {
final ProjectId internal = ProjectId.fromId(id);
return new ProxyInternal(internal);
}

static ProjectIdBridge getDefault() {
return ProxyInternal.DEFAULT;
}

/**
* An implementation of {@link ProjectIdBridge} that proxies calls to
* an internal {@link ProjectId} instance.
*
* @see StableBridgeAPI.ProxyInternal
*/
final class ProxyInternal extends StableBridgeAPI.ProxyInternal<ProjectId> implements ProjectIdBridge {
private static final ProjectIdBridge.ProxyInternal DEFAULT = new ProjectIdBridge.ProxyInternal(ProjectId.DEFAULT);

ProxyInternal(ProjectId internalDelegate) {
super(internalDelegate);
}

@Override
public String id() {
return this.internalDelegate.id();
}

@Override
public ProjectId toInternal() {
return this.internalDelegate;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,27 @@
import org.elasticsearch.logstashbridge.StableBridgeAPI;

/**
* An external bridge for {@link Settings}
* A {@link StableBridgeAPI} for {@link Settings}
*/
public class SettingsBridge extends StableBridgeAPI.ProxyInternal<Settings> {
public interface SettingsBridge extends StableBridgeAPI<Settings> {

public static SettingsBridge fromInternal(final Settings delegate) {
return new SettingsBridge(delegate);
static SettingsBridge fromInternal(final Settings delegate) {
return new ProxyInternal(delegate);
}

public static Builder builder() {
return Builder.fromInternal(Settings.builder());
}

public SettingsBridge(final Settings delegate) {
super(delegate);
}

@Override
public Settings toInternal() {
return this.internalDelegate;
static SettingsBuilderBridge builder() {
return SettingsBuilderBridge.fromInternal(Settings.builder());
}

/**
* An external bridge for {@link Settings.Builder} that proxies calls to a real {@link Settings.Builder}
* An implementation of {@link SettingsBridge} that proxies calls to
* an internal {@link Settings} instance.
*
* @see StableBridgeAPI.ProxyInternal
*/
public static class Builder extends StableBridgeAPI.ProxyInternal<Settings.Builder> {
static Builder fromInternal(final Settings.Builder delegate) {
return new Builder(delegate);
}

private Builder(final Settings.Builder delegate) {
super(delegate);
}

public Builder put(final String key, final String value) {
this.internalDelegate.put(key, value);
return this;
}

public SettingsBridge build() {
return new SettingsBridge(this.internalDelegate.build());
final class ProxyInternal extends StableBridgeAPI.ProxyInternal<Settings> implements SettingsBridge {
ProxyInternal(Settings internalDelegate) {
super(internalDelegate);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.logstashbridge.common;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.logstashbridge.StableBridgeAPI;

/**
* A {@link StableBridgeAPI} for {@link Settings.Builder}.
*/
public interface SettingsBuilderBridge extends StableBridgeAPI<Settings.Builder> {

SettingsBuilderBridge put(String key, String value);

SettingsBridge build();

static SettingsBuilderBridge fromInternal(final Settings.Builder builder) {
return new ProxyInternal(builder);
}

/**
* An implementation of {@link SettingsBuilderBridge} that proxies calls to
* an internal {@link Settings.Builder} instance.
*
* @see StableBridgeAPI.ProxyInternal
*/
final class ProxyInternal extends StableBridgeAPI.ProxyInternal<Settings.Builder> implements SettingsBuilderBridge {
ProxyInternal(Settings.Builder internalDelegate) {
super(internalDelegate);
}

@Override
public SettingsBuilderBridge put(String key, String value) {
internalDelegate.put(key, value);
return this;
}

@Override
public SettingsBridge build() {
final Settings delegate = internalDelegate.build();
return SettingsBridge.fromInternal(delegate);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@

package org.elasticsearch.logstashbridge.core;

import org.elasticsearch.ingest.common.FailProcessorException;
import org.elasticsearch.common.CheckedBiFunction;
import org.elasticsearch.logstashbridge.StableBridgeAPI;

public class FailProcessorExceptionBridge extends StableBridgeAPI.ProxyInternal<FailProcessorException> {
protected FailProcessorExceptionBridge(FailProcessorException internalDelegate) {
super(internalDelegate);
}
/**
* A stable interface on top of {@link CheckedBiFunction}.
* @param <T> type of lhs parameter
* @param <U> type of rhs parameter
* @param <R> type of return value
* @param <E> type of anticipated exception
*/
@FunctionalInterface
public interface CheckedBiFunctionBridge<T, U, R, E extends Exception> extends StableBridgeAPI<CheckedBiFunction<T, U, R, E>> {
R apply(T t, U u) throws E;

public static boolean isInstanceOf(Throwable exception) {
return exception instanceof FailProcessorException;
@Override
default CheckedBiFunction<T, U, R, E> toInternal() {
return this::apply;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* An external bridge for {@link IOUtils}
*/
public class IOUtilsBridge {
private IOUtilsBridge() {}

public static void closeWhileHandlingException(final Iterable<? extends Closeable> objects) {
IOUtils.closeWhileHandlingException(objects);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,52 @@
package org.elasticsearch.logstashbridge.core;

import org.elasticsearch.action.support.RefCountingRunnable;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.logstashbridge.StableBridgeAPI;

public class RefCountingRunnableBridge extends StableBridgeAPI.ProxyInternal<RefCountingRunnable> {
import java.io.Closeable;

private RefCountingRunnableBridge(final RefCountingRunnable delegate) {
super(delegate);
}

public RefCountingRunnableBridge(final Runnable delegate) {
super(new RefCountingRunnable(delegate));
}

public void close() {
toInternal().close();
}

public ReleasableBridge acquire() {
return new ReleasableBridge.ProxyInternal(toInternal().acquire());
/**
* A {@link StableBridgeAPI} for {@link RefCountingRunnable}
*/
public interface RefCountingRunnableBridge extends StableBridgeAPI<RefCountingRunnable>, Closeable {

@Override // only RuntimeException
void close();

ReleasableBridge acquire();

/**
* An API-stable factory method for {@link RefCountingRunnableBridge}
* @param delegate the {@link Runnable} to execute when all refs are closed
* @return a {@link RefCountingRunnableBridge} that will execute the provided
* block when all refs are closed
*/
static RefCountingRunnableBridge create(final Runnable delegate) {
final RefCountingRunnable refCountingRunnable = new RefCountingRunnable(delegate);
return new ProxyInternal(refCountingRunnable);
}

@Override
public RefCountingRunnable toInternal() {
return this.internalDelegate;
/**
* An implementation of {@link RefCountingRunnableBridge} that proxies calls through
* to an internal {@link RefCountingRunnable}.
* @see StableBridgeAPI.ProxyInternal
*/
final class ProxyInternal extends StableBridgeAPI.ProxyInternal<RefCountingRunnable> implements RefCountingRunnableBridge {
private ProxyInternal(final RefCountingRunnable delegate) {
super(delegate);
}

@Override
public void close() {
toInternal().close();
}

@Override
public ReleasableBridge acquire() {
@SuppressWarnings("resource")
final Releasable releasable = toInternal().acquire();
return ReleasableBridge.fromInternal(releasable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,28 @@
import org.elasticsearch.core.Releasable;
import org.elasticsearch.logstashbridge.StableBridgeAPI;

public interface ReleasableBridge extends StableBridgeAPI<Releasable> {
import java.io.Closeable;

/**
* A {@link StableBridgeAPI} for {@link Releasable} for use with {@link RefCountingRunnableBridge}
*/
public interface ReleasableBridge extends StableBridgeAPI<Releasable>, Closeable {

@Override // only RuntimeException
void close();

class ProxyInternal extends StableBridgeAPI.ProxyInternal<Releasable> implements ReleasableBridge {
static ReleasableBridge fromInternal(Releasable releasable) {
return new ProxyInternal(releasable);
}

/**
* An implementation of {@link ReleasableBridge} that proxies calls through
* to an internal {@link Releasable}.
* @see StableBridgeAPI.ProxyInternal
*/
final class ProxyInternal extends StableBridgeAPI.ProxyInternal<Releasable> implements ReleasableBridge {

public ProxyInternal(final Releasable delegate) {
private ProxyInternal(final Releasable delegate) {
super(delegate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,30 @@
import java.nio.file.Path;

/**
* An external bridge for {@link Environment}
* A {@link StableBridgeAPI} for {@link Environment}
*/
public class EnvironmentBridge extends StableBridgeAPI.ProxyInternal<Environment> {
public static EnvironmentBridge fromInternal(final Environment delegate) {
return new EnvironmentBridge(delegate);
public interface EnvironmentBridge extends StableBridgeAPI<Environment> {
static EnvironmentBridge fromInternal(final Environment delegate) {
return new EnvironmentBridge.ProxyInternal(delegate);
}

public EnvironmentBridge(final SettingsBridge settingsBridge, final Path configPath) {
this(new Environment(settingsBridge.toInternal(), configPath));
static EnvironmentBridge create(final SettingsBridge bridgedSettings, final Path configPath) {
return fromInternal(new Environment(bridgedSettings.toInternal(), configPath));
}

private EnvironmentBridge(final Environment delegate) {
super(delegate);
}
/**
* An implementation of {@link EnvironmentBridge} that proxies calls through
* to an internal {@link Environment}.
* @see StableBridgeAPI.ProxyInternal
*/
final class ProxyInternal extends StableBridgeAPI.ProxyInternal<Environment> implements EnvironmentBridge {
private ProxyInternal(final Environment delegate) {
super(delegate);
}

@Override
public Environment toInternal() {
return this.internalDelegate;
@Override
public Environment toInternal() {
return this.internalDelegate;
}
}
}
Loading