パッケージ org.wcardinal.controller
インタフェース StreamingResult
public interface StreamingResult
When
@Callable /
@Task methods need to
return large set of data, it is preferable to stream those data instead
of consuming large heap memory. This class is for that purpose.
If @Callable /
@Task methods return
StreamingResult, serialize(JsonGenerator)
is called to serialize their return values. Therefore, all the data don't
need to be stored in the heap memory.
Please note that if the methods are not annotated with
@Ajax, the serialized data
still consume the heap memory, although the data themselve don't. Because of
this, the annotating methods with @Ajax
is highly recommended if the serialized data are considered to be large.
import org.wcardinal.controller.StreamingResult;
import org.wcardinal.controller.annotation.Callable;
import org.wcardinal.controller.annotation.Controller;
@Controller
class MyController {
@Ajax
@Callable
StreamingResult callable() {
return (generator) -> {
generator.writeStartArray();
for (int i = 0; i < 3; ++i) {
generator.writeNumber(i);
}
generator.writeEndArray();
};
}
}
Thread Safety
In the case that@Callable /
@Task methods have a lock,
serialize(JsonGenerator) gets called before releasing that lock.
When @Callable /
@Task methods don't have a lock,
a lock isn't aquired automatically before calling serialize(JsonGenerator).-
メソッドの概要
-
メソッドの詳細
-
serialize
- パラメータ:
generator- a JSON generator- 例外:
IOException
-