no.mnemonic.services.common.api.annotations.ResultSetExtention Maven / Gradle / Ivy
Show all versions of service-api Show documentation
package no.mnemonic.services.common.api.annotations;
import no.mnemonic.services.common.api.ResultSet;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.function.Function;
/**
* Any method returning a ResultSet will be streamed back to the Service Client.
* However, if the client interface expects a subtype of ResultSet, the client
* side needs a ResultSet extender function to convert a plain resultset returned by the
* Service Client to the type actually declared by the method.
*
* To do this, annotate the extended ResultSet type <T>
with
* @ResultSetExtention(extender=MyResultSetExtender.class)
,
* specifying an extender which can handle the result.
*
* The extender must be a type with a zero-argument constructor,
* and implement Function<ResultSet, T>.
*
* The extender should make sure to wrap the iterator of the ResultSet to retain
* streaming capabilities, i.e. iterate each element as it is requested by the client side.
* If the extender iterates all elements up-front, that will cause the underlying ResultSet to block until
* all elements are received, effectively disabling the effect of the streaming resultset.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface ResultSetExtention {
Class extends Function, ? extends ResultSet>>> extender();
}