<commit_before>/* DO NOT EDIT: File is auto-generated */
package <%= to_package(repository.gwt_rpc.qualified_rpc_services_dagger_module_name) %>;

@javax.annotation.Generated( "Domgen" )
@java.lang.SuppressWarnings( { "UnusedDeclaration", "JavaDoc", "PMD.FieldDeclarationsShouldBeAtStartOfClass", "PMD.UseUtilityClass" } )
@dagger.Module
public class <%= repository.gwt_rpc.rpc_services_dagger_module_name %>
{
<% if repository.keycloak? -%>
  private static final int MIN_TOKEN_VALIDITY_SECONDS = 15;
  @javax.annotation.Nullable
  private static org.realityforge.gwt.keycloak.Keycloak c_keycloak;
<% end -%>
  private static String c_baseURL;
<% if repository.imit? -%>
  private static replicant.Request c_request;
<% end -%>
<% if repository.keycloak? -%>

  @javax.annotation.Nonnull
  public static org.realityforge.gwt.keycloak.Keycloak getKeycloak()
  {
    if ( org.realityforge.braincheck.BrainCheckConfig.checkInvariants() )
    {
      org.realityforge.braincheck.Guards.invariant( () -> null != c_keycloak,
                                                    () -> "Keycloak not configured when calling <%= repository.gwt_rpc.rpc_services_dagger_module_name %>.getKeycloak()" );
    }
    assert null != c_keycloak;
    return c_keycloak;
  }

  public static void setKeycloak( @javax.annotation.Nonnull final org.realityforge.gwt.keycloak.Keycloak keycloak )
  {
    c_keycloak = keycloak;
  }

  public static void updateTokenAndExecute( @javax.annotation.Nonnull final java.lang.Runnable action )
  {
    if ( null == c_keycloak )
    {
      action.run();
    }
    else
    {
      c_keycloak.updateToken( MIN_TOKEN_VALIDITY_SECONDS, action );
    }
  }

<% end -%>
<% if repository.imit? -%>
  public static void setRequest( @javax.annotation.Nullable final replicant.Request request )
  {
    c_request = request;
  }

  @javax.annotation.Nullable
  public static replicant.Request getRequest()
  {
    return c_request;
  }

  @javax.annotation.Nonnull
  public static replicant.WebSocketConfig newWebSocketConfig()
  {
    return new replicant.WebSocketConfig( getBaseURL().replace( "https://", "wss://" ).replace( "http://", "ws://" ) + "api" + org.realityforge.replicant.shared.SharedConstants.REPLICANT_URL_FRAGMENT, RoseGwtRpcServicesDaggerModule::updateTokenAndExecute, () -> RoseGwtRpcServicesDaggerModule.getKeycloak().getToken() );
  }
<% end -%>

  public static void setBaseURL( @javax.annotation.Nonnull final String baseURL )<commit_msg>Ensure that actions that are pending token update are executed in the queued order<commit_after>/* DO NOT EDIT: File is auto-generated */
package <%= to_package(repository.gwt_rpc.qualified_rpc_services_dagger_module_name) %>;

@javax.annotation.Generated( "Domgen" )
@java.lang.SuppressWarnings( { "UnusedDeclaration", "JavaDoc", "PMD.FieldDeclarationsShouldBeAtStartOfClass", "PMD.UseUtilityClass" } )
@dagger.Module
public class <%= repository.gwt_rpc.rpc_services_dagger_module_name %>
{
<% if repository.keycloak? -%>
  private static final int MIN_TOKEN_VALIDITY_SECONDS = 15;
  @javax.annotation.Nullable
  private static org.realityforge.gwt.keycloak.Keycloak c_keycloak;
  @javax.annotation.Nonnull
  private static java.util.ArrayList<java.lang.Runnable> c_actions = new java.util.ArrayList<>();
<% end -%>
  private static String c_baseURL;
<% if repository.imit? -%>
  private static replicant.Request c_request;
<% end -%>
<% if repository.keycloak? -%>

  @javax.annotation.Nonnull
  public static org.realityforge.gwt.keycloak.Keycloak getKeycloak()
  {
    if ( org.realityforge.braincheck.BrainCheckConfig.checkInvariants() )
    {
      org.realityforge.braincheck.Guards.invariant( () -> null != c_keycloak,
                                                    () -> "Keycloak not configured when calling <%= repository.gwt_rpc.rpc_services_dagger_module_name %>.getKeycloak()" );
    }
    assert null != c_keycloak;
    return c_keycloak;
  }

  public static void setKeycloak( @javax.annotation.Nonnull final org.realityforge.gwt.keycloak.Keycloak keycloak )
  {
    c_keycloak = keycloak;
  }

  public static void updateTokenAndExecute( @javax.annotation.Nonnull final java.lang.Runnable action )
  {
    if ( null == c_keycloak )
    {
      action.run();
    }
    else
    {
      c_actions.add( action );
      c_keycloak.updateToken( MIN_TOKEN_VALIDITY_SECONDS, () -> {
        c_actions.forEach( java.lang.Runnable::run );
        c_actions.clear();
      } );
    }
  }

<% end -%>
<% if repository.imit? -%>
  public static void setRequest( @javax.annotation.Nullable final replicant.Request request )
  {
    c_request = request;
  }

  @javax.annotation.Nullable
  public static replicant.Request getRequest()
  {
    return c_request;
  }

  @javax.annotation.Nonnull
  public static replicant.WebSocketConfig newWebSocketConfig()
  {
    return new replicant.WebSocketConfig( getBaseURL().replace( "https://", "wss://" ).replace( "http://", "ws://" ) + "api" + org.realityforge.replicant.shared.SharedConstants.REPLICANT_URL_FRAGMENT, RoseGwtRpcServicesDaggerModule::updateTokenAndExecute, () -> RoseGwtRpcServicesDaggerModule.getKeycloak().getToken() );
  }
<% end -%>

  public static void setBaseURL( @javax.annotation.Nonnull final String baseURL )
{'fraction_non_alphanumeric': 0.12152909851654621, 'fraction_numerical': 0.0007607455306200076, 'mean_word_length': 3.8966480446927374, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 34, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7589394', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1720, 'n_words': 308}