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

io.vlingo.actors.PooledCompletes 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-2018 Vaughn Vernon. 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;

import io.vlingo.common.Completes;

public class PooledCompletes implements CompletesEventually {
  public final Completes clientCompletes;
  public final CompletesEventually completesEventually;
  public final long id;
  private Object outcome;

  @SuppressWarnings("unchecked")
  public PooledCompletes(
          final long id,
          final Completes clientCompletes,
          final CompletesEventually completesEventually) {
    this.id = id;
    this.clientCompletes = (Completes) clientCompletes;
    this.completesEventually = completesEventually;
  }

  @Override
  public Address address() {
    return completesEventually.address();
  }

  public Object outcome() {
    return outcome;
  }

  @Override
  public void with(final Object outcome) {
    this.outcome = outcome;
    completesEventually.with(this);
  }

  @Override
  public boolean isStopped() {
    return completesEventually.isStopped();
  }

  @Override
  public void stop() { }

  @Override
  public int hashCode() {
    return 31 * address().hashCode();
  }

  @Override
  public boolean equals(final Object other) {
    if (other == null || other.getClass() != getClass()) {
      return false;
    }
    return address().equals(((PooledCompletes)other).address());
  }

  @Override
  public String toString() {
    return "PooledCompletes[id=" + id + " address=" + address() + "]";
  }
}