Polish
This commit is contained in:
parent
3312ef0aa2
commit
43eea41dd6
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2017 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.web.reactive.result.view;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Rossen Stoyanchev
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
public interface Render {
|
||||||
|
|
||||||
|
Optional<Object> view();
|
||||||
|
|
||||||
|
Map<String, Object> model();
|
||||||
|
|
||||||
|
Optional<HttpStatus> status();
|
||||||
|
|
||||||
|
HttpHeaders headers();
|
||||||
|
|
||||||
|
|
||||||
|
static Builder<?> view(String name) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface Builder<B extends Builder<B>> {
|
||||||
|
|
||||||
|
B modelAttribute(String name, Object value);
|
||||||
|
|
||||||
|
B modelMap(Map<String, ?> model);
|
||||||
|
|
||||||
|
B model(Model model);
|
||||||
|
|
||||||
|
B status(HttpStatus status);
|
||||||
|
|
||||||
|
B header(String headerName, String... headerValues);
|
||||||
|
|
||||||
|
B headers(HttpHeaders headers);
|
||||||
|
|
||||||
|
Render build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -184,15 +184,16 @@ class ReactiveTypeHandler {
|
||||||
|
|
||||||
private Subscription subscription;
|
private Subscription subscription;
|
||||||
|
|
||||||
private final AtomicReference<Object> queue = new AtomicReference<Object>();
|
private final AtomicReference<Object> elementRef = new AtomicReference<>();
|
||||||
|
|
||||||
|
private Throwable error;
|
||||||
|
|
||||||
|
private volatile boolean terminated;
|
||||||
|
|
||||||
private final AtomicLong executing = new AtomicLong();
|
private final AtomicLong executing = new AtomicLong();
|
||||||
|
|
||||||
private volatile boolean done;
|
private volatile boolean done;
|
||||||
|
|
||||||
private volatile boolean terminated;
|
|
||||||
|
|
||||||
private Throwable error;
|
|
||||||
|
|
||||||
protected AbstractEmitterSubscriber(ResponseBodyEmitter emitter, TaskExecutor executor) {
|
protected AbstractEmitterSubscriber(ResponseBodyEmitter emitter, TaskExecutor executor) {
|
||||||
this.emitter = emitter;
|
this.emitter = emitter;
|
||||||
|
|
@ -229,20 +230,20 @@ class ReactiveTypeHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onNext(Object element) {
|
public final void onNext(Object element) {
|
||||||
this.queue.lazySet(element);
|
this.elementRef.lazySet(element);
|
||||||
trySchedule();
|
trySchedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onError(Throwable ex) {
|
public final void onError(Throwable ex) {
|
||||||
error = ex;
|
this.error = ex;
|
||||||
terminated = true;
|
this.terminated = true;
|
||||||
trySchedule();
|
trySchedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onComplete() {
|
public final void onComplete() {
|
||||||
terminated = true;
|
this.terminated = true;
|
||||||
trySchedule();
|
trySchedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,24 +263,23 @@ class ReactiveTypeHandler {
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
this.executing.decrementAndGet();
|
this.executing.decrementAndGet();
|
||||||
queue.lazySet(null);
|
this.elementRef.lazySet(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (done) {
|
if (this.done) {
|
||||||
queue.lazySet(null);
|
this.elementRef.lazySet(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean d = terminated;
|
Object element = this.elementRef.get();
|
||||||
Object o = queue.get();
|
if (element != null) {
|
||||||
if (o != null) {
|
this.elementRef.lazySet(null);
|
||||||
queue.lazySet(null);
|
|
||||||
try {
|
try {
|
||||||
send(o);
|
send(element);
|
||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
catch (final Throwable ex) {
|
catch (final Throwable ex) {
|
||||||
|
|
@ -291,16 +291,17 @@ class ReactiveTypeHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d) {
|
if (this.terminated) {
|
||||||
this.done = true;
|
this.done = true;
|
||||||
Throwable ex = error;
|
Throwable ex = this.error;
|
||||||
error = null;
|
this.error = null;
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Publisher error for " + this.emitter, ex);
|
logger.debug("Publisher error for " + this.emitter, ex);
|
||||||
}
|
}
|
||||||
emitter.completeWithError(ex);
|
this.emitter.completeWithError(ex);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Publishing completed for " + this.emitter);
|
logger.debug("Publishing completed for " + this.emitter);
|
||||||
}
|
}
|
||||||
|
|
@ -309,7 +310,7 @@ class ReactiveTypeHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (executing.decrementAndGet() != 0) {
|
if (this.executing.decrementAndGet() != 0) {
|
||||||
schedule();
|
schedule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue