// Path: siden-core/src/main/java/ninja/siden/internal/BlockingRenderer.java
// public class BlockingRenderer<T> implements Renderer<T> {
// 
// 	final Renderer<T> renderer;
// 
// 	public BlockingRenderer(Renderer<T> renderer) {
// 		super();
// 		this.renderer = renderer;
// 	}
// 
// 	@Override
// 	public void render(T model, HttpServerExchange sink) throws IOException {
// 		if (sink.isBlocking() == false) {
// 			sink.startBlocking();
// 		}
// 		if (sink.isInIoThread()) {
// 			sink.dispatch(exchange -> {
// 				renderer.render(model, exchange);
// 			});
// 		} else {
// 			renderer.render(model, sink);
// 		}
// 	}
// }
// 
// Path: siden-core/src/main/java/ninja/siden/internal/Core.java
// public class Core implements HttpHandler {
// 
// 	public static final AttachmentKey<OptionMap> CONFIG = AttachmentKey
// 			.create(OptionMap.class);
// 
// 	public static final AttachmentKey<Request> REQUEST = AttachmentKey
// 			.create(Request.class);
// 
// 	public static final AttachmentKey<Response> RESPONSE = AttachmentKey
// 			.create(Response.class);
// 
// 	final OptionMap config;
// 	final HttpHandler next;
// 
// 	public Core(OptionMap config, HttpHandler next) {
// 		super();
// 		this.config = config;
// 		this.next = next;
// 	}
// 
// 	@Override
// 	public void handleRequest(HttpServerExchange exchange) throws Exception {
// 		exchange.putAttachment(CONFIG, config);
// 		exchange.putAttachment(REQUEST, new SidenRequest(exchange));
// 		exchange.putAttachment(RESPONSE, new SidenResponse(exchange));
// 		exchange.addExchangeCompleteListener((ex, next) -> {
// 			try {
// 				exchange.removeAttachment(CONFIG);
// 				exchange.removeAttachment(REQUEST);
// 				exchange.removeAttachment(RESPONSE);
// 			} finally {
// 				next.proceed();
// 			}
// 		});
// 		next.handleRequest(exchange);
// 	}
// 
// 	public static io.undertow.predicate.Predicate adapt(Predicate<Request> fn) {
// 		return exchange -> {
// 			Request request = exchange.getAttachment(Core.REQUEST);
// 			return fn.test(request);
// 		};
// 	}
// }


import io.undertow.server.HttpServerExchange;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import ninja.siden.internal.BlockingRenderer;
import ninja.siden.internal.Core;
import org.xnio.OptionMap;
/*
 * Copyright 2014 SATO taichi
 *
 * 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 ninja.siden;





/**
 * @author taichi
 */
@FunctionalInterface
public interface Renderer<T> {

	void render(T model, HttpServerExchange sink) throws IOException;

	public static <MODEL> Renderer<MODEL> ofStream(
			OutputStreamConsumer<MODEL> fn) {
// Path: siden-core/src/main/java/ninja/siden/internal/BlockingRenderer.java
// public class BlockingRenderer<T> implements Renderer<T> {
// 
// 	final Renderer<T> renderer;
// 
// 	public BlockingRenderer(Renderer<T> renderer) {
// 		super();
// 		this.renderer = renderer;
// 	}
// 
// 	@Override
// 	public void render(T model, HttpServerExchange sink) throws IOException {
// 		if (sink.isBlocking() == false) {
// 			sink.startBlocking();
// 		}
// 		if (sink.isInIoThread()) {
// 			sink.dispatch(exchange -> {
// 				renderer.render(model, exchange);
// 			});
// 		} else {
// 			renderer.render(model, sink);
// 		}
// 	}
// }
// 
// Path: siden-core/src/main/java/ninja/siden/internal/Core.java
// public class Core implements HttpHandler {
// 
// 	public static final AttachmentKey<OptionMap> CONFIG = AttachmentKey
// 			.create(OptionMap.class);
// 
// 	public static final AttachmentKey<Request> REQUEST = AttachmentKey
// 			.create(Request.class);
// 
// 	public static final AttachmentKey<Response> RESPONSE = AttachmentKey
// 			.create(Response.class);
// 
// 	final OptionMap config;
// 	final HttpHandler next;
// 
// 	public Core(OptionMap config, HttpHandler next) {
// 		super();
// 		this.config = config;
// 		this.next = next;
// 	}
// 
// 	@Override
// 	public void handleRequest(HttpServerExchange exchange) throws Exception {
// 		exchange.putAttachment(CONFIG, config);
// 		exchange.putAttachment(REQUEST, new SidenRequest(exchange));
// 		exchange.putAttachment(RESPONSE, new SidenResponse(exchange));
// 		exchange.addExchangeCompleteListener((ex, next) -> {
// 			try {
// 				exchange.removeAttachment(CONFIG);
// 				exchange.removeAttachment(REQUEST);
// 				exchange.removeAttachment(RESPONSE);
// 			} finally {
// 				next.proceed();
// 			}
// 		});
// 		next.handleRequest(exchange);
// 	}
// 
// 	public static io.undertow.predicate.Predicate adapt(Predicate<Request> fn) {
// 		return exchange -> {
// 			Request request = exchange.getAttachment(Core.REQUEST);
// 			return fn.test(request);
// 		};
// 	}
// }


// Path: siden-core/src/main/java/ninja/siden/Renderer.java
import io.undertow.server.HttpServerExchange;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import ninja.siden.internal.BlockingRenderer;
import ninja.siden.internal.Core;
import org.xnio.OptionMap;

/*
 * Copyright 2014 SATO taichi
 *
 * 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 ninja.siden;





/**
 * @author taichi
 */
@FunctionalInterface
public interface Renderer<T> {

	void render(T model, HttpServerExchange sink) throws IOException;

	public static <MODEL> Renderer<MODEL> ofStream(
			OutputStreamConsumer<MODEL> fn) {
		return new BlockingRenderer<MODEL>((model, sink) -> fn.render(model,