简体   繁体   English

约束JAX-WS CXF Web服务请求方法调用每个客户端IP一个请求

[英]Constraint JAX-WS CXF web service request method invocation to one request per client IP

I have a CXF-based web service with a one-way method say: Service.report() 我有一个基于CXF的Web服务,使用单向方法说:Service.report()

While a report() from a client is being processed, I want to make another incoming report() from the same client IP wait till the first request is processed. 当正在处理来自客户端的report()时,我想从同一客户端IP生成另一个传入报告(),等待第一个请求被处理。 Seen from a client, report() is an atomic operation and successive calls to report() should be processed sequentially. 从客户端看,report()是一个原子操作,应该按顺序处理对report()的连续调用。

How can I best implement this locking mechanism? 我怎样才能最好地实现这种锁定机制? Will I need to implement a per-client queue or is there a simple way to accomplish this? 我是否需要实现每个客户端队列,还是有一种简单的方法来实现这一目标?

You don't need a full blown queue for this. 你不需要一个完整的队列。 A simple object synchronisation should work 一个简单的对象同步应该工作

static ConcurrentMap syncMap = new ConcurrentHashMap();

public void report()
{
   String clientIp =  ...
   syncMap.putIfAbsent(clientIp, new Object()); // just new Object is good enough to sync on
   synchronized(syncMap.get(clientIp))
   {
      //do synchronized stuff.
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM