private Container findMatchingContainer(String name) {
   for (Container container : containers) {
     if (container.getName().equals(name)) {
       return container;
     }
   }
   return null;
 }
  /**
   * @see
   *     org.jboss.arquillian.container.test.impl.client.container.ClientContainerController#stop(java.lang.String)
   */
  @Override
  public void stop(String containerQualifier, int timeout) {
    {
      DeploymentScenario scenario = getDeploymentScenario().get();
      if (scenario == null) {
        throw new IllegalArgumentException("No deployment scenario in context");
      }

      ContainerRegistry registry = getContainerRegistry().get();
      if (registry == null) {
        throw new IllegalArgumentException("No container registry in context");
      }

      if (!containerExists(registry.getContainers(), containerQualifier)) {
        throw new IllegalArgumentException("No container with the specified name exists");
      }

      if (!isControllableContainer(registry.getContainers(), containerQualifier)) {
        throw new IllegalArgumentException(
            "Could not start "
                + containerQualifier
                + " container. The container life cycle is controlled by Arquillian");
      }

      Container container =
          getContainerRegistry().get().getContainer(new TargetDescription(containerQualifier));

      List<Deployment> managedDeployments =
          scenario.startupDeploymentsFor(new TargetDescription(containerQualifier));

      for (Deployment d : managedDeployments) {
        if (d.isDeployed()) {
          log.info(
              "Automatic undeploying of the managed deployment with name "
                  + d.getDescription().getName()
                  + " from the container with name "
                  + container.getName());
          getContainerControllerEvent().fire(new UnDeployDeployment(container, d));
        }
      }

      log.info("Manual stopping of a server instance with timeout=" + timeout);

      getContainerControllerEvent().fire(new StopContainerWithTimeout(container, timeout));
    }
  }
 @Override
 public Object doLookup(ArquillianResource resource, Annotation... qualifiers) {
   Container container = containerInst.get();
   if (container == null) {
     throw new IllegalStateException(
         "No Container found in context, can't perform CubeID injection");
   }
   CubeRegistry cubeRegistry = cubeRegistryInst.get();
   if (cubeRegistry == null) {
     throw new IllegalStateException(
         "No CubeRegistry found in context, can't perform CubeID injection");
   }
   Cube<?> cube = cubeRegistry.getCube(ContainerUtil.getCubeIDForContainer(container));
   if (cube == null) {
     throw new IllegalStateException(
         String.format(
             "No Cube found mapped to current Container[%s] with CubeID[%s]",
             container.getName(), ContainerUtil.getCubeIDForContainer(container)));
   }
   return new CubeID(cube.getId());
 }
 @Override
 void call(Container container, Deployment deployment) {
   containerContext.get().activate(container.getName());
   deploymentContext.get().activate(deployment);
 }