title: How to create read transform using ParDo and DoFn in Apache Beam
body: <p>According to the <a href="https://beam.apache.org/documentation/io/authoring-overview/#when-to-implement-using-the-source-ap" rel="nofollow noreferrer">Apache Beam documentation</a> the recommended way 
  to write simple sources is by using Read Transforms and <code>ParDo</code>. Unfortunately the Apache Beam docs has let me down here.</p>
  
  <p>I'm trying to write a simple unbounded data source which emits events using a <code>ParDo</code> but the compiler keeps complaining about the input type of the <code>DoFn</code> object:</p>
  
  <pre><code>message: 'The method apply(PTransform&lt;? super PBegin,OutputT&gt;) in the type PBegin is not applicable for the arguments (ParDo.SingleOutput&lt;PBegin,Event&gt;)'
  </code></pre>
  
  <p>My attempt:</p>
  
  <pre><code>public class TestIO extends PTransform&lt;PBegin, PCollection&lt;Event&gt;&gt; {
  
      @Override
      public PCollection&lt;Event&gt; expand(PBegin input) {
          return input.apply(ParDo.of(new ReadFn()));
      }
  
      private static class ReadFn extends DoFn&lt;PBegin, Event&gt; {
          @ProcessElement
          public void process(@TimerId("poll") Timer pollTimer) {
              Event testEvent = new Event(...);
  
              //custom logic, this can happen infinitely
              for(...) {
                  context.output(testEvent);
              }
          }
      }
  }
  </code></pre>