com.tangosol.net.topic.Publisher Maven / Gradle / Ivy
Show all versions of coherence Show documentation
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
package com.tangosol.net.topic;
import com.oracle.coherence.common.util.Options;
import com.tangosol.io.ExternalizableLite;
import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;
import com.tangosol.net.FlowControl;
import com.tangosol.util.Base;
import com.tangosol.util.ExternalizableHelper;
import com.tangosol.util.function.Remote;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.ToIntFunction;
/**
* Publisher provides a means to publish values to the {@link NamedTopic}.
*
* The factory method {@link NamedTopic#createPublisher(Publisher.Option[])} allows one to specify
* one or more {@link Publisher.Option}s to configure the {@link Publisher}.
*
* Since the {@link #send(Object)} method is asynchronous, there is a {@link #flush()} that allows one to block until all outstanding
* {@link #send sent values} for the {@link Publisher} have completed.
*
* @param the value type
*
* @author jf/jk/mf 2015.06.03
* @since Coherence 14.1.1
*/
public interface Publisher
extends AutoCloseable
{
/**
* Asynchronously publish the specified value to the topic.
*
* {@link CompletableFuture#cancel(boolean) Cancellation} of the returned future
* is best effort and is not guaranteed to stop the corresponding publication of the value.
*
* @param value the value to add to the topic
*
* @return a {@link CompletableFuture} which can be used to identify
* when the value has been delivered to the topic
*/
public CompletableFuture send(V value);
/**
* Return the {@link FlowControl} object governing this publisher.
*
* @return the FlowControl object.
*/
public FlowControl getFlowControl();
/**
* Obtain a {@link CompletableFuture} that will be complete when
* all of the currently outstanding publish operations complete.
*
* The returned {@link CompletableFuture} will always complete
* normally, even if the outstanding operations complete exceptionally.
*
* @return a {@link CompletableFuture} that will be completed when
* all of the currently outstanding publish operations are complete
*/
public CompletableFuture flush();
/**
* Close this {@link Publisher}.
*
* This is a blocking method and will wait until all outstanding
* {@link CompletableFuture}s returned from previous calls
* to {@link #send(Object)} have completed before returning.
*/
@Override
public void close();
/**
* Add an action to be executed when this {@link Publisher} is closed.
*
* @param action the action to execute
*/
public void onClose(Runnable action);
// ----- inner interface: Option ----------------------------------------
/**
* A marker interface to indicate that a class is a valid {@link Option}
* for a {@link Publisher}.
*
*
* Options to use with {@link NamedTopic#createPublisher(Publisher.Option...)}
*
* Publisher Option
* Description
*
*
* {@link OnFailure#Stop}
* Default. If an individual {@link #send} invocation fails then stop any further publishing and close the {@link Publisher}.
*
*
* {@link OnFailure#Continue}
* If an individual {@link #send} invocation fails then skip that value and continue to publish other values.
*
*
* {@link FailOnFull FailOnFull.enabled()}
* When the storage size of the unprocessed values on the topic exceed a configured high-units,
* the {@link CompletableFuture} returned from the {@link #send} invocation should complete exceptionally.
*
Overrides the default to block completing until the operation completes when space becomes available.
*
*
* {@link OrderBy#thread()}
* Default. Ensure that all {@link #send values sent} from
* the same thread are stored sequentially.
*
*
* {@link OrderBy#none()}
* Enforce no specific ordering between {@link #send sent values} allowing
* for the greatest level of parallelism
*
*
* {@link OrderBy#id(int)}
* Ensure ordering of {@link #send sent values} across
* all threads which share the same id.
*
*
* {@link OrderBy#value(ToIntFunction)}
* Compute the unit-of-order based on the applying this method on {@link #send sent value}
*
*
* {@link OrderBy#value(Remote.ToIntFunction)}
* Compute the unit-of-order based on the applying this method on {@link #send sent value}
*
*
*/
public interface Option
{
}
// ----- inner class: OnFailure -----------------------------------------
/**
* This option controls how a {@link Publisher} handles a failure of an individual
* {@link #send} call.
*/
public enum OnFailure
implements Option