1 23 package org.objectweb.joram.mom.proxies; 24 25 public class FlowControl { 26 27 private static Object lock = new Object (); 28 private static int inFlow = 29 org.objectweb.joram.mom.proxies.ConnectionManager.inFlow; 30 private static long flowControl = 0; 31 private static long start = 0L; 32 private static long end = 0L; 33 private static int nbmsg = 0; 34 35 public static void flowControl() { 36 if (inFlow != -1) { 39 synchronized (lock) { 40 if (start == 0L) start = System.currentTimeMillis(); 41 nbmsg += 1; 42 if (nbmsg == inFlow) { 43 end = System.currentTimeMillis(); 44 flowControl = 1000L - (end - start); 45 if (flowControl > 0) { 46 try { 47 Thread.sleep(flowControl); 48 } catch (InterruptedException exc) {} 49 start = System.currentTimeMillis(); 50 } else { 51 start = end; 52 } 53 nbmsg = 0; 54 } 55 } 56 } 57 } 58 } 59 | Popular Tags |