Repository: beam Updated Branches: refs/heads/master 019d3002b -> dabad1ae5
Remove context from size estimate operations. Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/78a99be1 Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/78a99be1 Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/78a99be1 Branch: refs/heads/master Commit: 78a99be1c46656996081744e52dac3d619cb4fe7 Parents: 019d300 Author: Robert Bradshaw <[email protected]> Authored: Fri May 5 15:18:52 2017 -0700 Committer: Luke Cwik <[email protected]> Committed: Sat May 6 19:23:50 2017 -0700 ---------------------------------------------------------------------- .../java/org/apache/beam/sdk/coders/Coder.java | 52 ++++---------------- 1 file changed, 10 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/beam/blob/78a99be1/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java index eeafbd2..d140e89 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java @@ -301,40 +301,10 @@ public abstract class Coder<T> implements Serializable { * unless it is overridden. This is considered expensive. */ public boolean isRegisterByteSizeObserverCheap(T value) { - return isRegisterByteSizeObserverCheap(value, Context.NESTED); - } - - /** - * {@inheritDoc} - * - * <p>Not intended to be called by user code, but instead by - * {@link PipelineRunner} - * implementations. - * - * @return {@code false} unless it is overridden. {@link StructuredCoder#registerByteSizeObserver} - * invokes {@link #getEncodedElementByteSize} which requires re-encoding an element - * unless it is overridden. This is considered expensive. - */ - @Deprecated - public boolean isRegisterByteSizeObserverCheap(T value, Context context) { return false; } /** - * Returns the size in bytes of the encoded value using this coder. - */ - protected long getEncodedElementByteSize(T value, Context context) - throws Exception { - try (CountingOutputStream os = new CountingOutputStream(ByteStreams.nullOutputStream())) { - encode(value, os, context); - return os.getCount(); - } catch (Exception exn) { - throw new IllegalArgumentException( - "Unable to encode element '" + value + "' with coder '" + this + "'.", exn); - } - } - - /** * Notifies the {@code ElementByteSizeObserver} about the byte size * of the encoded value using this {@code Coder}. * @@ -347,22 +317,20 @@ public abstract class Coder<T> implements Serializable { */ public void registerByteSizeObserver(T value, ElementByteSizeObserver observer) throws Exception { - registerByteSizeObserver(value, observer, Context.NESTED); + observer.update(getEncodedElementByteSize(value)); } /** - * Notifies the {@code ElementByteSizeObserver} about the byte size - * of the encoded value using this {@code Coder}. - * - * <p>Not intended to be called by user code, but instead by - * {@link PipelineRunner} - * implementations. + * Returns the size in bytes of the encoded value using this coder. */ - @Deprecated - public void registerByteSizeObserver( - T value, ElementByteSizeObserver observer, Context context) - throws Exception { - observer.update(getEncodedElementByteSize(value, context)); + protected long getEncodedElementByteSize(T value) throws Exception { + try (CountingOutputStream os = new CountingOutputStream(ByteStreams.nullOutputStream())) { + encode(value, os); + return os.getCount(); + } catch (Exception exn) { + throw new IllegalArgumentException( + "Unable to encode element '" + value + "' with coder '" + this + "'.", exn); + } } /**
