class DanglingArtifactsService extends AbstractLifecycleComponent implements ClusterStateListener {

    private static final Logger LOGGER = LogManager.getLogger(DanglingArtifactsService.class);

    private final ClusterService clusterService;
    private final List<Pattern> danglingPatterns;

    @Inject
    public DanglingArtifactsService(ClusterService clusterService) {
        this.clusterService = clusterService;
        this.danglingPatterns = IndexParts.DANGLING_INDICES_PREFIX_PATTERNS
            .stream()
            .map(Pattern::compile)
            .collect(Collectors.toList());
    }

    @Override
    protected void doStart() {
        clusterService.addListener(this);
    }

    @Override
    protected void doStop() {
        clusterService.removeListener(this);
    }

    @Override
    protected void doClose() {
    }

    @Override
    public void clusterChanged(ClusterChangedEvent event) {<FILL_FUNCTION_BODY>}
}

        if (LOGGER.isInfoEnabled() && event.isNewCluster()) {
            for (ObjectCursor<String> key : event.state().metadata().indices().keys()) {
                for (Pattern pattern : danglingPatterns) {
                    if (pattern.matcher(key.value).matches()) {
                        LOGGER.info("Dangling artifacts exist in the cluster. Use 'alter cluster gc dangling artifacts;' to remove them");
                        doStop();
                        return;
                    }
                }
            }
        }
    
<methods>public void addLifecycleListener(org.elasticsearch.common.component.LifecycleListener) ,public void close() ,public org.elasticsearch.common.component.Lifecycle.State lifecycleState() ,public void removeLifecycleListener(org.elasticsearch.common.component.LifecycleListener) ,public void start() ,public void stop() <variables>protected final org.elasticsearch.common.component.Lifecycle lifecycle,private final List<org.elasticsearch.common.component.LifecycleListener> listeners