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

io.vlingo.actors.plugin.completes.DefaultCompletesEventuallyProviderKeeper Maven / Gradle / Ivy

Go to download

Type safe Actor Model toolkit for reactive concurrency and resiliency using Java and other JVM languages.

There is a newer version: 1.7.5
Show newest version
// Copyright © 2012-2020 VLINGO LABS. All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL
// was not distributed with this file, You can obtain
// one at https://mozilla.org/MPL/2.0/.

package io.vlingo.actors.plugin.completes;

import io.vlingo.actors.CompletesEventuallyProvider;
import io.vlingo.actors.CompletesEventuallyProviderKeeper;

public final class DefaultCompletesEventuallyProviderKeeper implements CompletesEventuallyProviderKeeper {
  private CompletesEventuallyProviderInfo completesEventuallyProviderInfo;

  public DefaultCompletesEventuallyProviderKeeper() { }

  @Override
  public CompletesEventuallyProvider providerFor(final String name) {
    if (completesEventuallyProviderInfo == null) {
      throw new IllegalStateException("No registered CompletesEventuallyProvider named " + name);
    }
    return completesEventuallyProviderInfo.completesEventuallyProvider;
  }

  @Override
  public void close() {
    if (completesEventuallyProviderInfo != null) {
      completesEventuallyProviderInfo.completesEventuallyProvider.close();
    }
  }

  @Override
  public CompletesEventuallyProvider findDefault() {
    if (completesEventuallyProviderInfo == null) {
      throw new IllegalStateException("No registered default CompletesEventuallyProvider.");
    }
    return completesEventuallyProviderInfo.completesEventuallyProvider;
  }

  @Override
  public void keep(final String name, final CompletesEventuallyProvider completesEventuallyProvider) {
    completesEventuallyProviderInfo = new CompletesEventuallyProviderInfo(name, completesEventuallyProvider, true);
  }

  final class CompletesEventuallyProviderInfo {
    final boolean isDefault;
    final CompletesEventuallyProvider completesEventuallyProvider;
    final String name;

    CompletesEventuallyProviderInfo(final String name, final CompletesEventuallyProvider completesEventuallyProvider, final boolean isDefault) {
      this.name = name;
      this.completesEventuallyProvider = completesEventuallyProvider;
      this.isDefault = isDefault;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy