org.apache.reef.util.Optional.isPresent()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中org.apache.reef.util.Optional.isPresent()方法的一些代码示例,展示了Optional.isPresent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.isPresent()方法的具体详情如下:
包路径:org.apache.reef.util.Optional
类名称:Optional
方法名:isPresent

Optional.isPresent介绍

暂无

代码示例

代码示例来源:origin: org.apache.reef/reef-runtime-yarn

/**
 * @return true, if a registration was set.
 */
synchronized boolean isPresent() {
 return this.registration.isPresent();
}

代码示例来源:origin: org.apache.reef/reef-common

public synchronized boolean isSet() {
  return this.value.isPresent();
 }
}

代码示例来源:origin: org.apache.reef/reef-common

public synchronized boolean isRootContext() {
  return !this.parentID.isPresent();
 }
}

代码示例来源:origin: org.apache.reef/reef-common

private void check() {
 if (this.result.isPresent() && this.lastException.isPresent()) {
  throw new RuntimeException("Found both an exception and a result. This is unsupported.");
 }
}

代码示例来源:origin: org.apache.reef/reef-common

/**
  * Log message.
  * @param message
  */
 private void log(final String message) {
  if (this.optionalParams.isPresent()) {
   logger.log(logLevel, message, params);
  } else {
   logger.log(logLevel, message);
  }
 }
}

代码示例来源:origin: org.apache.reef/reef-common

/**
 * Called by the child context when it has been closed.
 */
private void resetChildContext() {
 synchronized (this.contextLifeCycle) {
  if (this.childContext.isPresent()) {
   this.childContext = Optional.empty();
  } else {
   throw new IllegalStateException("no child context set");
  }
 }
}

代码示例来源: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-utils

/**
 * @param other
 * @return the value of this Optional or other, if no value exists.
 */
public T orElse(final T other) {
 if (isPresent()) {
  return this.get();
 } else {
  return other;
 }
}

代码示例来源:origin: org.apache.reef/reef-utils

public synchronized V waitAndGet() {
  while (!value.isPresent()) {
   try {
    this.wait();
   } catch (final InterruptedException ignored) {
    // Ignore, as while loop will be re-entered
   }
  }
  return value.get();
 }
}

代码示例来源:origin: apache/reef

public synchronized V waitAndGet() {
  while (!value.isPresent()) {
   try {
    this.wait();
   } catch (final InterruptedException ignored) {
    // Ignore, as while loop will be re-entered
   }
  }
  return value.get();
 }
}

代码示例来源:origin: apache/reef

/**
 * @param other
 * @return the value of this Optional or other, if no value exists.
 */
public T orElse(final T other) {
 if (isPresent()) {
  return this.get();
 } else {
  return other;
 }
}

代码示例来源:origin: org.apache.reef/reef-utils

private void expireEntriesAtTime(final long now) {
 for (final Entry<K, WrappedValue<V>> entry : internalMap.entrySet()) {
  if (entry.getValue() != null) {
   final Optional<Long> writeTime = entry.getValue().getWriteTime();
   if (writeTime.isPresent() && writeTime.get() + timeoutMillis < now) {
    invalidate(entry.getKey());
   }
  }
 }
}

代码示例来源:origin: org.apache.reef/reef-common

/**
  * Closes the remote manager, if there was one.
  */
 synchronized void close() {
  if (this.remoteManager.isPresent()) {
   try {
    this.remoteManager.get().close();
   } catch (final Exception e) {
    LOG.log(Level.WARNING, "Exception while shutting down the RemoteManager.", e);
   }
  }
 }
}

代码示例来源:origin: apache/reef

private void expireEntriesAtTime(final long now) {
 for (final Entry<K, WrappedValue<V>> entry : internalMap.entrySet()) {
  if (entry.getValue() != null) {
   final Optional<Long> writeTime = entry.getValue().getWriteTime();
   if (writeTime.isPresent() && writeTime.get() + timeoutMillis < now) {
    invalidate(entry.getKey());
   }
  }
 }
}

代码示例来源:origin: org.apache.reef/reef-io

private static AvroActiveContext unwrapOptionalActiveContext(final Optional<ActiveContext> optionalActiveContext) {
 if (optionalActiveContext.isPresent()) {
  return toAvroActiveContext(optionalActiveContext.get());
 }
 return null;
}

代码示例来源:origin: org.apache.reef/reef-common

synchronized String getRemoteManagerIdentifier() {
 if (!this.isClientPresent() || !this.remoteManager.isPresent()) {
  throw new RuntimeException("No need to setup the remote manager.");
 } else {
  return this.remoteManager.get().getMyIdentifier();
 }
}

代码示例来源:origin: org.apache.reef/reef-common

@Override
public Optional<Throwable> fromBytes(final Optional<byte[]> bytes) {
 if (bytes.isPresent()) {
  return this.fromBytes(bytes.get());
 } else {
  return Optional.empty();
 }
}

代码示例来源:origin: org.apache.reef/reef-runtime-yarn

/**
 * NM Callback: NM accepts the starting container request.
 * @param containerId ID of a new container being started.
 * @param stringByteBufferMap a Map between the auxiliary service names and their outputs. Not used.
 */
@Override
public void onContainerStarted(final ContainerId containerId, final Map<String, ByteBuffer> stringByteBufferMap) {
 final Optional<Container> container = this.containers.getOptional(containerId.toString());
 if (container.isPresent()) {
  this.nodeManager.getContainerStatusAsync(containerId, container.get().getNodeId());
 }
}

代码示例来源: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

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);
}

相关文章

微信公众号

最新文章

更多