/** * Returns the result of evaluating the specified function. If the supplied value is of type Message, this method * returns the result of calling {@code #getFormattedMessage} on that Message. * @param supplier a lambda expression or {@code null} * @return the results of evaluating the lambda expression (or {@code null} if the supplier * was {@code null} */ public static Object get(final Supplier<?> supplier) { if (supplier == null) { return null; } final Object result = supplier.get(); return result instanceof Message ? ((Message) result).getFormattedMessage() : result; }
/** * Returns a Message, either the value supplied by the specified function, or a new Message created by the specified * Factory. * @param supplier a lambda expression or {@code null} * @return the Message resulting from evaluating the lambda expression or the Message created by the factory for * supplied values that are not of type Message */ public static Message getMessage(final Supplier<?> supplier, final MessageFactory messageFactory) { if (supplier == null) { return null; } final Object result = supplier.get(); return result instanceof Message ? (Message) result : messageFactory.newMessage(result); } }
protected EntryMessage entryMsg(final String format, final Supplier<?>... paramSuppliers) { final int count = paramSuppliers == null ? 0 : paramSuppliers.length; final Object[] params = new Object[count]; for (int i = 0; i < count; i++) { params[i] = paramSuppliers[i].get(); if (params[i] instanceof Message) { params[i] = ((Message) params[i]).getFormattedMessage(); } } return entryMsg(format, params); }
@Override public T newInstance() { return responseFactory.get(); }
void retry (final Supplier<Void> function, final String label) { for (int i = 0; ; ++i) { try { function.get(); break; } catch (final Exception e) { if (i >= CREATE_ELASTIC_ADMIN_RETRY_ATTEMPTS) { logger.error("Failed to {} after {} attempts", label, CREATE_ELASTIC_ADMIN_RETRY_ATTEMPTS); throw new NoPersistedMetaDataException("Failed to " + label + " after " + CREATE_ELASTIC_ADMIN_RETRY_ATTEMPTS + " attempts", e); } else logger.info("Retrying: {}", label); } } }
/** * Returns the result of evaluating the specified function. If the supplied value is of type Message, this method * returns the result of calling {@code #getFormattedMessage} on that Message. * @param supplier a lambda expression or {@code null} * @return the results of evaluating the lambda expression (or {@code null} if the supplier * was {@code null} */ public static Object get(final Supplier<?> supplier) { if (supplier == null) { return null; } final Object result = supplier.get(); return result instanceof Message ? ((Message) result).getFormattedMessage() : result; }
/** * Returns a Message, either the value supplied by the specified function, or a new Message created by the specified * Factory. * @param supplier a lambda expression or {@code null} * @return the Message resulting from evaluating the lambda expression or the Message created by the factory for * supplied values that are not of type Message */ public static Message getMessage(final Supplier<?> supplier, final MessageFactory messageFactory) { if (supplier == null) { return null; } final Object result = supplier.get(); return result instanceof Message ? (Message) result : messageFactory.newMessage(result); } }
protected EntryMessage entryMsg(final String format, final Supplier<?>... paramSuppliers) { final int count = paramSuppliers == null ? 0 : paramSuppliers.length; final Object[] params = new Object[count]; for (int i = 0; i < count; i++) { params[i] = paramSuppliers[i].get(); if (params[i] instanceof Message) { params[i] = ((Message) params[i]).getFormattedMessage(); } } return entryMsg(format, params); }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); targetNode = new DiscoveryNode(in); wrapped = supplier.get(); wrapped.readFrom(in); }
@Override public LoggerConfig getActiveLoggerConfig(final Supplier<LoggerConfig> next) { LoggerConfig result = this.loggerConfig; if (!beforeLogEvent()) { result = next.get(); return result.getReliabilityStrategy().getActiveLoggerConfig(next); } return result; }
@Override public LoggerConfig getActiveLoggerConfig(final Supplier<LoggerConfig> next) { LoggerConfig result = this.loggerConfig; if (!beforeLogEvent()) { result = next.get(); return result.getReliabilityStrategy().getActiveLoggerConfig(next); } return result; }
protected void onShardFailure(String phaseName, final int shardIndex, final CountDown counter, final long searchId, Exception failure, @Nullable SearchShardTarget searchShardTarget, Supplier<SearchPhase> nextPhaseSupplier) { if (logger.isDebugEnabled()) { logger.debug((Supplier<?>) () -> new ParameterizedMessage("[{}] Failed to execute {} phase", searchId, phaseName), failure); } addShardFailure(new ShardSearchFailure(failure, searchShardTarget)); int successfulOperations = successfulOps.decrementAndGet(); assert successfulOperations >= 0 : "successfulOperations must be >= 0 but was: " + successfulOperations; if (counter.countDown()) { if (successfulOps.get() == 0) { listener.onFailure(new SearchPhaseExecutionException(phaseName, "all shards failed", failure, buildShardFailures())); } else { SearchPhase phase = nextPhaseSupplier.get(); try { phase.run(); } catch (Exception e) { e.addSuppressed(failure); listener.onFailure(new SearchPhaseExecutionException(phase.getName(), "Phase failed", e, ShardSearchFailure.EMPTY_ARRAY)); } } } } }
@Override protected synchronized void doStart() { Objects.requireNonNull(clusterStatePublisher, "please set a cluster state publisher before starting"); Objects.requireNonNull(nodeConnectionsService, "please set the node connection service before starting"); Objects.requireNonNull(discoverySettings, "please set discovery settings before starting"); addListener(localNodeMasterListeners); DiscoveryNode localNode = localNodeSupplier.get(); assert localNode != null; updateState(state -> { assert state.nodes().getLocalNodeId() == null : "local node is already set"; DiscoveryNodes nodes = DiscoveryNodes.builder(state.nodes()).add(localNode).localNodeId(localNode.getId()).build(); return ClusterState.builder(state).nodes(nodes).blocks(initialBlocks).build(); }); this.threadPoolExecutor = EsExecutors.newSinglePrioritizing(UPDATE_THREAD_NAME, daemonThreadFactory(settings, UPDATE_THREAD_NAME), threadPool.getThreadContext(), threadPool.scheduler()); this.taskBatcher = new ClusterServiceTaskBatcher(logger, threadPoolExecutor); }