Google Cloud Dataflow SDK for Java, version 1.9.1
Class CustomCoder<T>
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.coders.StandardCoder<T>
-
- com.google.cloud.dataflow.sdk.coders.DeterministicStandardCoder<T>
-
- com.google.cloud.dataflow.sdk.coders.AtomicCoder<T>
-
- com.google.cloud.dataflow.sdk.coders.CustomCoder<T>
-
- Type Parameters:
T
- the type of elements handled by this coder
- All Implemented Interfaces:
- Coder<T>, Serializable
- Direct Known Subclasses:
- DelegateCoder
public abstract class CustomCoder<T> extends AtomicCoder<T> implements Serializable
An abstract base class for writing aCoder
class that encodes itself via Java serialization.To complete an implementation, subclasses must implement
Coder.encode(T, java.io.OutputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)
andCoder.decode(java.io.InputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)
methods. Anonymous subclasses must furthermore overridegetEncodingId()
.Not to be confused with
SerializableCoder
that encodes objects that implement theSerializable
interface.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.cloud.dataflow.sdk.coders.Coder
Coder.Context, Coder.NonDeterministicException
-
-
Constructor Summary
Constructors Constructor and Description CustomCoder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description com.google.cloud.dataflow.sdk.util.CloudObject
asCloudObject()
Returns theCloudObject
that represents thisCoder
.String
getEncodingId()
An identifier for the binary format written byCoder.encode(T, java.io.OutputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)
.static CustomCoder<?>
of(String typeId, String encodingId, String type, String serializedCoder)
void
verifyDeterministic()
ThrowCoder.NonDeterministicException
if the coding is not deterministic.-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.AtomicCoder
getCoderArguments, getInstanceComponents
-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder
consistentWithEquals, equals, getAllowedEncodings, getComponents, getEncodedElementByteSize, hashCode, isRegisterByteSizeObserverCheap, registerByteSizeObserver, structuralValue, toString, verifyDeterministic, verifyDeterministic
-
-
-
-
Method Detail
-
of
public static CustomCoder<?> of(String typeId, String encodingId, String type, String serializedCoder)
-
asCloudObject
public com.google.cloud.dataflow.sdk.util.CloudObject asCloudObject()
Returns theCloudObject
that represents thisCoder
.- Specified by:
asCloudObject
in interfaceCoder<T>
- Overrides:
asCloudObject
in classStandardCoder<T>
- Returns:
- A thin
CloudObject
wrapping of the Java serialization ofthis
.
-
verifyDeterministic
public void verifyDeterministic() throws Coder.NonDeterministicException
ThrowCoder.NonDeterministicException
if the coding is not deterministic.In order for a
Coder
to be considered deterministic, the following must be true:- two values that compare as equal (via
Object.equals()
orComparable.compareTo()
, if supported) have the same encoding. - the
Coder
always produces a canonical encoding, which is the same for an instance of an object even if produced on different computers at different times.
- Specified by:
verifyDeterministic
in interfaceCoder<T>
- Overrides:
verifyDeterministic
in classDeterministicStandardCoder<T>
- Throws:
NonDeterministicException
- aCustomCoder
is presumed nondeterministic.Coder.NonDeterministicException
- if this coder is not deterministic.
- two values that compare as equal (via
-
getEncodingId
public String getEncodingId()
An identifier for the binary format written byCoder.encode(T, java.io.OutputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)
.This value, along with the fully qualified class name, forms an identifier for the binary format of this coder. Whenever this value changes, the new encoding is considered incompatible with the prior format: It is presumed that the prior version of the coder will be unable to correctly read the new format and the new version of the coder will be unable to correctly read the old format.
If the format is changed in a backwards-compatible way (the Coder can still accept data from the prior format), such as by adding optional fields to a Protocol Buffer or Avro definition, and you want Dataflow to understand that the new coder is compatible with the prior coder, this value must remain unchanged. It is then the responsibility of
Coder.decode(java.io.InputStream, com.google.cloud.dataflow.sdk.coders.Coder.Context)
to correctly read data from the prior format.- Specified by:
getEncodingId
in interfaceCoder<T>
- Overrides:
getEncodingId
in classStandardCoder<T>
- Returns:
- The canonical class name for this coder. For stable data formats that are independent of class name, it is recommended to override this method.
- Throws:
UnsupportedOperationException
- when an anonymous class is used, since they do not have a stable canonical class name.
-
-