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

io.zeebe.gossip.protocol.MembershipEventConsumer Maven / Gradle / Ivy

There is a newer version: 0.16.4
Show newest version
/*
 * Copyright © 2017 camunda services GmbH ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.zeebe.gossip.protocol;

@FunctionalInterface
public interface MembershipEventConsumer {
  /**
   * Consume the given event.
   *
   * @return true when the event is new (i.e. the internal state has changed).
   */
  boolean consumeMembershipEvent(MembershipEvent event);

  /**
   * Return a composed consumer that invoke this consumer followed by the given consumer. The next
   * consumer if only invoked when the previous consumer returns true.
   */
  default MembershipEventConsumer andThen(MembershipEventConsumer nextConsumer) {
    return event -> {
      boolean changed = consumeMembershipEvent(event);
      if (changed) {
        changed = nextConsumer.consumeMembershipEvent(event);
      }
      return changed;
    };
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy