tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r723775 [4/5] - in /tomcat/trunk: java/org/apache/juli/ modules/bayeux/ modules/bayeux/java/org/apache/cometd/bayeux/ modules/bayeux/java/org/apache/tomcat/bayeux/ modules/bayeux/java/org/apache/tomcat/bayeux/request/ modules/bayeux/test/or...
Date Fri, 05 Dec 2008 15:57:46 GMT
Modified: tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/BayeuxStockTicker.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/BayeuxStockTicker.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/BayeuxStockTicker.java (original)
+++ tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/BayeuxStockTicker.java Fri Dec  5 07:57:43 2008
@@ -1,215 +1,215 @@
-package org.apache.cometd.bayeux.samples;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletContextAttributeListener;
-import javax.servlet.ServletContextAttributeEvent;
-import org.apache.cometd.bayeux.Bayeux;
-
-import java.text.DecimalFormat;
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.cometd.bayeux.Client;
-import org.apache.cometd.bayeux.Listener;
-import org.apache.cometd.bayeux.Message;
-import org.apache.cometd.bayeux.Channel;
-
-public class BayeuxStockTicker implements ServletContextListener,
-        ServletContextAttributeListener, Listener {
-
-    static AtomicInteger counter = new AtomicInteger(0);
-    protected int id;
-    protected Bayeux b;
-    protected Client c;
-    protected boolean alive = true;
-    protected boolean initialized = false;
-    protected TickerThread tt = new TickerThread();
-
-    public BayeuxStockTicker() {
-        id = counter.incrementAndGet();
-        System.out.println("new listener created with id:" + id);
-    }
-
-    public void contextDestroyed(ServletContextEvent servletContextEvent) {
-        alive = false;
-        tt.run = false;
-        tt.interrupt();
-    }
-
-    public void contextInitialized(ServletContextEvent servletContextEvent) {
-    }
-
-    public void attributeAdded(ServletContextAttributeEvent scae) {
-        if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
-            if (initialized) return;
-            initialized = true;
-            System.out.println("Starting stock ticker server client!");
-            b = (Bayeux) scae.getValue();
-            c = b.newClient("stock-ticker-", this);
-            tt.start();
-        }
-    }
-
-    public void attributeRemoved(ServletContextAttributeEvent scae) {
-        if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
-            initialized = false;
-            b = (Bayeux) scae.getValue();
-            List<Channel> chs = b.getChannels();
-            for (Channel ch : chs) {
-                ch.unsubscribe(c);
-            }
-        }
-    }
-
-    public void attributeReplaced(
-            ServletContextAttributeEvent servletContextAttributeEvent) {
-    }
-
-    public void removed(boolean timeout) {
-        System.out.println("Client removed.");
-    }
-
-    public void deliver(Message[] msgs) {
-        for (int i = 0; msgs != null && i < msgs.length; i++) {
-            Message msg = msgs[i];
-            System.out.println("[stock ticker server client ]received message:" + msg);
-        }
-    }
-
-    public class TickerThread extends Thread {
-        public boolean run = true;
-
-        public TickerThread() {
-            setName("Ticker Thread");
-        }
-
-        public void run() {
-            try {
-                
-                Stock[] stocks = new Stock[] { 
-                        new Stock("GOOG", 435.43),
-                        new Stock("YHOO", 27.88), 
-                        new Stock("SPRG", 1015.55), };
-                for (Stock s : stocks) {
-                    Channel ch = b.getChannel("/stock/"+s.getSymbol(), true);
-                    ch.subscribe(c);
-                    
-                }
-                Random r = new Random(System.currentTimeMillis());
-                while (run) {
-                    for (int j = 0; j < 1; j++) {
-                        int i = r.nextInt() % 3;
-                        if (i < 0)
-                            i = i * (-1);
-                        Stock stock = stocks[i];
-                        double change = r.nextDouble();
-                        boolean plus = r.nextBoolean();
-                        if (plus) {
-                            stock.setValue(stock.getValue() + change);
-                        } else {
-                            stock.setValue(stock.getValue() - change);
-                        }
-                        Channel ch = b.getChannel("/stock/"+stock.getSymbol(), true);
-                        Message m = b.newMessage(c);
-                        m.put("stock", stock.toString());
-                        m.put("symbol", stock.getSymbol());
-                        m.put("price", stock.getValueAsString());
-                        m.put("change", stock.getLastChangeAsString());
-                        ch.publish(m);
-                        System.out.println("Stock: "+stock.getSymbol()+" Price: "+stock.getValueAsString()+" Change: "+stock.getLastChangeAsString());
-                    }
-                    Thread.sleep(850);
-                }
-            } catch (InterruptedException ix) {
-
-            } catch (Exception x) {
-                x.printStackTrace();
-            }
-        }
-    }
-
-    public static class Stock {
-        protected static DecimalFormat df = new DecimalFormat("0.00");
-        protected String symbol = "";
-        protected double value = 0.0d;
-        protected double lastchange = 0.0d;
-        protected int cnt = 0;
-
-        public Stock(String symbol, double initvalue) {
-            this.symbol = symbol;
-            this.value = initvalue;
-        }
-
-        public void setCnt(int c) {
-            this.cnt = c;
-        }
-
-        public int getCnt() {
-            return cnt;
-        }
-
-        public String getSymbol() {
-            return symbol;
-        }
-
-        public double getValue() {
-            return value;
-        }
-
-        public void setValue(double value) {
-            double old = this.value;
-            this.value = value;
-            this.lastchange = value - old;
-        }
-
-        public String getValueAsString() {
-            return df.format(value);
-        }
-
-        public double getLastChange() {
-            return this.lastchange;
-        }
-
-        public void setLastChange(double lastchange) {
-            this.lastchange = lastchange;
-        }
-
-        public String getLastChangeAsString() {
-            return df.format(lastchange);
-        }
-
-        public int hashCode() {
-            return symbol.hashCode();
-        }
-
-        public boolean equals(Object other) {
-            if (other instanceof Stock) {
-                return this.symbol.equals(((Stock) other).symbol);
-            } else {
-                return false;
-            }
-        }
-        
-        public String toString(){
-            StringBuffer buf = new StringBuffer("STOCK#");
-            buf.append(getSymbol());
-            buf.append("#");
-            buf.append(getValueAsString());
-            buf.append("#");
-            buf.append(getLastChangeAsString());
-            buf.append("#");
-            buf.append(String.valueOf(getCnt()));
-            return buf.toString();
-         
-        }
-
-        public Object clone() {
-            Stock s = new Stock(this.getSymbol(), this.getValue());
-            s.setLastChange(this.getLastChange());
-            s.setCnt(this.cnt);
-            return s;
-        }
-    }
-
+package org.apache.cometd.bayeux.samples;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextAttributeEvent;
+import org.apache.cometd.bayeux.Bayeux;
+
+import java.text.DecimalFormat;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.cometd.bayeux.Client;
+import org.apache.cometd.bayeux.Listener;
+import org.apache.cometd.bayeux.Message;
+import org.apache.cometd.bayeux.Channel;
+
+public class BayeuxStockTicker implements ServletContextListener,
+        ServletContextAttributeListener, Listener {
+
+    static AtomicInteger counter = new AtomicInteger(0);
+    protected int id;
+    protected Bayeux b;
+    protected Client c;
+    protected boolean alive = true;
+    protected boolean initialized = false;
+    protected TickerThread tt = new TickerThread();
+
+    public BayeuxStockTicker() {
+        id = counter.incrementAndGet();
+        System.out.println("new listener created with id:" + id);
+    }
+
+    public void contextDestroyed(ServletContextEvent servletContextEvent) {
+        alive = false;
+        tt.run = false;
+        tt.interrupt();
+    }
+
+    public void contextInitialized(ServletContextEvent servletContextEvent) {
+    }
+
+    public void attributeAdded(ServletContextAttributeEvent scae) {
+        if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
+            if (initialized) return;
+            initialized = true;
+            System.out.println("Starting stock ticker server client!");
+            b = (Bayeux) scae.getValue();
+            c = b.newClient("stock-ticker-", this);
+            tt.start();
+        }
+    }
+
+    public void attributeRemoved(ServletContextAttributeEvent scae) {
+        if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
+            initialized = false;
+            b = (Bayeux) scae.getValue();
+            List<Channel> chs = b.getChannels();
+            for (Channel ch : chs) {
+                ch.unsubscribe(c);
+            }
+        }
+    }
+
+    public void attributeReplaced(
+            ServletContextAttributeEvent servletContextAttributeEvent) {
+    }
+
+    public void removed(boolean timeout) {
+        System.out.println("Client removed.");
+    }
+
+    public void deliver(Message[] msgs) {
+        for (int i = 0; msgs != null && i < msgs.length; i++) {
+            Message msg = msgs[i];
+            System.out.println("[stock ticker server client ]received message:" + msg);
+        }
+    }
+
+    public class TickerThread extends Thread {
+        public boolean run = true;
+
+        public TickerThread() {
+            setName("Ticker Thread");
+        }
+
+        public void run() {
+            try {
+                
+                Stock[] stocks = new Stock[] { 
+                        new Stock("GOOG", 435.43),
+                        new Stock("YHOO", 27.88), 
+                        new Stock("SPRG", 1015.55), };
+                for (Stock s : stocks) {
+                    Channel ch = b.getChannel("/stock/"+s.getSymbol(), true);
+                    ch.subscribe(c);
+                    
+                }
+                Random r = new Random(System.currentTimeMillis());
+                while (run) {
+                    for (int j = 0; j < 1; j++) {
+                        int i = r.nextInt() % 3;
+                        if (i < 0)
+                            i = i * (-1);
+                        Stock stock = stocks[i];
+                        double change = r.nextDouble();
+                        boolean plus = r.nextBoolean();
+                        if (plus) {
+                            stock.setValue(stock.getValue() + change);
+                        } else {
+                            stock.setValue(stock.getValue() - change);
+                        }
+                        Channel ch = b.getChannel("/stock/"+stock.getSymbol(), true);
+                        Message m = b.newMessage(c);
+                        m.put("stock", stock.toString());
+                        m.put("symbol", stock.getSymbol());
+                        m.put("price", stock.getValueAsString());
+                        m.put("change", stock.getLastChangeAsString());
+                        ch.publish(m);
+                        System.out.println("Stock: "+stock.getSymbol()+" Price: "+stock.getValueAsString()+" Change: "+stock.getLastChangeAsString());
+                    }
+                    Thread.sleep(850);
+                }
+            } catch (InterruptedException ix) {
+
+            } catch (Exception x) {
+                x.printStackTrace();
+            }
+        }
+    }
+
+    public static class Stock {
+        protected static DecimalFormat df = new DecimalFormat("0.00");
+        protected String symbol = "";
+        protected double value = 0.0d;
+        protected double lastchange = 0.0d;
+        protected int cnt = 0;
+
+        public Stock(String symbol, double initvalue) {
+            this.symbol = symbol;
+            this.value = initvalue;
+        }
+
+        public void setCnt(int c) {
+            this.cnt = c;
+        }
+
+        public int getCnt() {
+            return cnt;
+        }
+
+        public String getSymbol() {
+            return symbol;
+        }
+
+        public double getValue() {
+            return value;
+        }
+
+        public void setValue(double value) {
+            double old = this.value;
+            this.value = value;
+            this.lastchange = value - old;
+        }
+
+        public String getValueAsString() {
+            return df.format(value);
+        }
+
+        public double getLastChange() {
+            return this.lastchange;
+        }
+
+        public void setLastChange(double lastchange) {
+            this.lastchange = lastchange;
+        }
+
+        public String getLastChangeAsString() {
+            return df.format(lastchange);
+        }
+
+        public int hashCode() {
+            return symbol.hashCode();
+        }
+
+        public boolean equals(Object other) {
+            if (other instanceof Stock) {
+                return this.symbol.equals(((Stock) other).symbol);
+            } else {
+                return false;
+            }
+        }
+        
+        public String toString(){
+            StringBuffer buf = new StringBuffer("STOCK#");
+            buf.append(getSymbol());
+            buf.append("#");
+            buf.append(getValueAsString());
+            buf.append("#");
+            buf.append(getLastChangeAsString());
+            buf.append("#");
+            buf.append(String.valueOf(getCnt()));
+            return buf.toString();
+         
+        }
+
+        public Object clone() {
+            Stock s = new Stock(this.getSymbol(), this.getValue());
+            s.setLastChange(this.getLastChange());
+            s.setCnt(this.cnt);
+            return s;
+        }
+    }
+
 }
\ No newline at end of file

Propchange: tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/BayeuxStockTicker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/EchoChatClient.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/EchoChatClient.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/EchoChatClient.java (original)
+++ tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/EchoChatClient.java Fri Dec  5 07:57:43 2008
@@ -1,101 +1,101 @@
-package org.apache.cometd.bayeux.samples;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletContextAttributeListener;
-import javax.servlet.ServletContextAttributeEvent;
-import org.apache.cometd.bayeux.Bayeux;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.cometd.bayeux.Client;
-import org.apache.cometd.bayeux.Listener;
-import org.apache.cometd.bayeux.Message;
-import org.apache.cometd.bayeux.Channel;
-
-public class EchoChatClient implements ServletContextListener, ServletContextAttributeListener, Listener {
-    
-    static AtomicInteger counter = new AtomicInteger(0);
-    protected int id;
-    protected Bayeux b;
-    protected Client c;
-    protected boolean alive = true;
-    protected TimestampThread tt = new TimestampThread();
-
-    public EchoChatClient() {
-        id = counter.incrementAndGet();
-        System.out.println("new listener created with id:"+id);
-    }
-
-    public void contextDestroyed(ServletContextEvent servletContextEvent) {
-        alive = false;
-        tt.interrupt();
-    }
-
-    public void contextInitialized(ServletContextEvent servletContextEvent) {
-    }
-
-    public void attributeAdded(ServletContextAttributeEvent scae) {
-        if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
-            System.out.println("Starting echo chat client!");
-            b = (Bayeux)scae.getValue();
-            c = b.newClient("echochat-",this);
-            Channel ch = b.getChannel("/chat/demo",true);
-            ch.subscribe(c);
-            tt.start();
-        }
-    }
-
-    public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
-    }
-
-    public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {
-    }
-
-    public void removed(boolean timeout) {
-        System.out.println("Client removed.");
-    }
-
-    public void deliver(Message[] msgs) {
-        for (int i=0; msgs!=null && i<msgs.length; i++) {
-            Message msg = msgs[i];
-            System.out.println("[echochatclient ]received message:" + msg);
-            Message m = b.newMessage(c);
-            m.putAll(msg);
-            //echo the same message
-            m.put("user", "echochatserver");
-            if (m.containsKey("msg")) {
-                //simple chat demo
-                String chat = (String) m.get("msg");
-                m.put("msg", "echochatserver|I received your message-" + chat.substring(chat.indexOf("|") + 1));
-            }
-            System.out.println("[echochatclient ]sending message:" + m);
-            msg.getChannel().publish(m);
-        }
-    }
-
-    public class TimestampThread extends Thread {
-        public TimestampThread() {
-            setDaemon(true);
-        }
-        
-        public void run() {
-            while (alive) {
-                try {
-                    sleep(5000);
-                    Channel ch = b.getChannel("/chat/demo",false);
-                    if (ch.getSubscribers().size()<=1) {
-                        continue;
-                    }
-                    Message m = b.newMessage(c);
-                    m.put("user","echochatserver");
-                    m.put("chat","Time is:"+new java.sql.Date(System.currentTimeMillis()).toLocaleString());
-                    m.put("join",false);
-                    ch.publish(m);
-                }catch (InterruptedException ignore) {
-                    Thread.currentThread().interrupted();
-                }catch (Exception x) {
-                    x.printStackTrace();
-                }
-            }
-        }
-    }
-}
+package org.apache.cometd.bayeux.samples;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextAttributeEvent;
+import org.apache.cometd.bayeux.Bayeux;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.cometd.bayeux.Client;
+import org.apache.cometd.bayeux.Listener;
+import org.apache.cometd.bayeux.Message;
+import org.apache.cometd.bayeux.Channel;
+
+public class EchoChatClient implements ServletContextListener, ServletContextAttributeListener, Listener {
+    
+    static AtomicInteger counter = new AtomicInteger(0);
+    protected int id;
+    protected Bayeux b;
+    protected Client c;
+    protected boolean alive = true;
+    protected TimestampThread tt = new TimestampThread();
+
+    public EchoChatClient() {
+        id = counter.incrementAndGet();
+        System.out.println("new listener created with id:"+id);
+    }
+
+    public void contextDestroyed(ServletContextEvent servletContextEvent) {
+        alive = false;
+        tt.interrupt();
+    }
+
+    public void contextInitialized(ServletContextEvent servletContextEvent) {
+    }
+
+    public void attributeAdded(ServletContextAttributeEvent scae) {
+        if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
+            System.out.println("Starting echo chat client!");
+            b = (Bayeux)scae.getValue();
+            c = b.newClient("echochat-",this);
+            Channel ch = b.getChannel("/chat/demo",true);
+            ch.subscribe(c);
+            tt.start();
+        }
+    }
+
+    public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
+    }
+
+    public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {
+    }
+
+    public void removed(boolean timeout) {
+        System.out.println("Client removed.");
+    }
+
+    public void deliver(Message[] msgs) {
+        for (int i=0; msgs!=null && i<msgs.length; i++) {
+            Message msg = msgs[i];
+            System.out.println("[echochatclient ]received message:" + msg);
+            Message m = b.newMessage(c);
+            m.putAll(msg);
+            //echo the same message
+            m.put("user", "echochatserver");
+            if (m.containsKey("msg")) {
+                //simple chat demo
+                String chat = (String) m.get("msg");
+                m.put("msg", "echochatserver|I received your message-" + chat.substring(chat.indexOf("|") + 1));
+            }
+            System.out.println("[echochatclient ]sending message:" + m);
+            msg.getChannel().publish(m);
+        }
+    }
+
+    public class TimestampThread extends Thread {
+        public TimestampThread() {
+            setDaemon(true);
+        }
+        
+        public void run() {
+            while (alive) {
+                try {
+                    sleep(5000);
+                    Channel ch = b.getChannel("/chat/demo",false);
+                    if (ch.getSubscribers().size()<=1) {
+                        continue;
+                    }
+                    Message m = b.newMessage(c);
+                    m.put("user","echochatserver");
+                    m.put("chat","Time is:"+new java.sql.Date(System.currentTimeMillis()).toLocaleString());
+                    m.put("join",false);
+                    ch.publish(m);
+                }catch (InterruptedException ignore) {
+                    Thread.currentThread().interrupted();
+                }catch (Exception x) {
+                    x.printStackTrace();
+                }
+            }
+        }
+    }
+}

