class DefaultAgentCache implements AgentCache {

    @Override
    public Single<AgentInstanceGroup> updateInstanceGroupStore(String instanceGroupId, Function<AgentInstanceGroup, AgentInstanceGroup> function) {
        Single<AgentInstanceGroup> single = onEventLoopWithSubscription(() -> {
            AgentInstanceGroup instanceGroup = getInstanceGroup(instanceGroupId);
            Set<AgentInstance> agentInstances = dataSnapshot.getInstances(instanceGroup.getId());
            if (agentInstances == null) {
                agentInstances = Collections.emptySet();
            }
            AgentInstanceGroup updatedInstanceGroup = function.apply(instanceGroup);
            setDataSnapshot(dataSnapshot.updateInstanceGroup(updatedInstanceGroup, agentInstances));
            eventSubject.onNext(new CacheUpdateEvent(CacheUpdateType.InstanceGroup, instanceGroupId));
            return updatedInstanceGroup;
        });
        return single.flatMap(ig -> agentStore.storeAgentInstanceGroup(ig).toSingle(() -> ig));
    }

    @Inject public  DefaultAgentCache(AgentManagementConfiguration configuration,
                             AgentStore agentStore,
                             InstanceCloudConnector connector,
                             Registry registry);
      DefaultAgentCache(AgentManagementConfiguration configuration,
                      AgentStore agentStore,
                      InstanceCloudConnector connector,
                      Registry registry,
                      Scheduler scheduler);

}