antelder 2002/06/10 02:01:53 Modified: java/src/org/apache/wsif/util WSIFDefaultCorrelationService.java Log: WSIFDefaultCorrelationService only starts timeout thread when reqd Revision Changes Path 1.2 +30 -115 xml-axis-wsif/java/src/org/apache/wsif/util/WSIFDefaultCorrelationService.java Index: WSIFDefaultCorrelationService.java =================================================================== RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/WSIFDefaultCorrelationService.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WSIFDefaultCorrelationService.java 6 Jun 2002 08:28:52 -0000 1.1 +++ WSIFDefaultCorrelationService.java 10 Jun 2002 09:01:53 -0000 1.2 @@ -117,13 +117,13 @@ } try { correlatorStore.put(correlator, serialize(state)); - Long t; - if (timeout == 0) { - t = new Long(Long.MAX_VALUE); - } else { - t = new Long(System.currentTimeMillis() + timeout); + if ( timeout > 0 ) { + if ( timeouts == null ) { + initTimeouts(); + } + timeouts.put( correlator, + new Long( System.currentTimeMillis()+timeout ) ); } - timeouts.put(correlator, t); } catch (IOException ex) { throw new WSIFException(ex.toString()); } @@ -170,7 +170,9 @@ throw new IllegalArgumentException("cannot remove null"); } else { correlatorStore.remove(id); - timeouts.remove(id); + if ( timeouts != null ) { + timeouts.remove(id); + } Tr.exit(); } } @@ -205,27 +207,27 @@ } private void initialise() { - shutdown = false; - correlatorStore = new HashMap(); - timeouts = new HashMap(); - timeoutWatcher = new Thread() { - public void run() { - while (!shutdown) { - try { - sleep(WSIFConstants.CORRELATION_TIMEOUT_DELAY); - } catch (InterruptedException ex) { - } - checkForTimeouts(); - } - if (correlatorStore != null) - correlatorStore = null; - if (timeouts != null) - timeouts = null; - } - }; - timeoutWatcher.setName("WSIFDefaultCorrelationService timeout watcher"); - timeoutWatcher.start(); - } + shutdown = false; + correlatorStore = new HashMap(); + } + + private void initTimeouts() { + timeouts = new HashMap(); + timeoutWatcher = new Thread() { + public void run() { + while ( !shutdown ) { + try { + sleep(WSIFConstants.CORRELATION_TIMEOUT_DELAY); + } catch (InterruptedException ex) {} + checkForTimeouts(); + } + if ( correlatorStore != null ) correlatorStore = null; + if ( timeouts != null ) timeouts = null; + } + }; + timeoutWatcher.setName( "WSIFDefaultCorrelationService timeout watcher" ); + timeoutWatcher.start(); + } private void checkForTimeouts() { Long expireTime; @@ -273,91 +275,4 @@ } } - public static void main(String[] args) { - Tr.entry(null, args); - System.out.println("Testing WSIFDefaultCorrelationService"); - - System.out.println("getting a CorrelationService"); - WSIFCorrelationService cs = - WSIFCorrelationServiceLocator.getCorrelationService(); - - try { - - WSIFCorrelationId cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("1"); - System.out.println("\nadding key " + cid + " data 'petra'"); - cs.put(cid, (Serializable) "petra", (long) 0); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("2"); - System.out.println("adding key " + cid + " data 'ant'"); - cs.put(cid, "ant", (long) 0); - - System.out.println("\ngetting another CorrelationService"); - WSIFCorrelationService cs2 = - WSIFCorrelationServiceLocator.getCorrelationService(); - - System.out.println("\ncs1 should equal cs2 " + (cs == cs2)); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("3"); - System.out.println( - "adding key " + cid + " data 'tanya' with timeout 5000 to the other cs"); - cs2.put(cid, "tanya", 5000); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("1"); - String s = (String) cs.get(cid); - System.out.println("\nget key " + cid + " got '" + s + "' should be 'petra'"); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("2"); - s = (String) cs.get(cid); - System.out.println("get key " + cid + " got '" + s + "' should be 'ant'"); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("3"); - s = (String) cs.get(cid); - System.out.println("get key " + cid + " got '" + s + "' should be 'tanya'"); - - System.out.println("\nsleeping 10 secs"); - try { - Thread.sleep(30000); - } catch (Exception ex) { - System.out.println("interupted early"); - } - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("1"); - s = (String) cs.get(cid); - System.out.println("\nget key '1' got '" + s + "' should be 'petra'"); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("2"); - s = (String) cs.get(cid); - System.out.println("get key '2' got '" + s + "' should be 'ant'"); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("3"); - s = (String) cs.get(cid); - System.out.println( - "get key '3' got '" + s + "' should be 'null' due to timeout"); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("2"); - System.out.println("\nremoving key '2'"); - cs.remove(cid); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("1"); - s = (String) cs.get(cid); - System.out.println("\nget key '1' got '" + s + "' should be 'petra'"); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("2"); - s = (String) cs.get(cid); - System.out.println( - "get key '2' got '" + s + "' should be 'null' due to remove"); - - cid = new org.apache.wsif.util.jms.WSIFJMSCorrelationId("3"); - s = (String) cs.get(cid); - System.out.println( - "get key '3' got '" + s + "' should be 'null' due to timeout"); - - } catch (WSIFException ex) { - ex.printStackTrace(); - } - - System.out.println("\nTests complete"); - ((WSIFDefaultCorrelationService) cs).shutdown(); - Tr.exit(); - } }