Package de.stklcode.pubtrans.ura.reader
Class AsyncUraTripReader
java.lang.Object
de.stklcode.pubtrans.ura.reader.AsyncUraTripReader
- All Implemented Interfaces:
java.lang.AutoCloseable
public class AsyncUraTripReader
extends java.lang.Object
implements java.lang.AutoCloseable
Asynchronous stream reader for URA stream API.
This reader provides a handler for asynchronous stream events.
- Since:
- 1.2.0
- Author:
- Stefan Kalscheuer
-
Constructor Summary
Constructors Constructor Description AsyncUraTripReader(java.net.URI uri, UraClientConfiguration config, java.util.List<java.util.function.Consumer<Trip>> consumers)Initialize trip reader.AsyncUraTripReader(java.net.URI uri, java.util.function.Consumer<Trip> consumer)Initialize trip reader.AsyncUraTripReader(java.net.URI uri, java.util.List<java.util.function.Consumer<Trip>> consumers)Initialize trip reader. -
Method Summary
Modifier and Type Method Description voidaddConsumer(java.util.function.Consumer<Trip> consumer)Register an additional consumer.voidclose()Close the reader.voidopen()Open the reader, i.e. initiate connection to the API and start reading the response stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
AsyncUraTripReader
Initialize trip reader.- Parameters:
uri- URL to read trips from.consumer- Initial consumer.- Since:
- 2.0 Parameter of Type
URIinstead ofURL.
-
AsyncUraTripReader
public AsyncUraTripReader(java.net.URI uri, java.util.List<java.util.function.Consumer<Trip>> consumers)Initialize trip reader.- Parameters:
uri- URL to read trips from.consumers- Initial list of consumers.- Since:
- 2.0 Parameter of Type
URIinstead ofURL.
-
AsyncUraTripReader
public AsyncUraTripReader(java.net.URI uri, UraClientConfiguration config, java.util.List<java.util.function.Consumer<Trip>> consumers)Initialize trip reader.- Parameters:
uri- URL to read trips from.config- Client configuration for additional parameters.consumers- Initial list of consumers.- Since:
- 2.0 Configuration added.
-
-
Method Details
-
open
public void open()Open the reader, i.e. initiate connection to the API and start reading the response stream. -
addConsumer
Register an additional consumer.- Parameters:
consumer- New consumer.
-
close
public void close()Close the reader. This is done by signaling cancel to the asynchronous task. If the task is not completed within 1 second however it is canceled hard.- Specified by:
closein interfacejava.lang.AutoCloseable
-