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 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 volatile boolean done;
|
||||
|
||||
private volatile boolean terminated;
|
||||
|
||||
private Throwable error;
|
||||
|
||||
|
||||
protected AbstractEmitterSubscriber(ResponseBodyEmitter emitter, TaskExecutor executor) {
|
||||
this.emitter = emitter;
|
||||
|
|
@ -229,20 +230,20 @@ class ReactiveTypeHandler {
|
|||
|
||||
@Override
|
||||
public final void onNext(Object element) {
|
||||
this.queue.lazySet(element);
|
||||
this.elementRef.lazySet(element);
|
||||
trySchedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onError(Throwable ex) {
|
||||
error = ex;
|
||||
terminated = true;
|
||||
this.error = ex;
|
||||
this.terminated = true;
|
||||
trySchedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onComplete() {
|
||||
terminated = true;
|
||||
this.terminated = true;
|
||||
trySchedule();
|
||||
}
|
||||
|
||||
|
|
@ -262,24 +263,23 @@ class ReactiveTypeHandler {
|
|||
}
|
||||
finally {
|
||||
this.executing.decrementAndGet();
|
||||
queue.lazySet(null);
|
||||
this.elementRef.lazySet(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (done) {
|
||||
queue.lazySet(null);
|
||||
if (this.done) {
|
||||
this.elementRef.lazySet(null);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean d = terminated;
|
||||
Object o = queue.get();
|
||||
if (o != null) {
|
||||
queue.lazySet(null);
|
||||
Object element = this.elementRef.get();
|
||||
if (element != null) {
|
||||
this.elementRef.lazySet(null);
|
||||
try {
|
||||
send(o);
|
||||
send(element);
|
||||
this.subscription.request(1);
|
||||
}
|
||||
catch (final Throwable ex) {
|
||||
|
|
@ -291,16 +291,17 @@ class ReactiveTypeHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if (d) {
|
||||
if (this.terminated) {
|
||||
this.done = true;
|
||||
Throwable ex = error;
|
||||
error = null;
|
||||
Throwable ex = this.error;
|
||||
this.error = null;
|
||||
if (ex != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Publisher error for " + this.emitter, ex);
|
||||
}
|
||||
emitter.completeWithError(ex);
|
||||
} else {
|
||||
this.emitter.completeWithError(ex);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Publishing completed for " + this.emitter);
|
||||
}
|
||||
|
|
@ -309,7 +310,7 @@ class ReactiveTypeHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
if (executing.decrementAndGet() != 0) {
|
||||
if (this.executing.decrementAndGet() != 0) {
|
||||
schedule();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue