All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.apollographql.apollo3.runtime.java.internal.DefaultApolloDisposable Maven / Gradle / Ivy

There is a newer version: 4.0.0-beta.7
Show newest version
package com.apollographql.apollo3.runtime.java.internal;

import com.apollographql.apollo3.runtime.java.ApolloDisposable;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;

public class DefaultApolloDisposable implements ApolloDisposable {

  private AtomicBoolean isDisposed = new AtomicBoolean(false);
  private ArrayList listeners = new ArrayList<>();

  @Override public boolean isDisposed() {
    return isDisposed.get();
  }

  @Override public void addListener(Listener listener) {
    synchronized (listeners) {
      listeners.add(listener);
    }
  }

  @Override public void removeListener(Listener listener) {
    synchronized (listeners) {
      listeners.remove(listener);
    }
  }

  @Override public void dispose() {
    isDisposed.set(true);
    synchronized (listeners) {
      listeners.forEach(listener -> {
        listener.onDisposed();
      });
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy