我正在尝试创建一个可以使用 SSE (服务器发送事件)从服务器接收事件的客户端,并且我使用 OkHttp3 结合 OkHttp3-sse 库(com.squareup.okhttp3:okhttp:4.1 .0 和 com.squareup.okhttp3:okhttp-sse:4.1.0)。我能够很好地连接到服务器并接收事件,但在某个时间点,我想断开客户端连接并关闭我的应用程序。这就是问题所在。连接关闭,但应用程序未关闭,可能是由于ConnectionPool未关闭。
由于几乎没有任何有关使用 OkHttp3-sse 库的文档,因此我尝试从代码中进行逆向工程。我尝试过:
RealEventSource.cancel()在线程上的调用OkHttpClient.dispatcher().cancelAll()也正在断开连接,但仍挂在线程上Response.close()传递给的调用EventSourceListener.onOpen()作为替代方案,我查看了https://github.com/heremaps/oksse,其中包含RealServerSentEvent.close()正在执行我期望的操作的调用。它关闭连接并停止所有线程,从而允许应用程序完全关闭。我查看了该类的实现,RealServerSentEvent以了解该实现与RealEventSource. 我认为区别在于读取循环的条件:
RealEventSource行https://github.com/square/okhttp/blob/master/okhttp-sse/src/main/java/okhttp3/internal/sse/RealEventSource.kt#L75:
try {
listener.onOpen(this, response)
while (reader.processNextEvent()) {
}
} catch (e: Exception) {
listener.onFailure(this, e, response)
return
}
Run Code Online (Sandbox Code Playgroud)
RealServerSentEvent与行https://github.com/heremaps/oksse/blob/master/src/main/java/com/here/oksse/RealServerSentEvent.java#L94相比
:
listener.onOpen(this, response);
//noinspection StatementWithEmptyBody
while (call != null && !call.isCanceled() && sseReader.read()) {
}
Run Code Online (Sandbox Code Playgroud)
该OkSSE …
我使用多配置项目选项在Jenkins中配置了一个作业.我能够成功构建用户定义的轴目标,但发现Jenkins首先在工作区文件夹(实际上没有使用)中开始签出,并在工作区/目标文件夹中检出该目标,在该文件夹中为该目标构建实际上是执行的.
因此,当触发构建时,Jenkins首先将给定的URL检出到workspace /然后检查到workspace/target /等.
实际步骤:
1. checkout to workspace
2. checkout to workspace/target/<target1>
3. checkout to workspace/target/<target2>
Run Code Online (Sandbox Code Playgroud)
预期的步骤:
1. checkout to workspace/target/<target1>
2. checkout to workspace/target/<target2>
Run Code Online (Sandbox Code Playgroud)
我怎样才能阻止Jenkins进行第一次结账并只做相关的结账?
或者甚至更好,我的构建允许在一次结账时完成所有操作.我能这样做吗?