本文整理了Java中org.apache.reef.util.Optional.of()
方法的一些代码示例,展示了Optional.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.of()
方法的具体详情如下:
包路径:org.apache.reef.util.Optional
类名称:Optional
方法名:of
暂无
代码示例来源:origin: org.apache.reef/reef-common
@Override
public JavaLaunchCommandBuilder setConfigurationFilePaths(final List<String> configurationPaths) {
this.evaluatorConfigurationPaths = Optional.of(configurationPaths);
return this;
}
代码示例来源:origin: org.apache.reef/reef-common
private void onTaskFailed(final TaskStatusPOJO taskStatus) {
assert State.FAILED == taskStatus.getState();
final Optional<ActiveContext> evaluatorContext = Optional.<ActiveContext>of(this.context);
final Optional<byte[]> bytes = Optional.ofNullable(getResult(taskStatus));
final Optional<Throwable> exception = this.exceptionCodec.fromBytes(bytes);
final String message = exception.isPresent() ? exception.get().getMessage() : "No message given";
final Optional<String> description = Optional.empty();
final FailedTask failedTask = new FailedTask(
this.taskId, message, description, exception, bytes, evaluatorContext);
this.messageDispatcher.onTaskFailed(failedTask);
this.setState(State.FAILED);
}
代码示例来源:origin: org.apache.reef/reef-common
@Override
public CLRLaunchCommandBuilder setConfigurationFilePaths(final List<String> configurationFilePaths) {
this.evaluatorConfigurationPaths = Optional.of(configurationFilePaths);
return this;
}
代码示例来源:origin: org.apache.reef/reef-common
@Override
public void submitContextAndServiceAndTask(final Configuration contextConfiguration,
final Configuration serviceConfiguration,
final Configuration taskConfiguration) {
launch(contextConfiguration, Optional.of(serviceConfiguration), Optional.of(taskConfiguration));
}
代码示例来源:origin: org.apache.reef/reef-utils
/**
* @return An optional representing the given value, or an empty Optional.
*/
public static <T> Optional<T> ofNullable(final T value) {
if (null == value) {
return Optional.empty();
} else {
return Optional.of(value);
}
}
代码示例来源:origin: org.apache.reef/reef-common
@SuppressWarnings("checkstyle:hiddenfield")
public synchronized void set(final T value) {
if (this.value.isPresent()) {
throw new IllegalStateException("Trying to set new value " + value +
" while an old value was already present: " + this.value);
}
this.value = Optional.of(value);
}
代码示例来源:origin: org.apache.reef/reef-runtime-yarn
/**
* Set the registration information. This is a set-once field.
*
* @param registration
*/
synchronized void setRegistration(final RegisterApplicationMasterResponse registration) {
if (this.isPresent()) {
throw new RuntimeException("Trying to re-register the AM");
}
this.registration = Optional.of(registration);
}
代码示例来源:origin: org.apache.reef/reef-common
@Override
public Optional<String> getParentId() {
return Optional.of(this.parentContext.getId());
}
代码示例来源:origin: org.apache.reef/reef-common
@Override
public Optional<Throwable> fromBytes(final byte[] bytes) {
try {
return Optional.<Throwable>of((Throwable) SerializationUtils.deserialize(bytes));
} catch (SerializationException | IllegalArgumentException e) {
LOG.log(Level.FINE, "Unable to deserialize a Throwable.", e);
return Optional.empty();
}
}
代码示例来源:origin: org.apache.reef/reef-common
@Override
public void submitContextAndTask(final Configuration contextConfiguration,
final Configuration taskConfiguration) {
launch(contextConfiguration, Optional.<Configuration>empty(), Optional.of(taskConfiguration));
}
代码示例来源:origin: org.apache.reef/reef-common
void setException(final Throwable throwable) {
synchronized (this.heartBeatManager) {
this.lastException = Optional.of(throwable);
this.state = State.FAILED;
this.check();
this.heartbeat();
}
}
代码示例来源:origin: org.apache.reef/reef-common
/**
* Submit Context and Service with configuration strings.
* This method should be called from bridge and the configuration strings are
* serialized at .Net side.
* @param evaluatorConfiguration
* @param contextConfiguration
* @param serviceConfiguration
*/
public void submitContextAndService(final String evaluatorConfiguration,
final String contextConfiguration,
final String serviceConfiguration) {
launchWithConfigurationString(evaluatorConfiguration, contextConfiguration,
Optional.of(serviceConfiguration), Optional.<String>empty());
}
代码示例来源:origin: org.apache.reef/reef-common
@Override
public void submitContextAndService(final Configuration contextConfiguration,
final Configuration serviceConfiguration) {
launch(contextConfiguration, Optional.of(serviceConfiguration), Optional.<Configuration>empty());
}
代码示例来源:origin: org.apache.reef/reef-runtime-multi
/**
* Sets default runtime. Default runtime is used when no runtime was specified for evaluator
* @param runtimeName the default runtime name
* @return The builder instance
*/
public MultiRuntimeConfigurationBuilder setDefaultRuntime(final String runtimeName) {
Validate.isTrue(SUPPORTED_RUNTIMES.contains(runtimeName), "Unsupported runtime " + runtimeName);
Validate.isTrue(!this.defaultRuntime.isPresent(), "Default runtime was already added");
this.defaultRuntime = Optional.of(runtimeName);
return this;
}
代码示例来源:origin: org.apache.reef/reef-common
@Inject
RootContextLauncher(@Parameter(RootContextConfiguration.class) final String rootContextConfiguration,
@Parameter(RootServiceConfiguration.class) final String rootServiceConfiguration,
@Parameter(InitialTaskConfiguration.class) final String initialTaskConfiguration,
final Injector injector, final ConfigurationSerializer configurationSerializer)
throws IOException, BindException {
this.injector = injector;
this.configurationSerializer = configurationSerializer;
this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
this.rootServiceConfiguration = Optional.of(this.configurationSerializer.fromString(rootServiceConfiguration));
this.initialTaskConfiguration = Optional.of(this.configurationSerializer.fromString(initialTaskConfiguration));
}
代码示例来源:origin: org.apache.reef/reef-common
@Inject
RootContextLauncher(@Parameter(RootContextConfiguration.class) final String rootContextConfiguration,
final Injector injector,
@Parameter(RootServiceConfiguration.class) final String rootServiceConfiguration,
final ConfigurationSerializer configurationSerializer) throws IOException, BindException {
this.injector = injector;
this.configurationSerializer = configurationSerializer;
this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
this.rootServiceConfiguration = Optional.of(this.configurationSerializer.fromString(rootServiceConfiguration));
this.initialTaskConfiguration = Optional.empty();
}
代码示例来源:origin: org.apache.reef/reef-common
@Inject
RootContextLauncher(final Injector injector,
@Parameter(RootContextConfiguration.class) final String rootContextConfiguration,
@Parameter(InitialTaskConfiguration.class) final String initialTaskConfiguration,
final ConfigurationSerializer configurationSerializer) throws IOException, BindException {
this.injector = injector;
this.configurationSerializer = configurationSerializer;
this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
this.rootServiceConfiguration = Optional.empty();
this.initialTaskConfiguration = Optional.of(this.configurationSerializer.fromString(initialTaskConfiguration));
}
代码示例来源:origin: org.apache.reef/reef-common
/**
* Create a new Failure object out of protobuf data.
*
* @param error Error message as a protocol buffers object.
*/
public FailedRuntime(final RuntimeErrorProto error) {
super(error.getIdentifier(), error.getMessage(), Optional.<String>empty(), Optional.of(getThrowable(error)),
Optional.<byte[]>empty());
}
代码示例来源:origin: org.apache.reef/reef-common
@Override
public Optional<String> getParentId() {
if (this.getParentContext().isPresent()) {
return Optional.of(this.getParentContext().get().getId());
} else {
return Optional.empty();
}
}
代码示例来源:origin: org.apache.reef/reef-common
/**
* Called with a specific TaskStatus that must be delivered to the driver.
*/
public synchronized void sendTaskStatus(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
this.sendHeartBeat(this.getEvaluatorHeartbeatProto(
this.evaluatorRuntime.get().getEvaluatorStatus(),
this.contextManager.get().getContextStatusCollection(),
Optional.of(taskStatusProto)));
}
内容来源于网络,如有侵权,请联系作者删除!