livy源码阅读基础知识

1、解析json数据:
interactiveSession使用的jackson来解析传入的request
在org.apache.livy.server.JsonServlet中

提供了三种不同的方法来处理JSON
* 流式API - 读取并将JSON内容写入作为离散事件。 JsonParser读取数据,而JsonGenerator写入数据。它是三者中最有效的方法,是最低的开销和最快的读/写操作。它类似于Stax解析器XML。
* 树模型 - 准备JSON文件在内存里以树形式表示。 ObjectMapper构建JsonNode节点树。这是最灵活的方法。它类似于XML的DOM解析器。
* 数据绑定 - 转换JSON并从POJO(普通Java对象)使用属性访问或使用注释。它有两个类型。
* 简单的数据绑定 - 转换JSON和Java Maps, Lists, Strings, Numbers, Booleans 和null 对象。
* 全部数据绑定 - 转换为JSON从任何JAVA类型。

ObjectMapper读/写JSON两种类型的数据绑定。数据绑定是最方便的方式是类似XML的JAXB解析器。

2、scala中的++操作符串联映射
可以使用++运算符或映射。++()方法来连接两个或更多的映射,但同时增加了映射,将删除重复的键。下面是一个例子来连接两个映射:

object Test {
def main(args: Array[String]) {
val colors1 = Map("red" -> "#FF000F",
"azure" -> "#F0FFFF",
"peru" -> "#CD853F")
val colors2 = Map("blue" -> "#0033FF",
"yellow" -> "#FFFF00",
"red" -> "#FF0000")

// use two or more Maps with ++ as operator
var colors = colors1 ++ colors2
println( "colors1 ++ colors2 : " + colors )

// use two maps with ++ as method
colors = colors1.++(colors2)
println( "colors1.++(colors2)) : " + colors )

}}

当上述代码被编译和执行时,它产生了以下结果:
这里写图片描述
3、concurrentMap
这里写图片描述
这里写图片描述
4、学习netty
http://ifeve.com/netty5-user-guide/
5、await

Await.result(session.start(), Duration.Inf)

使用样例

val responseFuture = WS.url("http://search.twitter.com/search.json").withQueryString("q" -> query, "rpp" -> results.toString).get
val response = Await.result(responseFuture, 10 seconds)

猜你喜欢

转载自blog.csdn.net/qq_32635069/article/details/80056006