|
21 | 21 | /** |
22 | 22 | * An external bridge for {@link IngestDocument} that proxies calls through a real {@link IngestDocument} |
23 | 23 | */ |
24 | | -public class IngestDocumentBridge extends StableBridgeAPI.ProxyInternal<IngestDocument> { |
| 24 | +public interface IngestDocumentBridge extends StableBridgeAPI<IngestDocument> { |
25 | 25 |
|
26 | | - public static final class Constants { |
| 26 | + MetadataBridge getMetadata(); |
| 27 | + |
| 28 | + Map<String, Object> getSource(); |
| 29 | + |
| 30 | + boolean updateIndexHistory(String index); |
| 31 | + |
| 32 | + Set<String> getIndexHistory(); |
| 33 | + |
| 34 | + boolean isReroute(); |
| 35 | + |
| 36 | + void resetReroute(); |
| 37 | + |
| 38 | + Map<String, Object> getIngestMetadata(); |
| 39 | + |
| 40 | + <T> T getFieldValue(String name, Class<T> type); |
| 41 | + |
| 42 | + <T> T getFieldValue(String name, Class<T> type, boolean ignoreMissing); |
| 43 | + |
| 44 | + String renderTemplate(TemplateScriptBridge.Factory bridgedTemplateScriptFactory); |
| 45 | + |
| 46 | + void setFieldValue(String path, Object value); |
| 47 | + |
| 48 | + void removeField(String path); |
| 49 | + |
| 50 | + void executePipeline(PipelineBridge bridgedPipeline, BiConsumer<IngestDocumentBridge, Exception> bridgedHandler); |
| 51 | + |
| 52 | + final class Constants { |
27 | 53 | public static final String METADATA_VERSION_FIELD_NAME = IngestDocument.Metadata.VERSION.getFieldName(); |
28 | 54 |
|
29 | 55 | private Constants() {} |
30 | 56 | } |
31 | 57 |
|
32 | | - public static IngestDocumentBridge fromInternalNullable(final IngestDocument ingestDocument) { |
| 58 | + static IngestDocumentBridge fromInternalNullable(final IngestDocument ingestDocument) { |
33 | 59 | if (ingestDocument == null) { |
34 | 60 | return null; |
35 | 61 | } |
36 | | - return new IngestDocumentBridge(ingestDocument); |
| 62 | + return new IngestDocumentBridge.ProxyInternal(ingestDocument); |
37 | 63 | } |
38 | 64 |
|
39 | | - public IngestDocumentBridge(final Map<String, Object> sourceAndMetadata, final Map<String, Object> ingestMetadata) { |
40 | | - this(new IngestDocument(sourceAndMetadata, ingestMetadata)); |
| 65 | + static IngestDocumentBridge create(final Map<String, Object> sourceAndMetadata, final Map<String, Object> ingestMetadata) { |
| 66 | + final IngestDocument internal = new IngestDocument(sourceAndMetadata, ingestMetadata); |
| 67 | + return fromInternalNullable(internal); |
41 | 68 | } |
42 | 69 |
|
43 | | - private IngestDocumentBridge(IngestDocument inner) { |
44 | | - super(inner); |
45 | | - } |
| 70 | + class ProxyInternal extends StableBridgeAPI.ProxyInternal<IngestDocument> implements IngestDocumentBridge { |
46 | 71 |
|
47 | | - public MetadataBridge getMetadata() { |
48 | | - return new MetadataBridge(internalDelegate.getMetadata()); |
49 | | - } |
| 72 | + public ProxyInternal(final Map<String, Object> sourceAndMetadata, final Map<String, Object> ingestMetadata) { |
| 73 | + this(new IngestDocument(sourceAndMetadata, ingestMetadata)); |
| 74 | + } |
50 | 75 |
|
51 | | - public Map<String, Object> getSource() { |
52 | | - return internalDelegate.getSource(); |
53 | | - } |
| 76 | + private ProxyInternal(IngestDocument inner) { |
| 77 | + super(inner); |
| 78 | + } |
54 | 79 |
|
55 | | - public boolean updateIndexHistory(final String index) { |
56 | | - return internalDelegate.updateIndexHistory(index); |
57 | | - } |
| 80 | + @Override |
| 81 | + public MetadataBridge getMetadata() { |
| 82 | + return new MetadataBridge(internalDelegate.getMetadata()); |
| 83 | + } |
58 | 84 |
|
59 | | - public Set<String> getIndexHistory() { |
60 | | - return Set.copyOf(internalDelegate.getIndexHistory()); |
61 | | - } |
| 85 | + @Override |
| 86 | + public Map<String, Object> getSource() { |
| 87 | + return internalDelegate.getSource(); |
| 88 | + } |
62 | 89 |
|
63 | | - public boolean isReroute() { |
64 | | - return LogstashInternalBridge.isReroute(internalDelegate); |
65 | | - } |
| 90 | + @Override |
| 91 | + public boolean updateIndexHistory(final String index) { |
| 92 | + return internalDelegate.updateIndexHistory(index); |
| 93 | + } |
66 | 94 |
|
67 | | - public void resetReroute() { |
68 | | - LogstashInternalBridge.resetReroute(internalDelegate); |
69 | | - } |
| 95 | + @Override |
| 96 | + public Set<String> getIndexHistory() { |
| 97 | + return Set.copyOf(internalDelegate.getIndexHistory()); |
| 98 | + } |
70 | 99 |
|
71 | | - public Map<String, Object> getIngestMetadata() { |
72 | | - return internalDelegate.getIngestMetadata(); |
73 | | - } |
| 100 | + @Override |
| 101 | + public boolean isReroute() { |
| 102 | + return LogstashInternalBridge.isReroute(internalDelegate); |
| 103 | + } |
74 | 104 |
|
75 | | - public <T> T getFieldValue(final String fieldName, final Class<T> type) { |
76 | | - return internalDelegate.getFieldValue(fieldName, type); |
77 | | - } |
| 105 | + @Override |
| 106 | + public void resetReroute() { |
| 107 | + LogstashInternalBridge.resetReroute(internalDelegate); |
| 108 | + } |
78 | 109 |
|
79 | | - public <T> T getFieldValue(final String fieldName, final Class<T> type, final boolean ignoreMissing) { |
80 | | - return internalDelegate.getFieldValue(fieldName, type, ignoreMissing); |
81 | | - } |
| 110 | + @Override |
| 111 | + public Map<String, Object> getIngestMetadata() { |
| 112 | + return internalDelegate.getIngestMetadata(); |
| 113 | + } |
82 | 114 |
|
83 | | - public String renderTemplate(final TemplateScriptBridge.Factory templateScriptFactory) { |
84 | | - return internalDelegate.renderTemplate(templateScriptFactory.toInternal()); |
85 | | - } |
| 115 | + @Override |
| 116 | + public <T> T getFieldValue(final String fieldName, final Class<T> type) { |
| 117 | + return internalDelegate.getFieldValue(fieldName, type); |
| 118 | + } |
86 | 119 |
|
87 | | - public void setFieldValue(final String path, final Object value) { |
88 | | - internalDelegate.setFieldValue(path, value); |
89 | | - } |
| 120 | + @Override |
| 121 | + public <T> T getFieldValue(final String fieldName, final Class<T> type, final boolean ignoreMissing) { |
| 122 | + return internalDelegate.getFieldValue(fieldName, type, ignoreMissing); |
| 123 | + } |
90 | 124 |
|
91 | | - public void removeField(final String path) { |
92 | | - internalDelegate.removeField(path); |
93 | | - } |
| 125 | + @Override |
| 126 | + public String renderTemplate(final TemplateScriptBridge.Factory templateScriptFactory) { |
| 127 | + return internalDelegate.renderTemplate(templateScriptFactory.toInternal()); |
| 128 | + } |
94 | 129 |
|
95 | | - public void executePipeline(final PipelineBridge pipelineBridge, final BiConsumer<IngestDocumentBridge, Exception> handler) { |
96 | | - this.internalDelegate.executePipeline(pipelineBridge.toInternal(), (ingestDocument, e) -> { |
97 | | - handler.accept(IngestDocumentBridge.fromInternalNullable(ingestDocument), e); |
98 | | - }); |
| 130 | + @Override |
| 131 | + public void setFieldValue(final String path, final Object value) { |
| 132 | + internalDelegate.setFieldValue(path, value); |
| 133 | + } |
| 134 | + |
| 135 | + @Override |
| 136 | + public void removeField(final String path) { |
| 137 | + internalDelegate.removeField(path); |
| 138 | + } |
| 139 | + |
| 140 | + @Override |
| 141 | + public void executePipeline(final PipelineBridge pipelineBridge, final BiConsumer<IngestDocumentBridge, Exception> handler) { |
| 142 | + this.internalDelegate.executePipeline(pipelineBridge.toInternal(), (ingestDocument, e) -> { |
| 143 | + handler.accept(IngestDocumentBridge.fromInternalNullable(ingestDocument), e); |
| 144 | + }); |
| 145 | + } |
99 | 146 | } |
100 | 147 | } |
0 commit comments