Index: Configurator.java =================================================================== --- Configurator.java (.../tags/release-0.5/acs-ejb/src/java/org/openacs/Configurator.java) (revision 142313) +++ Configurator.java (.../trunk/acs-ejb/src/java/org/openacs/Configurator.java) (revision 142313) @@ -33,6 +33,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import javax.ejb.CreateException; @@ -85,6 +88,9 @@ //private static final String OUI_Thomson = "00147F"; //private static final String OUI_Thomson2 = "0090D0"; + private BlockingQueue requestQueue; + private BlockingQueue responseQueue; + public Configurator(Inform lastInform, Object hostid, ArrayList transferComplete, String fwpath, String urlServer, String sessionid) { this.lastInform = lastInform; this.hostid = hostid; @@ -96,6 +102,9 @@ this.paramConfigVersion = vcf + "Version"; this.paramConfigName = vcf + "Name"; this.sessionid = sessionid; + + requestQueue = new SynchronousQueue(); + responseQueue = new SynchronousQueue(); } private Message Call(Message request, long timeout) { @@ -977,34 +986,36 @@ sdl.setVoicecaps("".getBytes()); } } - private Message request; - private Message response; - public synchronized Message ReceiveRequest(long w) { - Message r = request; - //System.out.println ("Configurator::ReceiveRequest w="+w+" req="+request+" resp="+response); - if (w != 0) { - try { - wait(w); - //System.out.println ("Configurator::ReceiveRequest2 w="+w+" req="+request+" resp="+response); - } catch (InterruptedException ex) { - //System.out.println ("Configurator::ReceiveRequest3 w="+w+" req="+request+" resp="+response); - } - r = request; - } - request = null; - response = null; - return r; - } + public Message ReceiveRequest(long w) { + log(Level.FINE, "Configurator::ReceiveRequest w=> " + w); + Message r = null; + try { + long beforeTime = System.currentTimeMillis(); + r = requestQueue.poll(w, TimeUnit.MILLISECONDS); + log(Level.FINE, "Configurator::ReceiveRequest after " + + (System.currentTimeMillis() - beforeTime) + " ms req=> " + + r); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + return r; + } - public synchronized void SendResponse(Message response) { - this.response = response; - //System.out.println ("Configurator::SendResponse req="+request+" resp="+response); - notify(); - //System.out.println ("Configurator::SendResponse2 req="+request+" resp="+response); - } + public void SendResponse(Message response) { + log(Level.FINE, "Configurator:SendResponse response=> " + + response); + try { + if (!responseQueue.offer(response, 5, TimeUnit.SECONDS)) { + log(Level.WARNING, + "Configurator::SendResponse responseQueue offer unable to occur"); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } - public synchronized Message Call(HostsLocal host, Message call, long timeout) { + public Message Call(HostsLocal host, Message call, long timeout) { Message mr = null; if (timeout > MAX_CALL_TIMEOUT) { @@ -1012,30 +1023,27 @@ } else if (timeout < MIN_CALL_TIMEOUT) { timeout = MIN_CALL_TIMEOUT; } + log(Level.FINE, "Configurator::Call timeout=> " + timeout + " msg=> " + call + " callType => " + callType); switch (callType) { case 1: mr = Ejb.lookupCPEBean().Call(host, call, timeout); break; case 2: - request = call; - //System.out.println ("Configurator::Call req="+request+" resp="+response); - notify(); - //System.out.println ("Configurator::Call2 req="+request+" resp="+response); - - try { -// System.out.println ("Configurator::Call WAIT timeout="+timeout); - wait(timeout * 1000); - } catch (InterruptedException ex) { - //System.out.println ("Configurator::Call4 req="+request+" resp="+response); - } - //System.out.println ("Configurator::Call3 req="+request+" resp="+response); - mr = response; - break; + try { + if( ! requestQueue.offer(call, 5, TimeUnit.SECONDS )){ + log( Level.WARNING, "Configurator::Call requestQueue offer unable to occur"); + } + mr = responseQueue.poll(timeout , TimeUnit.SECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + break; } if (mr instanceof Fault) { Fault f = (Fault) mr; System.out.println("Fault: " + f.getFaultString() + " cwmp: " + f.getFaultStringCwmp()); } + log( Level.FINE, "Configurator::Call response=> " + mr ); return mr; } private int callType = 1;