Java Code Examples for org.apache.reef.util.Optional#ofNullable()
The following examples show how to use
org.apache.reef.util.Optional#ofNullable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GRPCDriverClientService.java From reef with Apache License 2.0 | 6 votes |
@Override public void failedContextHandler(final ContextInfo request, final StreamObserver<Void> responseObserver) { if (this.activeContextBridgeMap.containsKey(request.getContextId())) { LOG.log(Level.INFO, "Failed context id {0}", request.getContextId()); try (ObserverCleanup cleanup = ObserverCleanup.of(responseObserver)) { final ActiveContextBridge context = this.activeContextBridgeMap.remove(request.getContextId()); final Optional<ActiveContext> parent = Optional.<ActiveContext>ofNullable(this.activeContextBridgeMap.get(context.getParentId().get())); final Optional<Throwable> reason = this.exceptionCodec.fromBytes(request.getException().getData().toByteArray()); this.clientDriverDispatcher.get().dispatch( new FailedContextBridge( context.getId(), context.getEvaluatorId(), request.getException().getMessage(), context.getEvaluatorDescriptor(), parent, reason)); } } else { responseObserver.onError(Status.INTERNAL .withDescription("Unknown context id " + request.getContextId() + " in close") .asRuntimeException()); responseObserver.onCompleted(); } }
Example 2
Source File: RunningWorkers.java From reef with Apache License 2.0 | 6 votes |
/** * Concurrency: Called by multiple threads. * Parameter: Called exactly once per id. */ Optional<Collection<Tasklet>> removeWorker(final String id) { lock.lock(); try { if (!terminated) { final VortexWorkerManager vortexWorkerManager = this.runningWorkers.remove(id); if (vortexWorkerManager != null) { this.schedulingPolicy.workerRemoved(vortexWorkerManager); return Optional.ofNullable(vortexWorkerManager.removed()); } else { // Called before addWorker (e.g. RM preempted the resource before the Evaluator started) removedBeforeAddedWorkers.add(id); return Optional.empty(); } } else { // No need to return anything since it is terminated return Optional.empty(); } } finally { try { workerAggregateFunctionMap.remove(id); } finally { lock.unlock(); } } }
Example 3
Source File: ContainerManager.java From reef with Apache License 2.0 | 6 votes |
/** * Allocates a container based on a request event. First it tries to match a * given node, if it cannot, it tries to get a spot in a rack. * @param requestEvent resource request event. * @return an optional with the container if allocated. */ Optional<Container> allocateContainer(final ResourceRequestEvent requestEvent) { Container container = null; final Optional<String> nodeName = getPreferredNode(requestEvent.getNodeNameList()); if (nodeName.isPresent()) { container = allocateBasedOnNode( requestEvent.getMemorySize().orElse(this.defaultMemorySize), requestEvent.getVirtualCores().orElse(this.defaultNumberOfCores), nodeName.get()); } else { final Optional<String> rackName = getPreferredRack(requestEvent.getRackNameList()); if (rackName.isPresent()) { container = allocateBasedOnRack( requestEvent.getMemorySize().orElse(this.defaultMemorySize), requestEvent.getVirtualCores().orElse(this.defaultNumberOfCores), rackName.get()); } } return Optional.ofNullable(container); }
Example 4
Source File: WrappedValue.java From reef with Apache License 2.0 | 6 votes |
/** * Must only be called once, by the thread that created this WrappedValue. * @return The value returned by valueFetcher */ public synchronized V loadAndGet() throws ExecutionException { try { value = Optional.ofNullable(valueFetcher.call()); } catch (final Exception e) { throw new ExecutionException(e); } finally { writeTime = Optional.of(currentTime.now()); this.notifyAll(); } if (!value.isPresent()) { throw new ExecutionException(new NullPointerException("valueFetcher returned null")); } else { return value.get(); } }
Example 5
Source File: TaskStatus.java From reef with Apache License 2.0 | 5 votes |
void setResult(final byte[] result) { synchronized (this.heartBeatManager) { this.result = Optional.ofNullable(result); if (this.state == State.RUNNING) { this.setState(State.DONE); } else if (this.state == State.SUSPEND_REQUESTED) { this.setState(State.SUSPENDED); } else if (this.state == State.CLOSE_REQUESTED) { this.setState(State.DONE); } this.check(); this.heartbeat(); } }
Example 6
Source File: GRPCDriverClientService.java From reef with Apache License 2.0 | 5 votes |
@Override public void activeContextHandler(final ContextInfo request, final StreamObserver<Void> responseObserver) { try (ObserverCleanup cleanup = ObserverCleanup.of(responseObserver)) { LOG.log(Level.INFO, "Active context id {0}", request.getContextId()); final AllocatedEvaluatorBridge eval = this.evaluatorBridgeMap.get(request.getEvaluatorId()); final ActiveContextBridge context = new ActiveContextBridge( this.driverServiceClient, request.getContextId(), Optional.ofNullable(request.getParentId()), eval.getId(), eval.getEvaluatorDescriptor()); this.activeContextBridgeMap.put(context.getId(), context); this.clientDriverDispatcher.get().dispatch(context); } }
Example 7
Source File: ClientWireUp.java From reef with Apache License 2.0 | 5 votes |
@Inject ClientWireUp(final RemoteManager remoteManager, @Parameter(ClientPresent.class) final String clientPresent, final RuntimeErrorProtoHandler runtimeErrorProtoHandler, final JobStatusMessageHandler jobStatusMessageHandler) { this.remoteManager = Optional.ofNullable(remoteManager); this.runtimeErrorProtoHandler = runtimeErrorProtoHandler; this.jobStatusMessageHandler = jobStatusMessageHandler; this.isClientPresent = clientPresent.equals(ClientPresent.YES); LOG.log(Level.FINE, "Instantiated 'ClientWireUp'. Client present: " + this.isClientPresent()); }
Example 8
Source File: JobSubmissionEventImpl.java From reef with Apache License 2.0 | 5 votes |
private JobSubmissionEventImpl(final Builder builder) { this.identifier = BuilderUtils.notNull(builder.identifier); this.remoteId = BuilderUtils.notNull(builder.remoteId); this.configuration = BuilderUtils.notNull(builder.configuration); this.userName = BuilderUtils.notNull(builder.userName); this.globalFileSet = BuilderUtils.notNull(builder.globalFileSet); this.localFileSet = BuilderUtils.notNull(builder.localFileSet); this.driverMemory = Optional.ofNullable(builder.driverMemory); this.driverCpuCores = Optional.ofNullable(builder.driverCpuCores); this.priority = Optional.ofNullable(builder.priority); this.preserveEvaluators = Optional.ofNullable(builder.preserveEvaluators); this.queue = Optional.ofNullable(builder.queue); this.maxApplicationSubmissions = Optional.ofNullable(builder.maxApplicationSubmissions); }
Example 9
Source File: ResourceRequestEventImpl.java From reef with Apache License 2.0 | 5 votes |
private ResourceRequestEventImpl(final Builder builder) { this.resourceCount = BuilderUtils.notNull(builder.resourceCount); this.nodeNameList = BuilderUtils.notNull(builder.nodeNameList); this.rackNameList = BuilderUtils.notNull(builder.rackNameList); this.memorySize = Optional.ofNullable(builder.memorySize); this.priority = Optional.ofNullable(builder.priority); this.virtualCores = Optional.ofNullable(builder.virtualCores); this.relaxLocality = Optional.ofNullable(builder.relaxLocality); this.nodeLabelExpression = Optional.ofNullable(builder.nodeLabelExpression); this.runtimeName = builder.runtimeName == null ? "" : builder.runtimeName; }
Example 10
Source File: ResourceStatusEventImpl.java From reef with Apache License 2.0 | 5 votes |
private ResourceStatusEventImpl(final Builder builder) { this.identifier = BuilderUtils.notNull(builder.identifier); this.state = BuilderUtils.notNull(builder.state); this.diagnostics = Optional.ofNullable(builder.diagnostics); this.exitCode = Optional.ofNullable(builder.exitCode); this.runtimeName = BuilderUtils.notNull(builder.identifier); }
Example 11
Source File: ResourceEventImpl.java From reef with Apache License 2.0 | 5 votes |
private ResourceEventImpl(final Builder builder) { this.identifier = BuilderUtils.notNull(builder.identifier); this.resourceMemory = builder.recovery ? builder.resourceMemory : BuilderUtils.notNull(builder.resourceMemory); this.nodeId = builder.recovery ? builder.nodeId : BuilderUtils.notNull(builder.nodeId); this.virtualCores = Optional.ofNullable(builder.virtualCores); this.rackName = Optional.ofNullable(builder.rackName); this.runtimeName = BuilderUtils.notNull(builder.runtimeName); }
Example 12
Source File: LoggingScopeImpl.java From reef with Apache License 2.0 | 5 votes |
/** * A constructor of ReefLoggingScope. It starts the timer and logs the msg * * @param logger * @param msg * @param params */ LoggingScopeImpl(final Logger logger, final Level logLevel, final String msg, final Object[] params) { this.logger = logger; this.logLevel = logLevel; this.msg = msg; this.params = params; stopWatch.start(); this.optionalParams = Optional.ofNullable(params); if (logger.isLoggable(logLevel)) { final StringBuilder sb = new StringBuilder(); log(sb.append(START_PREFIX).append(msg).toString()); } }
Example 13
Source File: FailedContextBridge.java From reef with Apache License 2.0 | 4 votes |
@Override public Optional<String> getParentId() { return Optional.ofNullable(this.parentContextId); }
Example 14
Source File: LauncherStatus.java From reef with Apache License 2.0 | 4 votes |
private LauncherStatus(final State state, final Throwable ex) { this.state = state; this.error = Optional.ofNullable(ex); }
Example 15
Source File: CloseEventImpl.java From reef with Apache License 2.0 | 4 votes |
CloseEventImpl(final byte[] theBytes) { this.value = Optional.ofNullable(theBytes); }
Example 16
Source File: SuspendEventImpl.java From reef with Apache License 2.0 | 4 votes |
SuspendEventImpl(final byte[] theBytes) { this.value = Optional.ofNullable(theBytes); }
Example 17
Source File: DriverMessageImpl.java From reef with Apache License 2.0 | 4 votes |
DriverMessageImpl(final byte[] theBytes) { this.value = Optional.ofNullable(theBytes); }
Example 18
Source File: LocalClasspathProvider.java From reef with Apache License 2.0 | 2 votes |
/** * @param envName * @return the value of the environment variable, if there is one. */ private static Optional<String> getEnv(final String envName) { return Optional.ofNullable(System.getenv(envName)); }
Example 19
Source File: Containers.java From reef with Apache License 2.0 | 2 votes |
/** * @param containerId * @return the Container stored under this containerId or an empty Optional. */ synchronized Optional<Container> getOptional(final String containerId) { return Optional.ofNullable(this.containers.get(containerId)); }
Example 20
Source File: Evaluators.java From reef with Apache License 2.0 | 2 votes |
/** * @param evaluatorId * @return the EvaluatorManager for the given id, if one exists. */ public synchronized Optional<EvaluatorManager> get(final String evaluatorId) { return Optional.ofNullable(this.evaluators.get(evaluatorId)); }