Propchange: tomcat/trunk/modules/bayeux/test/org/apache/cometd/bayeux/samples/EchoChatClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/webapps/cometd/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/webapps/cometd/WEB-INF/web.xml?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/webapps/cometd/WEB-INF/web.xml (original)
+++ tomcat/trunk/modules/bayeux/webapps/cometd/WEB-INF/web.xml Fri Dec  5 07:57:43 2008
@@ -1,37 +1,37 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<web-app 
-   xmlns="http://java.sun.com/xml/ns/javaee" 
-   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
-   version="2.5"> 
-  <display-name>Cometd Test WebApp</display-name>
-  
-  <servlet>
-    <servlet-name>cometd</servlet-name>
-    <servlet-class>org.apache.tomcat.bayeux.BayeuxServlet</servlet-class>
-    <init-param>
-      <param-name>timeout</param-name>
-      <param-value>120000000</param-value>
-    </init-param>
-    <init-param>
-      <param-name>reconnectInterval</param-name>
-      <param-value>250</param-value>
-    </init-param>
-    <load-on-startup>1</load-on-startup>
-  </servlet>
-
-  <servlet-mapping>
-    <servlet-name>cometd</servlet-name>
-    <url-pattern>/cometd/*</url-pattern>
-  </servlet-mapping>
-  
-  <listener>
-    <listener-class>org.apache.cometd.bayeux.samples.EchoChatClient</listener-class>
-  </listener>
-  <listener>
-    <listener-class>org.apache.cometd.bayeux.samples.BayeuxStockTicker</listener-class>
-  </listener>
-  
-</web-app>
-
-
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<web-app 
+   xmlns="http://java.sun.com/xml/ns/javaee" 
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+   version="2.5"> 
+  <display-name>Cometd Test WebApp</display-name>
+  
+  <servlet>
+    <servlet-name>cometd</servlet-name>
+    <servlet-class>org.apache.tomcat.bayeux.BayeuxServlet</servlet-class>
+    <init-param>
+      <param-name>timeout</param-name>
+      <param-value>120000000</param-value>
+    </init-param>
+    <init-param>
+      <param-name>reconnectInterval</param-name>
+      <param-value>250</param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>cometd</servlet-name>
+    <url-pattern>/cometd/*</url-pattern>
+  </servlet-mapping>
+  
+  <listener>
+    <listener-class>org.apache.cometd.bayeux.samples.EchoChatClient</listener-class>
+  </listener>
+  <listener>
+    <listener-class>org.apache.cometd.bayeux.samples.BayeuxStockTicker</listener-class>
+  </listener>
+  
+</web-app>
+
+

Propchange: tomcat/trunk/modules/bayeux/webapps/cometd/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/webapps/cometd/examples/simplechat/ticker.html
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/webapps/cometd/examples/simplechat/ticker.html?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/webapps/cometd/examples/simplechat/ticker.html (original)
+++ tomcat/trunk/modules/bayeux/webapps/cometd/examples/simplechat/ticker.html Fri Dec  5 07:57:43 2008
@@ -1,128 +1,128 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" >
-<title>Bayeux Stock Ticker</title>
-<script type="text/javascript" src="../../dojo/dojo.js.uncompressed.js"></script>
-<script type="text/javascript" src="../../dojox/cometd.js"></script>
-<script type="text/javascript" src="../../dojox/cometd/_base.js"></script>
-<script type="text/javascript">
-
-dojo.require("dojox.cometd");
-
-dojo.addOnUnload(function() {
-	  dojox.cometd.init("/cometd/cometd");
-	  dojox.cometd.startBatch();
-	  dojox.cometd.unsubscribe("/stock/GOOG", this,"");
-	  dojox.cometd.unsubscribe("/stock/YHOO", this,"");
-	  dojox.cometd.unsubscribe("/stock/SPRG", this,"");
-	  dojox.cometd.endBatch();
-	});
-
-
-dojo.addOnLoad(function() {
-  dojox.cometd.init("/cometd/cometd");
-  dojox.cometd.startBatch();
-  dojox.cometd.subscribe("/stock/GOOG", onMsgEvent);
-  dojox.cometd.subscribe("/stock/YHOO", onMsgEvent);
-  dojox.cometd.subscribe("/stock/SPRG", onMsgEvent);
-  dojox.cometd.endBatch();
-});
-
-
-function subscribe(box, symbol) {
-	if (box.checked) {
-		dojox.cometd.subscribe("/stock/"+symbol, onMsgEvent);
-		var rowCurrent = dojo.byId("row."+symbol);
-		rowCurrent.bgColor="white";
-	} else {
-		dojox.cometd.unsubscribe("/stock/"+symbol, onMsgEvent);
-		var rowCurrent = dojo.byId("row."+symbol);
-		rowCurrent.bgColor="gray";
-	}
-}
-
-function removeChildrenFromNode(node)
-{
-   if(node == undefined || node == null)
-   {
-      return;
-   }
-
-   var len = node.childNodes.length;
-
-	while (node.hasChildNodes())
-	{
-	  node.removeChild(node.firstChild);
-	}
-}
-
-function onMsgEvent(event) {
-   // Break apart the text string into screen name and message parts.
-   var symbol = event.data.symbol;
-   var price = event.data.price;
-   var pricechange = event.data.change;
-   //alert("symbol: "+symbol+" price: "+price+" change: "+pricechange);
-
-   var pricenode = dojo.byId("price."+symbol);
-   var changenode = dojo.byId("change."+symbol);
-   removeChildrenFromNode(pricenode);
-   removeChildrenFromNode(changenode);
-   var pricelabel = document.createTextNode(price);
-   pricelabel.value = price;
-   var changelabel = document.createTextNode(pricechange);
-   changelabel.value = pricechange;
-   pricenode.appendChild(pricelabel);
-   changenode.appendChild(changelabel);
-
-   var table = dojo.byId("stocktable");  
-   var rows = table.getElementsByTagName("tr");  
-   for(i = 0; i < rows.length; i++){
-	   if (rows[i].bgColor != "gray") {
-	       rows[i].bgColor = "white"; 
-	   }
-   }          
-   //manipulate rows 
-   var rowCurrent = dojo.byId("row."+symbol);
-   if (pricechange<=0) {
-       rowCurrent.bgColor = "red";
-   } else {
-	   rowCurrent.bgColor = "cyan";
-   }
-}
-
-
-</script>
-</head>
-<body bgcolor="#ffffff">
-<h1 align="center">Bayeux Stock Ticker</h1>
-<h2 align="left"> &nbsp;</h2>
-<p>
-<table id="stocktable" cellspacing="0" cellpadding="3" width="100%" align="center" border="0">
-  <tr id="row.HEADER">
-    <td>SYMBOL</td>
-    <td>PRICE</td>
-    <td>LAST CHANGE</td>
-    <td>SUBSCRIBE</td></tr>
-  <tr id="row.SPRG">
-    <td>SPRG</td>
-    <td id="price.SPRG"></td>
-    <td id="change.SPRG"></td>
-    <td id="check.SPRG"><input type="checkbox" id="check.SPRG" checked onClick="subscribe(this,'SPRG')"></td>
-  </tr>
-  <tr id="row.GOOG">
-    <td>GOOG</td>
-    <td id="price.GOOG"></td>
-    <td id="change.GOOG"></td>
-    <td id="check.GOOG"><input type="checkbox" id="check.GOOG" checked  onClick="subscribe(this,'GOOG')"></td>
-  </tr>
-  <tr id="row.YHOO">
-    <td>YHOO</td>
-    <td id="price.YHOO"></td>
-    <td id="change.YHOO"></td>
-    <td id="check.YHOO"><input type="checkbox" id="check.GOOG" checked  onClick="subscribe(this,'YHOO')"></td>
-  </tr>
-</table>
-</p>
-</body>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" >
+<title>Bayeux Stock Ticker</title>
+<script type="text/javascript" src="../../dojo/dojo.js.uncompressed.js"></script>
+<script type="text/javascript" src="../../dojox/cometd.js"></script>
+<script type="text/javascript" src="../../dojox/cometd/_base.js"></script>
+<script type="text/javascript">
+
+dojo.require("dojox.cometd");
+
+dojo.addOnUnload(function() {
+	  dojox.cometd.init("/cometd/cometd");
+	  dojox.cometd.startBatch();
+	  dojox.cometd.unsubscribe("/stock/GOOG", this,"");
+	  dojox.cometd.unsubscribe("/stock/YHOO", this,"");
+	  dojox.cometd.unsubscribe("/stock/SPRG", this,"");
+	  dojox.cometd.endBatch();
+	});
+
+
+dojo.addOnLoad(function() {
+  dojox.cometd.init("/cometd/cometd");
+  dojox.cometd.startBatch();
+  dojox.cometd.subscribe("/stock/GOOG", onMsgEvent);
+  dojox.cometd.subscribe("/stock/YHOO", onMsgEvent);
+  dojox.cometd.subscribe("/stock/SPRG", onMsgEvent);
+  dojox.cometd.endBatch();
+});
+
+
+function subscribe(box, symbol) {
+	if (box.checked) {
+		dojox.cometd.subscribe("/stock/"+symbol, onMsgEvent);
+		var rowCurrent = dojo.byId("row."+symbol);
+		rowCurrent.bgColor="white";
+	} else {
+		dojox.cometd.unsubscribe("/stock/"+symbol, onMsgEvent);
+		var rowCurrent = dojo.byId("row."+symbol);
+		rowCurrent.bgColor="gray";
+	}
+}
+
+function removeChildrenFromNode(node)
+{
+   if(node == undefined || node == null)
+   {
+      return;
+   }
+
+   var len = node.childNodes.length;
+
+	while (node.hasChildNodes())
+	{
+	  node.removeChild(node.firstChild);
+	}
+}
+
+function onMsgEvent(event) {
+   // Break apart the text string into screen name and message parts.
+   var symbol = event.data.symbol;
+   var price = event.data.price;
+   var pricechange = event.data.change;
+   //alert("symbol: "+symbol+" price: "+price+" change: "+pricechange);
+
+   var pricenode = dojo.byId("price."+symbol);
+   var changenode = dojo.byId("change."+symbol);
+   removeChildrenFromNode(pricenode);
+   removeChildrenFromNode(changenode);
+   var pricelabel = document.createTextNode(price);
+   pricelabel.value = price;
+   var changelabel = document.createTextNode(pricechange);
+   changelabel.value = pricechange;
+   pricenode.appendChild(pricelabel);
+   changenode.appendChild(changelabel);
+
+   var table = dojo.byId("stocktable");  
+   var rows = table.getElementsByTagName("tr");  
+   for(i = 0; i < rows.length; i++){
+	   if (rows[i].bgColor != "gray") {
+	       rows[i].bgColor = "white"; 
+	   }
+   }          
+   //manipulate rows 
+   var rowCurrent = dojo.byId("row."+symbol);
+   if (pricechange<=0) {
+       rowCurrent.bgColor = "red";
+   } else {
+	   rowCurrent.bgColor = "cyan";
+   }
+}
+
+
+</script>
+</head>
+<body bgcolor="#ffffff">
+<h1 align="center">Bayeux Stock Ticker</h1>
+<h2 align="left"> &nbsp;</h2>
+<p>
+<table id="stocktable" cellspacing="0" cellpadding="3" width="100%" align="center" border="0">
+  <tr id="row.HEADER">
+    <td>SYMBOL</td>
+    <td>PRICE</td>
+    <td>LAST CHANGE</td>
+    <td>SUBSCRIBE</td></tr>
+  <tr id="row.SPRG">
+    <td>SPRG</td>
+    <td id="price.SPRG"></td>
+    <td id="change.SPRG"></td>
+    <td id="check.SPRG"><input type="checkbox" id="check.SPRG" checked onClick="subscribe(this,'SPRG')"></td>
+  </tr>
+  <tr id="row.GOOG">
+    <td>GOOG</td>
+    <td id="price.GOOG"></td>
+    <td id="change.GOOG"></td>
+    <td id="check.GOOG"><input type="checkbox" id="check.GOOG" checked  onClick="subscribe(this,'GOOG')"></td>
+  </tr>
+  <tr id="row.YHOO">
+    <td>YHOO</td>
+    <td id="price.YHOO"></td>
+    <td id="change.YHOO"></td>
+    <td id="check.YHOO"><input type="checkbox" id="check.GOOG" checked  onClick="subscribe(this,'YHOO')"></td>
+  </tr>
+</table>
+</p>
+</body>
 </html>
\ No newline at end of file

Propchange: tomcat/trunk/modules/bayeux/webapps/cometd/examples/simplechat/ticker.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/webapps/cometd/index.html
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/webapps/cometd/index.html?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/webapps/cometd/index.html (original)
+++ tomcat/trunk/modules/bayeux/webapps/cometd/index.html Fri Dec  5 07:57:43 2008
@@ -1,7 +1,7 @@
-
-<h1>Cometd demo</h1>
-
-<p>
-Try the <a href="examples/simplechat/cometdchat.htm">Simple Chat Demo</a>.</br>
-Try the <a href="examples/simplechat/ticker.html">Stock Ticker Demo</a>.</br>
-</p>
+
+<h1>Cometd demo</h1>
+
+<p>
+Try the <a href="examples/simplechat/cometdchat.htm">Simple Chat Demo</a>.</br>
+Try the <a href="examples/simplechat/ticker.html">Stock Ticker Demo</a>.</br>
+</p>

Propchange: tomcat/trunk/modules/bayeux/webapps/cometd/index.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/doc/changelog.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java Fri Dec  5 07:57:43 2008
@@ -1,135 +1,135 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tomcat.jdbc.pool.interceptor;
-
-import java.lang.reflect.Method;
-import java.sql.SQLException;
-
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-import org.apache.tomcat.jdbc.pool.ConnectionPool;
-import org.apache.tomcat.jdbc.pool.DataSourceFactory;
-import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
-import org.apache.tomcat.jdbc.pool.PoolProperties;
-import org.apache.tomcat.jdbc.pool.PooledConnection;
-
-/**
- * Interceptor that keep track of connection state to avoid roundtrips to the database
- * @author fhanik
- *
- */
-
-public class ConnectionState extends JdbcInterceptor  {
-    protected static Log log = LogFactory.getLog(ConnectionState.class);
-    
-    protected final String[] readState = {"getAutoCommit","getTransactionIsolation","isReadOnly","getCatalog"};
-    protected final String[] writeState = {"setAutoCommit","setTransactionIsolation","setReadOnly","setCatalog"};
-
-    protected Boolean autoCommit = null;
-    protected Integer transactionIsolation = null;
-    protected Boolean readOnly = null;
-    protected String catalog = null;
-    
-    
-    public void reset(ConnectionPool parent, PooledConnection con) {
-        PoolProperties poolProperties = parent.getPoolProperties();
-        if (poolProperties.getDefaultReadOnly()!=null) {
-            try {
-                if (readOnly==null || readOnly.booleanValue()!=poolProperties.getDefaultReadOnly().booleanValue()) {
-                    con.getConnection().setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
-                    readOnly = poolProperties.getDefaultReadOnly();
-                }
-            }catch (SQLException x) {
-                readOnly = null;
-                log.error("Unable to reset readonly state to connection.",x);
-            }
-        }
-        if (poolProperties.getDefaultAutoCommit()!=null) {
-            try {
-                if (autoCommit==null || autoCommit.booleanValue()!=poolProperties.getDefaultAutoCommit().booleanValue()) {
-                    con.getConnection().setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
-                    autoCommit = poolProperties.getDefaultAutoCommit();
-                }
-            }catch (SQLException x) {
-                autoCommit = null;
-                log.error("Unable to reset autocommit state to connection.",x);
-            }
-        }
-        if (poolProperties.getDefaultCatalog()!=null) {
-            try {
-                if (catalog==null || (!catalog.equals(poolProperties.getDefaultCatalog()))) {
-                    con.getConnection().setCatalog(poolProperties.getDefaultCatalog());
-                    catalog = poolProperties.getDefaultCatalog();
-                }
-            }catch (SQLException x) {
-                catalog = null;
-                log.error("Unable to reset default catalog state to connection.",x);
-            }
-        }
-        if (poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION) {
-            try {
-                if (transactionIsolation==null || transactionIsolation.intValue()!=poolProperties.getDefaultTransactionIsolation()) {
-                    con.getConnection().setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
-                    transactionIsolation = poolProperties.getDefaultTransactionIsolation();
-                }
-            }catch (SQLException x) {
-                transactionIsolation = null;
-                log.error("Unable to reset transaction isolation state to connection.",x);
-            }
-        }
-    }
-
-    @Override
-    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-        String name = method.getName();
-        boolean read = false;
-        int index = -1;
-        for (int i=0; (!read) && i<readState.length; i++) {
-            read = compare(name,readState[i]);
-            if (read) index = i;
-        }
-        boolean write = false;
-        for (int i=0; (!write) && (!read) && i<writeState.length; i++) {
-            write = compare(name,writeState[i]);
-            if (write) index = i;
-        }
-        Object result = null;
-        if (read) {
-            switch (index) {
-                case 0:{result = autoCommit; break;}
-                case 1:{result = transactionIsolation; break;}
-                case 2:{result = readOnly; break;}
-                case 3:{result = catalog; break;}
-                default: result = null;
-            }
-            //return cached result, if we have it
-            if (result!=null) return result;
-        }
-
-        result = super.invoke(proxy, method, args);
-        if (read || write) {
-            switch (index) {
-                case 0:{autoCommit = (Boolean) (read?result:args[0]); break;}
-                case 1:{transactionIsolation = (Integer)(read?result:args[0]); break;}
-                case 2:{readOnly = (Boolean)(read?result:args[0]); break;}
-                case 3:{catalog = (String)(read?result:args[0]); break;}
-            }
-        }
-        return result;
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.jdbc.pool.interceptor;
+
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.jdbc.pool.ConnectionPool;
+import org.apache.tomcat.jdbc.pool.DataSourceFactory;
+import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
+import org.apache.tomcat.jdbc.pool.PoolProperties;
+import org.apache.tomcat.jdbc.pool.PooledConnection;
+
+/**
+ * Interceptor that keep track of connection state to avoid roundtrips to the database
+ * @author fhanik
+ *
+ */
+
+public class ConnectionState extends JdbcInterceptor  {
+    protected static Log log = LogFactory.getLog(ConnectionState.class);
+    
+    protected final String[] readState = {"getAutoCommit","getTransactionIsolation","isReadOnly","getCatalog"};
+    protected final String[] writeState = {"setAutoCommit","setTransactionIsolation","setReadOnly","setCatalog"};
+
+    protected Boolean autoCommit = null;
+    protected Integer transactionIsolation = null;
+    protected Boolean readOnly = null;
+    protected String catalog = null;
+    
+    
+    public void reset(ConnectionPool parent, PooledConnection con) {
+        PoolProperties poolProperties = parent.getPoolProperties();
+        if (poolProperties.getDefaultReadOnly()!=null) {
+            try {
+                if (readOnly==null || readOnly.booleanValue()!=poolProperties.getDefaultReadOnly().booleanValue()) {
+                    con.getConnection().setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
+                    readOnly = poolProperties.getDefaultReadOnly();
+                }
+            }catch (SQLException x) {
+                readOnly = null;
+                log.error("Unable to reset readonly state to connection.",x);
+            }
+        }
+        if (poolProperties.getDefaultAutoCommit()!=null) {
+            try {
+                if (autoCommit==null || autoCommit.booleanValue()!=poolProperties.getDefaultAutoCommit().booleanValue()) {
+                    con.getConnection().setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
+                    autoCommit = poolProperties.getDefaultAutoCommit();
+                }
+            }catch (SQLException x) {
+                autoCommit = null;
+                log.error("Unable to reset autocommit state to connection.",x);
+            }
+        }
+        if (poolProperties.getDefaultCatalog()!=null) {
+            try {
+                if (catalog==null || (!catalog.equals(poolProperties.getDefaultCatalog()))) {
+                    con.getConnection().setCatalog(poolProperties.getDefaultCatalog());
+                    catalog = poolProperties.getDefaultCatalog();
+                }
+            }catch (SQLException x) {
+                catalog = null;
+                log.error("Unable to reset default catalog state to connection.",x);
+            }
+        }
+        if (poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION) {
+            try {
+                if (transactionIsolation==null || transactionIsolation.intValue()!=poolProperties.getDefaultTransactionIsolation()) {
+                    con.getConnection().setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
+                    transactionIsolation = poolProperties.getDefaultTransactionIsolation();
+                }
+            }catch (SQLException x) {
+                transactionIsolation = null;
+                log.error("Unable to reset transaction isolation state to connection.",x);
+            }
+        }
+    }
+
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        String name = method.getName();
+        boolean read = false;
+        int index = -1;
+        for (int i=0; (!read) && i<readState.length; i++) {
+            read = compare(name,readState[i]);
+            if (read) index = i;
+        }
+        boolean write = false;
+        for (int i=0; (!write) && (!read) && i<writeState.length; i++) {
+            write = compare(name,writeState[i]);
+            if (write) index = i;
+        }
+        Object result = null;
+        if (read) {
+            switch (index) {
+                case 0:{result = autoCommit; break;}
+                case 1:{result = transactionIsolation; break;}
+                case 2:{result = readOnly; break;}
+                case 3:{result = catalog; break;}
+                default: result = null;
+            }
+            //return cached result, if we have it
+            if (result!=null) return result;
+        }
+
+        result = super.invoke(proxy, method, args);
+        if (read || write) {
+            switch (index) {
+                case 0:{autoCommit = (Boolean) (read?result:args[0]); break;}
+                case 1:{transactionIsolation = (Integer)(read?result:args[0]); break;}
+                case 2:{readOnly = (Boolean)(read?result:args[0]); break;}
+                case 3:{catalog = (String)(read?result:args[0]); break;}
+            }
+        }
+        return result;
+    }
+
+}

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java Fri Dec  5 07:57:43 2008
@@ -1,206 +1,206 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tomcat.jdbc.pool.interceptor;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.sql.CallableStatement;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.LinkedHashMap;
-import java.util.Map.Entry;
-
-import org.apache.tomcat.jdbc.pool.ConnectionPool;
-import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
-import org.apache.tomcat.jdbc.pool.PooledConnection;
-
-/**
- * @author Filip Hanik
- * @version 1.0
- */
-public class SlowQueryReport extends AbstractCreateStatementInterceptor {
-    protected final String[] statements = {"createStatement","prepareStatement","prepareCall"};
-    protected final String[] executes = {"execute","executeQuery","executeUpdate","executeBatch"};
-
-    protected static IdentityHashMap<ConnectionPool,HashMap<String,QueryStats>> perPoolStats = 
-        new IdentityHashMap<ConnectionPool,HashMap<String,QueryStats>>();
-    
-    protected HashMap<String,QueryStats> queries = null;
-    
-    protected long threshold = 100; //don't report queries less than this
-    protected int  maxQueries= 1000; //don't store more than this amount of queries
-
-    
-    
-    public SlowQueryReport() {
-        super();
-    }
-
-    public long getThreshold() {
-        return threshold;
-    }
-
-    public void setThreshold(long threshold) {
-        this.threshold = threshold;
-    }
-
-    @Override
-    public void closeInvoked() {
-        // TODO Auto-generated method stub
-        
-    }
-
-    @Override
-    public Object createStatement(Object proxy, Method method, Object[] args, Object statement) {
-        // TODO Auto-generated method stub
-        String sql = null;
-        if (method.getName().startsWith("prepare")) {
-            sql = (args.length>0 && (args[0] instanceof String))?(String)args[0]:null;
-        }
-        return new StatementProxy(statement,sql);
-    }
-
-    protected boolean process(final String[] names, Method method, boolean process) {
-        for (int i=0; (!process) && i<names.length; i++) {
-            process = compare(method.getName(),names[i]);
-        }
-        return process;
-    }
-
-    protected class QueryStats {
-        private final String query;
-        private int nrOfInvocations;
-        private long maxInvocationTime;
-        private long maxInvocationDate;
-        private long minInvocationTime;
-        private long minInvocationDate;
-        private long totalInvocationTime;
-        
-        public QueryStats(String query) {
-            this.query = query;
-        }
-        
-        public void add(long invocationTime) {
-            long now = -1;
-            //not thread safe, but don't sacrifice performance for this kind of stuff
-            maxInvocationTime = Math.max(invocationTime, maxInvocationTime);
-            if (maxInvocationTime == invocationTime) {
-                now = System.currentTimeMillis();
-                maxInvocationDate = now;
-            }
-            minInvocationTime = Math.min(invocationTime, minInvocationTime);
-            if (minInvocationTime==invocationTime) {
-                now = (now==-1)?System.currentTimeMillis():now;
-                minInvocationDate = now;
-            }
-            nrOfInvocations++;
-            totalInvocationTime+=invocationTime;
-        }
-        
-        public String getQuery() {
-            return query;
-        }
-
-        public int getNrOfInvocations() {
-            return nrOfInvocations;
-        }
-
-        public long getMaxInvocationTime() {
-            return maxInvocationTime;
-        }
-
-        public long getMaxInvocationDate() {
-            return maxInvocationDate;
-        }
-
-        public long getMinInvocationTime() {
-            return minInvocationTime;
-        }
-
-        public long getMinInvocationDate() {
-            return minInvocationDate;
-        }
-
-        public long getTotalInvocationTime() {
-            return totalInvocationTime;
-        }
-
-        public int hashCode() {
-            return query.hashCode();
-        }
-        
-        public boolean equals(Object other) {
-            if (other instanceof QueryStats) {
-                QueryStats qs = (QueryStats)other;
-                return SlowQueryReport.this.compare(qs.query,this.query);
-            } 
-            return false;
-        }
-    }
-    
-    protected class StatementProxy implements InvocationHandler {
-        protected boolean closed = false;
-        protected Object delegate;
-        protected final String query;
-        public StatementProxy(Object parent, String query) {
-            this.delegate = parent;
-            this.query = query;
-        }
-        
-        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-            final String name = method.getName();
-            boolean close = compare(JdbcInterceptor.CLOSE_VAL,name);
-            if (close && closed) return null; //allow close to be called multiple times
-            if (closed) throw new SQLException("Statement closed.");
-            boolean process = false;
-            process = process(executes, method, process);
-            long start = (process)?System.currentTimeMillis():0;
-            //execute the query
-            Object result =  method.invoke(delegate,args);
-            long delta = (process)?(System.currentTimeMillis()-start):0;
-            if (delta>threshold) {
-                String sql = null;//TODO
-                QueryStats qs = SlowQueryReport.this.queries.get(sql);
-                if (qs == null) {
-                    qs = new QueryStats(sql);
-                    SlowQueryReport.this.queries.put((String)sql,qs);
-                }
-                qs.add(delta);
-                return qs;
-            }
-            if (close) {
-                closed=true;
-                delegate = null;
-            }
-            return result;
-        }
-    }
-
-    public void reset(ConnectionPool parent, PooledConnection con) {
-        if (queries==null && SlowQueryReport.perPoolStats.get(parent)==null) {
-            queries = new LinkedHashMap<String,QueryStats>() {
-                @Override
-                protected boolean removeEldestEntry(Entry<String, QueryStats> eldest) {
-                    return size()>maxQueries;
-                }
-
-            };
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.jdbc.pool.interceptor;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.CallableStatement;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+
+import org.apache.tomcat.jdbc.pool.ConnectionPool;
+import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
+import org.apache.tomcat.jdbc.pool.PooledConnection;
+
+/**
+ * @author Filip Hanik
+ * @version 1.0
+ */
+public class SlowQueryReport extends AbstractCreateStatementInterceptor {
+    protected final String[] statements = {"createStatement","prepareStatement","prepareCall"};
+    protected final String[] executes = {"execute","executeQuery","executeUpdate","executeBatch"};
+
+    protected static IdentityHashMap<ConnectionPool,HashMap<String,QueryStats>> perPoolStats = 
+        new IdentityHashMap<ConnectionPool,HashMap<String,QueryStats>>();
+    
+    protected HashMap<String,QueryStats> queries = null;
+    
+    protected long threshold = 100; //don't report queries less than this
+    protected int  maxQueries= 1000; //don't store more than this amount of queries
+
+    
+    
+    public SlowQueryReport() {
+        super();
+    }
+
+    public long getThreshold() {
+        return threshold;
+    }
+
+    public void setThreshold(long threshold) {
+        this.threshold = threshold;
+    }
+
+    @Override
+    public void closeInvoked() {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public Object createStatement(Object proxy, Method method, Object[] args, Object statement) {
+        // TODO Auto-generated method stub
+        String sql = null;
+        if (method.getName().startsWith("prepare")) {
+            sql = (args.length>0 && (args[0] instanceof String))?(String)args[0]:null;
+        }
+        return new StatementProxy(statement,sql);
+    }
+
+    protected boolean process(final String[] names, Method method, boolean process) {
+        for (int i=0; (!process) && i<names.length; i++) {
+            process = compare(method.getName(),names[i]);
+        }
+        return process;
+    }
+
+    protected class QueryStats {
+        private final String query;
+        private int nrOfInvocations;
+        private long maxInvocationTime;
+        private long maxInvocationDate;
+        private long minInvocationTime;
+        private long minInvocationDate;
+        private long totalInvocationTime;
+        
+        public QueryStats(String query) {
+            this.query = query;
+        }
+        
+        public void add(long invocationTime) {
+            long now = -1;
+            //not thread safe, but don't sacrifice performance for this kind of stuff
+            maxInvocationTime = Math.max(invocationTime, maxInvocationTime);
+            if (maxInvocationTime == invocationTime) {
+                now = System.currentTimeMillis();
+                maxInvocationDate = now;
+            }
+            minInvocationTime = Math.min(invocationTime, minInvocationTime);
+            if (minInvocationTime==invocationTime) {
+                now = (now==-1)?System.currentTimeMillis():now;
+                minInvocationDate = now;
+            }
+            nrOfInvocations++;
+            totalInvocationTime+=invocationTime;
+        }
+        
+        public String getQuery() {
+            return query;
+        }
+
+        public int getNrOfInvocations() {
+            return nrOfInvocations;
+        }
+
+        public long getMaxInvocationTime() {
+            return maxInvocationTime;
+        }
+
+        public long getMaxInvocationDate() {
+            return maxInvocationDate;
+        }
+
+        public long getMinInvocationTime() {
+            return minInvocationTime;
+        }
+
+        public long getMinInvocationDate() {
+            return minInvocationDate;
+        }
+
+        public long getTotalInvocationTime() {
+            return totalInvocationTime;
+        }
+
+        public int hashCode() {
+            return query.hashCode();
+        }
+        
+        public boolean equals(Object other) {
+            if (other instanceof QueryStats) {
+                QueryStats qs = (QueryStats)other;
+                return SlowQueryReport.this.compare(qs.query,this.query);
+            } 
+            return false;
+        }
+    }
+    
+    protected class StatementProxy implements InvocationHandler {
+        protected boolean closed = false;
+        protected Object delegate;
+        protected final String query;
+        public StatementProxy(Object parent, String query) {
+            this.delegate = parent;
+            this.query = query;
+        }
+        
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+            final String name = method.getName();
+            boolean close = compare(JdbcInterceptor.CLOSE_VAL,name);
+            if (close && closed) return null; //allow close to be called multiple times
+            if (closed) throw new SQLException("Statement closed.");
+            boolean process = false;
+            process = process(executes, method, process);
+            long start = (process)?System.currentTimeMillis():0;
+            //execute the query
+            Object result =  method.invoke(delegate,args);
+            long delta = (process)?(System.currentTimeMillis()-start):0;
+            if (delta>threshold) {
+                String sql = null;//TODO
+                QueryStats qs = SlowQueryReport.this.queries.get(sql);
+                if (qs == null) {
+                    qs = new QueryStats(sql);
+                    SlowQueryReport.this.queries.put((String)sql,qs);
+                }
+                qs.add(delta);
+                return qs;
+            }
+            if (close) {
+                closed=true;
+                delegate = null;
+            }
+            return result;
+        }
+    }
+
+    public void reset(ConnectionPool parent, PooledConnection con) {
+        if (queries==null && SlowQueryReport.perPoolStats.get(parent)==null) {
+            queries = new LinkedHashMap<String,QueryStats>() {
+                @Override
+                protected boolean removeEldestEntry(Entry<String, QueryStats> eldest) {
+                    return size()>maxQueries;
+                }
+
+            };
+        }
+    }
+}

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/StatementFinalizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOExample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/StatementFinalizerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestConnectionState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TwoDataSources.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message