<commit_before>package org.realityforge.replicant.client.transport;

import arez.annotations.Action;
import arez.annotations.Observable;
import java.util.ArrayList;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.realityforge.anodoc.TestOnly;
import replicant.Replicant;
import static org.realityforge.braincheck.Guards.*;

public class ReplicantClientSystem
{
  public enum State
  {
    /// The service is not yet connected or has been disconnected
    DISCONNECTED,
    /// The service has started connecting but connection has not completed.
    CONNECTING,
    /// The service is connected.
    CONNECTED,
    /// The service has started disconnecting but disconnection has not completed.
    DISCONNECTING,
    /// The service is in error state. This error may occur during connection, disconnection or in normal operation.
    ERROR
  }

  protected static final int CONVERGE_DELAY_IN_MS = 2000;

  private static final Logger LOG = Logger.getLogger( ReplicantClientSystem.class.getName() );

  private final ArrayList<DataLoaderEntry> _dataLoaders = new ArrayList<>();
  private State _state = State.DISCONNECTED;
  /**
   * If true then the desired state is CONNECTED while if false then the desired state is DISCONNECTED.
   */
  private boolean _active;

  final void registerDataSource( @Nonnull final DataLoaderService service )
  {
    if ( Replicant.shouldCheckInvariants() )
    {
      invariant( () -> _dataLoaders.stream()
                   .noneMatch( e -> e.getService().getSystemType() == service.getSystemType() ),
                 () -> "Replicant-0005: Invoked registerDataSource for system type " + service.getSystemType() +
                       " but a DataLoaderService for specified system type exists." );
    }
    _dataLoaders.add( new DataLoaderEntry( service, true ) );
  }

  final void deregisterDataSource( @Nonnull final DataLoaderService service )
  {
    if ( Replicant.shouldCheckInvariants() )
    {
      invariant( () -> _dataLoaders.stream()
                   .anyMatch( e -> e.getService().getSystemType() == service.getSystemType() ),
                 () -> "Replicant-0006: Invoked deregisterDataSource for system type " + service.getSystemType() +
                       " but no DataLoaderService for specified system type exists." );
    }
    _dataLoaders.removeIf( e -> e.getService().getSystemType() == service.getSystemType() );
  }

  //TODO: This should be package access
  public void setDataSourceRequired( @Nonnull final Class<?> systemType, final boolean required )
  {<commit_msg>Use unique error message prefix<commit_after>package org.realityforge.replicant.client.transport;

import arez.annotations.Action;
import arez.annotations.Observable;
import java.util.ArrayList;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.realityforge.anodoc.TestOnly;
import replicant.Replicant;
import static org.realityforge.braincheck.Guards.*;

public class ReplicantClientSystem
{
  public enum State
  {
    /// The service is not yet connected or has been disconnected
    DISCONNECTED,
    /// The service has started connecting but connection has not completed.
    CONNECTING,
    /// The service is connected.
    CONNECTED,
    /// The service has started disconnecting but disconnection has not completed.
    DISCONNECTING,
    /// The service is in error state. This error may occur during connection, disconnection or in normal operation.
    ERROR
  }

  protected static final int CONVERGE_DELAY_IN_MS = 2000;

  private static final Logger LOG = Logger.getLogger( ReplicantClientSystem.class.getName() );

  private final ArrayList<DataLoaderEntry> _dataLoaders = new ArrayList<>();
  private State _state = State.DISCONNECTED;
  /**
   * If true then the desired state is CONNECTED while if false then the desired state is DISCONNECTED.
   */
  private boolean _active;

  final void registerDataSource( @Nonnull final DataLoaderService service )
  {
    if ( Replicant.shouldCheckInvariants() )
    {
      invariant( () -> _dataLoaders.stream()
                   .noneMatch( e -> e.getService().getSystemType() == service.getSystemType() ),
                 () -> "Replicant-0015: Invoked registerDataSource for system type " + service.getSystemType() +
                       " but a DataLoaderService for specified system type exists." );
    }
    _dataLoaders.add( new DataLoaderEntry( service, true ) );
  }

  final void deregisterDataSource( @Nonnull final DataLoaderService service )
  {
    if ( Replicant.shouldCheckInvariants() )
    {
      invariant( () -> _dataLoaders.stream()
                   .anyMatch( e -> e.getService().getSystemType() == service.getSystemType() ),
                 () -> "Replicant-0006: Invoked deregisterDataSource for system type " + service.getSystemType() +
                       " but no DataLoaderService for specified system type exists." );
    }
    _dataLoaders.removeIf( e -> e.getService().getSystemType() == service.getSystemType() );
  }

  //TODO: This should be package access
  public void setDataSourceRequired( @Nonnull final Class<?> systemType, final boolean required )
  {
{'fraction_non_alphanumeric': 0.0930493273542601, 'fraction_numerical': 0.004484304932735426, 'mean_word_length': 3.3274050121261114, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5633088', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1420, 'n_words': 434}