JVM 上各种 Web 框架的抽象层 Asity

码农软件 · 软件分类 · Web框架 · 2019-03-24 14:59:32

软件介绍

Asity

Asity 是 Java 虚拟机上各种 Web 框架的抽象层,可以在 JVM 上构建 Web 框架不可知的应用程序。

Asity 是 Web 框架的一个轻量级抽象层,它被设计用来构建应用程序和框架,这些应用程序和框架可以在 JVM 上的任何全栈框架,任何微型框架或任何原始服务器上运行,而不会降低底层框架的性能。它提供了 HTTP 和 WebSocket 抽象。

HTTP

io.cettia.asity:asity-http 提供 HTTP 抽象,下边是 echo HTTP 服务器示例:

Action<ServerHttpExchange> httpAction = (ServerHttpExchange http) -> {
  // Request properties
  System.out.println(http.method() + " " + http.uri());
  http.headerNames().stream().forEach(name -> System.out.println(name + ": " + http.header(name)));
  
  // Sets 200 OK response status
  http.setStatus(HttpStatus.OK);
  
  // Copies the content-type header of the request to the response
  http.setHeader("content-type", http.header("content-type"));
  
  // When a chunk is read from the request body, writes it to the response body
  http.onchunk((ByteBuffer bytes) -> http.write(bytes));
  
  // When the request is fully read, ends the response
  http.onend((Void v) -> http.end());
  
  // Reads the request body as binary to circumvent encoding issue
  http.readAsBinary();
  
  // When the response is fully written and ends,
  http.onfinish((Void v) -> System.out.println("on finish"));
  
  // When some error happens in the request-response exchange,
  http.onerror((Throwable t) -> t.printStackTrace());
  
  // When the underlying connection is terminated,
  http.onclose((Void v) -> System.out.println("on close"));
};

WebSocket

io.cettia.asity:asity-websocket 提供 WebSocket 抽象,下边是 echo WebSocket 服务器示例:

Action<ServerWebSocket> wsAction = (ServerWebSocket ws) -> {
  // Handshake request properties
  System.out.println(HttpMethod.GET + " " + ws.uri());
  ws.headerNames().stream().forEach(name -> System.out.println(name + ": " + ws.header(name)));
  
  // When a text frame is arrived, sends it back
  ws.ontext((String data) -> ws.send(data));
  
  // When a binary frame is arrived, sends it back
  ws.onbinary((ByteBuffer bytes) -> ws.send(bytes));
  
  // When some error happens in the connection,
  ws.onerror((Throwable t) -> t.printStackTrace());
  
  // When the connection is closed for any reason,
  ws.onclose((Void v) -> System.out.println("on close"));
};

Bridge

io.cettia.asity:asity-bridge-xxx 是一个处理和转换框架特定资源到 Asity的 ServerHttpExchange 和 ServerWebSocket 的模块。下面这些 Bridge 都是可用的,也就是说基于 Asity 的应用程序或框架可以在以下框架中无缝地运行:

  • Atmosphere 2

  • Grizzly 2

  • Java Servlet 3

  • Java WebSocket API 1

  • Netty 4

  • Spring WebFlux 5

  • Vert.x 2 and 3

本文地址:https://codercto.com/soft/d/2055.html

C程序设计语言

C程序设计语言

Brian W. Kernighan、Dennis M. Ritchie / 机械工业出版社 / 2006-8-1 / 35.00元

在计算机发展的历史上,没有哪一种程序设计语言像C语言这样应用广泛。本书是C语言的设计者之一Dennis M.Ritchie和著名计算机科学家Brian W.Kernighan合著的一本介绍C语言的权威经典著作。我们现在见到的大量论述C语言程序设计的教材和专著均以此书为蓝本。本书第1版中介绍的C语言成为后来广泛使用的C语言版本——标准C的基础。人们熟知的“hello,World"程序就是由本书首次引......一起来看看 《C程序设计语言》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码