Source:
public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance) state.getResource(); if (instance == null) { return null; } Service service = loadService(instance); if (service == null) { return null; } List<Service> activeLbServices = lookupAllActiveLBServices(service); List<? extends Instance> lbInstances = getLBServiceInstances(activeLbServices); if (!lbInstances.isEmpty()) { objectManager.setFields(instance, ObjectMetaDataManager.TRANSITIONING_MESSAGE_FIELD, "Draining..."); } String targetIpAddress = DataAccessor.fieldString(instance, InstanceConstants.FIELD_PRIMARY_IP_ADDRESS); Map<String, Object> labels = DataAccessor.fieldMap(instance, InstanceConstants.FIELD_LABELS); String launchConfigName = labels.get(LABEL_SERVICE_LAUNCH_CONFIG) != null ? labels.get(LABEL_SERVICE_LAUNCH_CONFIG).toString() : null; Object drainTimeout = ServiceDiscoveryUtil.getLaunchConfigObject(service, launchConfigName, ServiceConstants.FIELD_DRAIN_TIMEOUT); Map<Instance, ListenableFuture<? extends Event>> drainFutures = new HashMap<>(); for (Instance lbInstance : lbInstances) { ListenableFuture<? extends Event> future = drainBackend(lbInstance, instance, targetIpAddress, drainTimeout); if (future != null) { drainFutures.put(lbInstance, future); } } for (Map.Entry<Instance, ListenableFuture<? extends Event>> entry : drainFutures.entrySet()) { Instance lbInstance = entry.getKey(); RemoteAgent agent = agentLocator.lookupAgent(lbInstance); ListenableFuture<? extends Event> future = entry.getValue(); try { AsyncUtils.get(future); log.debug("Got reply to event from AgentId for the target: " + agent.getAgentId()); } catch (EventExecutionException e) { log.debug("Got error: {}, to event from LB Agent: ", e, agent.getAgentId()); throw new ExecutionException(e); } } return null; }

Target:
public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance) state.getResource(); if (instance == null) { return null; } Service service = loadService(instance); if (service == null) { return null; } Map<String, Object> labels = DataAccessor.fieldMap(instance, InstanceConstants.FIELD_LABELS); String launchConfigName = labels.get(LABEL_SERVICE_LAUNCH_CONFIG) != null ? labels.get(LABEL_SERVICE_LAUNCH_CONFIG).toString() : null; Integer drainTimeout = (Integer) ServiceDiscoveryUtil.getLaunchConfigObject(service, launchConfigName, ServiceConstants.FIELD_DRAIN_TIMEOUT); if (drainTimeout == null || (drainTimeout == 0)) { return null; } List<Service> activeLbServices = lookupAllActiveLBServices(service); List<? extends Instance> lbInstances = getLBServiceInstances(activeLbServices); if (!lbInstances.isEmpty()) { objectManager.setFields(instance, ObjectMetaDataManager.TRANSITIONING_MESSAGE_FIELD, "Draining..."); } String targetIpAddress = DataAccessor.fieldString(instance, InstanceConstants.FIELD_PRIMARY_IP_ADDRESS); Map<Instance, ListenableFuture<? extends Event>> drainFutures = new HashMap<>(); for (Instance lbInstance : lbInstances) { ListenableFuture<? extends Event> future = drainBackend(lbInstance, instance, targetIpAddress, drainTimeout.toString()); if (future != null) { drainFutures.put(lbInstance, future); } } for (Map.Entry<Instance, ListenableFuture<? extends Event>> entry : drainFutures.entrySet()) { Instance lbInstance = entry.getKey(); RemoteAgent agent = agentLocator.lookupAgent(lbInstance); ListenableFuture<? extends Event> future = entry.getValue(); try { AsyncUtils.get(future); log.debug("Got reply to event from AgentId for the target: " + agent.getAgentId()); } catch (EventExecutionException e) { log.debug("Got error: {}, to event from LB Agent: ", e, agent.getAgentId()); throw new ExecutionException(e); } } return null; }