Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Microsoft Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.microsoft.reef.runtime.yarn.driver;
 
 
 
 import java.util.Map;
Helper class that manages the set of Containers we know about.
 
 final class Containers {
   private final Map<StringContainercontainers = new ConcurrentHashMap<>();
 
   @Inject
   Containers() {
   }

  

Parameters:
containerID
Returns:
the container for the given id.
Throws:
java.lang.RuntimeException when the container is unknown.
 
   synchronized Container get(final String containerID) {
     final Container result = this..get(containerID);
     if (null == result) {
       throw new RuntimeException("Requesting an unknown container: " + containerID);
     }
     return result;
   }

  
Registers the given container

Parameters:
container
Throws:
java.lang.RuntimeException if a container with the same ID had been registered before.
 
   synchronized void add(final Container container) {
     final String containerId = container.getId().toString();
     if (this.hasContainer(containerId)) {
       throw new RuntimeException("Trying to add a Container that is already known: " + containerId);
     }
     this..put(containerIdcontainer);
   }

  
Removes the container with the given ID.

Parameters:
containerId
Returns:
the container that was registered before.
Throws:
java.lang.RuntimeException if no such container existed.
 
   synchronized Container removeAndGet(final String containerId) {
     final Container result = this..remove(containerId);
     if (null == result) {
       throw new RuntimeException("Unknown container to remove: " + containerId);
     }
     return result;
   }

  

Parameters:
containerId
Returns:
true, if a container with this ID is known.
 
   synchronized boolean hasContainer(final String containerId) {
     return this..containsKey(containerId);
   }


  

Parameters:
containerId
Returns:
the Container stored under this containerId or an empty Optional.
 
   synchronized Optional<ContainergetOptional(final String containerId) {
     return Optional.ofNullable(this..get(containerId));
   }

  

Returns:
an Iterable of all the known container Ids.
  synchronized Iterable<StringgetContainerIds() {
    return new ArrayList(this..keySet());
  }
New to GrepCode? Check out our FAQ X