/** * Sets the {@link IndexWriter} this config is attached to. * * @throws AlreadySetException * if this config is already attached to a writer. */ IndexWriterConfig setIndexWriter(IndexWriter writer) { if (this.writer.get() != null) { throw new IllegalStateException("do not share IndexWriterConfig instances across IndexWriters"); } this.writer.set(writer); return this; }
@Override public String toString() { StringBuilder sb = new StringBuilder(super.toString()); sb.append("writer=").append(writer.get()).append("\n"); return sb.toString(); }
/** * It is possible to retrieve the setting names even if the keystore is closed. * This allows {@link SecureSetting} to correctly determine that a entry exists even though it cannot be read. Thus attempting to * read a secure setting after the keystore is closed will generate a "keystore is closed" exception rather than using the fallback * setting. */ @Override public Set<String> getSettingNames() { assert entries.get() != null : "Keystore is not loaded"; return entries.get().keySet(); }
void setTranslogLocation(Translog.Location translogLocation) { if (freeze.get() == null) { this.translogLocation = translogLocation; } else { throw new IllegalStateException("result is already frozen"); } }
void setTook(long took) { if (freeze.get() == null) { this.took = took; } else { throw new IllegalStateException("result is already frozen"); } }
@Override public synchronized InputStream getFile(String setting) { ensureOpen(); Entry entry = entries.get().get(setting); if (entry == null || entry.type != EntryType.FILE) { throw new IllegalArgumentException("Secret setting " + setting + " is not a file"); } return new ByteArrayInputStream(entry.bytes); }
@Override public Set<String> getSettingNames() { synchronized (settingNames) { if (settingNames.get() == null) { Set<String> names = delegate.getSettingNames().stream() .filter(keyPredicate).map(removePrefix).collect(Collectors.toSet()); settingNames.set(Collections.unmodifiableSet(names)); } } return settingNames.get(); }
/** Remove the given setting from the keystore. */ void remove(String setting) { ensureOpen(); Entry oldEntry = entries.get().remove(setting); if (oldEntry != null) { Arrays.fill(oldEntry.bytes, (byte)0); } }
/** * The {@link XContentType} that was parsed from the {@code Content-Type} header. This value will be {@code null} in the case of * a request without a valid {@code Content-Type} header, a request without content ({@link #hasContent()}, or a plain text request */ @Nullable public final XContentType getXContentType() { return xContentType.get(); }
private ShardSearchFailure[] buildShardFailures() { AtomicArray<ShardSearchFailure> shardFailures = this.shardFailures.get(); if (shardFailures == null) { return ShardSearchFailure.EMPTY_ARRAY; } List<ShardSearchFailure> entries = shardFailures.asList(); ShardSearchFailure[] failures = new ShardSearchFailure[entries.size()]; for (int i = 0; i < failures.length; i++) { failures[i] = entries.get(i); } return failures; }
/** Set a string setting. */ synchronized void setString(String setting, char[] value) { ensureOpen(); validateSettingName(setting); ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(value)); byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); Entry oldEntry = entries.get().put(setting, new Entry(EntryType.STRING, bytes)); if (oldEntry != null) { Arrays.fill(oldEntry.bytes, (byte)0); } }
protected final void ensureOpen(Exception suppressed) { if (isClosed.get()) { AlreadyClosedException ace = new AlreadyClosedException(shardId + " engine is closed", failedEngine.get()); if (suppressed != null) { ace.addSuppressed(suppressed); } throw ace; } }
public Builder setSecureSettings(SecureSettings secureSettings) { if (secureSettings.isLoaded() == false) { throw new IllegalStateException("Secure settings must already be loaded"); } if (this.secureSettings.get() != null) { throw new IllegalArgumentException("Secure settings already set. Existing settings: " + this.secureSettings.get().getSettingNames() + ", new settings: " + secureSettings.getSettingNames()); } this.secureSettings.set(secureSettings); return this; }
/** Set a file setting. */ synchronized void setFile(String setting, byte[] bytes) { ensureOpen(); validateSettingName(setting); Entry oldEntry = entries.get().put(setting, new Entry(EntryType.FILE, Arrays.copyOf(bytes, bytes.length))); if (oldEntry != null) { Arrays.fill(oldEntry.bytes, (byte)0); } }
/** * Builds a {@link Settings} (underlying uses {@link Settings}) based on everything * set on this builder. */ public Settings build() { processLegacyLists(map); return new Settings(map, secureSettings.get()); } }
/** * @return content of the request body or throw an exception if the body or content type is missing */ public final BytesReference requiredContent() { if (hasContent() == false) { throw new ElasticsearchParseException("request body is required"); } else if (xContentType.get() == null) { throw new IllegalStateException("unknown content type"); } return content(); }
@Override public void onAfter() { final Exception exception = failure.get(); if (exception != null) { final String failure = ExceptionsHelper.detailedMessage(exception); notifyFailedSnapshotShard(snapshot, shardId, localNodeId, failure, masterNode); } else { notifySuccessfulSnapshotShard(snapshot, shardId, localNodeId, masterNode); } } });
@Override public DiscoveryNode apply(BoundTransportAddress boundTransportAddress) { localNode.set(DiscoveryNode.createLocal(settings, boundTransportAddress.publishAddress(), persistentNodeId)); return localNode.get(); }
@SuppressWarnings("unchecked") public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException { ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser::getTokenLocation); SetOnce<Suggestion> suggestion = new SetOnce<>(); XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Suggestion.class, suggestion::set); return suggestion.get(); }