private Container getContainer(NMCommunicatorEvent event) { ContainerId id = event.getContainerId(); Container c = containers.get(id); if (c == null) { c = new Container( event.getContainerId(), event.getNodeId().toString(), event.getContainerToken()); Container old = containers.putIfAbsent(id, c); if (old != null) { c = old; } } return c; }
@Override public void run() { LOG.info("Processing the event " + event.toString()); // Load ContainerManager tokens before creating a connection. // TODO: Do it only once per NodeManager. ContainerId containerID = event.getContainerId(); Container c = getContainer(event); switch (event.getType()) { case CONTAINER_LAUNCH_REQUEST: NMCommunicatorLaunchRequestEvent launchEvent = (NMCommunicatorLaunchRequestEvent) event; c.launch(launchEvent); break; case CONTAINER_STOP_REQUEST: c.kill(); break; } removeContainerIfDone(containerID); }