我有两个需要连接的进程,如下所示:
proc1 - 将输出发送到proc2 proc2 - 将输出发送到proc1
到目前为止,所有管道示例都属于这种类型:proc1 | PROC2
这很好,但是如何让proc2的输出转到proc1?
一个bash例子会很好.一个Windows shell示例会很棒:)
先谢谢,阿德里安.
添加更多细节:
该系统有望用作客户端 - 服务器系统,其中客户端在请求 - 响应交互模型中与服务器一起工作.当客户端没有更多请求时,交互结束.
交互示例:client:request1; server:response1; 客户:request2; server:response2; ....客户端:closeRequest; server:closeApproved;
此时,服务器在客户端退出后退出.示例结束.
似乎有一个解决方案(假设管道可用)客户端<pipe | 服务器>管道不起作用(请纠正我),因为在这种安排中客户端产生一个大的请求,shell将这个大的请求传递给服务器,然后服务器产生一个大的响应,最后shell将这个大响应传递给客户.
我们需要在Servlet应用程序中实现一个优雅的关闭机制.
编辑:我们希望尽可能简化,这将处理通过操作系统的功能发送的终止信号.这将允许系统管理员使用内置的shell实用程序(在Windows上执行kill或taskkill),否则他们必须安装另一个实用程序才能与服务器"对话".
该机制分两个阶段:
阶段#1在我们的DAO层中实现.阶段#2在我们的ServletContextListener#contextDestroyed方法中实现
我们的问题是,一旦调用了contextDestroyed,Servlet容器就会停止为进一步的HTTP请求提供服务.
编辑:当有人在服务器进程上调用操作系统的kill函数时,将调用contextDestroyed.
我们希望在阶段#2期间让应用程序处于活动状态,通知用户某些活动不可用.
请考虑以下代码:
function foo(handlers) {
callSomeFunction(handlers.onSuccess, handlers.onFailure);
}
Run Code Online (Sandbox Code Playgroud)
来电者可以这样做:
foo({onSuccess: doSomething, onFailure: doSomethingElse });
Run Code Online (Sandbox Code Playgroud)
或者只是
foo()
Run Code Online (Sandbox Code Playgroud)
如果他/她没有什么特别的事可做.
上面代码的问题是如果'handlers'是未定义的,就像上面的简单foo()调用一样,那么在执行callSomeFunction(handlers.onSuccess,handlers.onFailure)时会抛出运行时异常.
为了处理这种情况,可以将foo函数重写为:
function foo(handlers) {
var _handlers = handlers || {};
callSomeFunction(_handlers.onSuccess, _handlers.onFailure);
}
Run Code Online (Sandbox Code Playgroud)
或更有条理的
function safe(o) {
return o === Object(o) ? o : {};
}
function foo(handlers) {
callSomeFunction(safe(handlers).onSuccess, safe(handlers).onFailure);
}
Run Code Online (Sandbox Code Playgroud)
我试图在诸如sugarjs和underscore之类的库中找到类似safe()函数的东西,但一无所获.我错过了什么?是否有其他具有类似功能的实用程序库?
试着不要重新发明轮子......;)
BR,阿德里安.
PS我没有测试上面的代码,所以它可能有错误.
有一个库提供了类,例如org.springframework.security.oauth2.provider.client.BaseClientDetails
我希望将其包装为 Lombok (或类似)构建器。
目前,我派生了一个像这样的包装类:
public static final class BaseClientDetailsWrapper
extends BaseClientDetails {
@Builder
private BaseClientDetailsWrapper(
final String clientId,
final List<String> resourceIds,
final List<GrantedAuthority> suthorities,
final List<String> scopes,
final List<String> autoApproveScopes,
final List<String> authorizedGrantTypes,
final String clientSecret) {
super();
setClientId(clientId);
setResourceIds(resourceIds);
setAuthorities(authorities);
setScope(scopes);
setAuthorizedGrantTypes(authorizedGrantTypes);
setAutoApproveScopes(autoApproveScopes);
setClientSecret(clientSecret);
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法摆脱烦人的 setXxx(...) 代码?