image.png

    1. /*
    2. * Licensed to the Apache Software Foundation (ASF) under one
    3. * or more contributor license agreements. See the NOTICE file
    4. * distributed with this work for additional information
    5. * regarding copyright ownership. The ASF licenses this file
    6. * to you under the Apache License, Version 2.0 (the
    7. * "License"); you may not use this file except in compliance
    8. * with the License. You may obtain a copy of the License at
    9. *
    10. * http://www.apache.org/licenses/LICENSE-2.0
    11. *
    12. * Unless required by applicable law or agreed to in writing, software
    13. * distributed under the License is distributed on an "AS IS" BASIS,
    14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15. * See the License for the specific language governing permissions and
    16. * limitations under the License.
    17. */
    18. package org.apache.flink.streaming.runtime.streamrecord;
    19. import org.apache.flink.annotation.Internal;
    20. import org.apache.flink.streaming.api.watermark.Watermark;
    21. import org.apache.flink.streaming.runtime.streamstatus.StreamStatus;
    22. /**
    23. * An element in a data stream. Can be a record or a Watermark.
    24. */
    25. @Internal
    26. public abstract class StreamElement {
    27. /**
    28. * Checks whether this element is a watermark.
    29. * @return True, if this element is a watermark, false otherwise.
    30. */
    31. public final boolean isWatermark() {
    32. return getClass() == Watermark.class;
    33. }
    34. /**
    35. * Checks whether this element is a stream status.
    36. * @return True, if this element is a stream status, false otherwise.
    37. */
    38. public final boolean isStreamStatus() {
    39. return getClass() == StreamStatus.class;
    40. }
    41. /**
    42. * Checks whether this element is a record.
    43. * @return True, if this element is a record, false otherwise.
    44. */
    45. public final boolean isRecord() {
    46. return getClass() == StreamRecord.class;
    47. }
    48. /**
    49. * Checks whether this element is a latency marker.
    50. * @return True, if this element is a latency marker, false otherwise.
    51. */
    52. public final boolean isLatencyMarker() {
    53. return getClass() == LatencyMarker.class;
    54. }
    55. /**
    56. * Casts this element into a StreamRecord.
    57. * @return This element as a stream record.
    58. * @throws java.lang.ClassCastException Thrown, if this element is actually not a stream record.
    59. */
    60. @SuppressWarnings("unchecked")
    61. public final <E> StreamRecord<E> asRecord() {
    62. return (StreamRecord<E>) this;
    63. }
    64. /**
    65. * Casts this element into a Watermark.
    66. * @return This element as a Watermark.
    67. * @throws java.lang.ClassCastException Thrown, if this element is actually not a Watermark.
    68. */
    69. public final Watermark asWatermark() {
    70. return (Watermark) this;
    71. }
    72. /**
    73. * Casts this element into a StreamStatus.
    74. * @return This element as a StreamStatus.
    75. * @throws java.lang.ClassCastException Thrown, if this element is actually not a Stream Status.
    76. */
    77. public final StreamStatus asStreamStatus() {
    78. return (StreamStatus) this;
    79. }
    80. /**
    81. * Casts this element into a LatencyMarker.
    82. * @return This element as a LatencyMarker.
    83. * @throws java.lang.ClassCastException Thrown, if this element is actually not a LatencyMarker.
    84. */
    85. public final LatencyMarker asLatencyMarker() {
    86. return (LatencyMarker) this;
    87. }
    88. }