View Javadoc
1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact info@exolab.org. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2000 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * 44 * $Id: HttpJmsSessionPinger.java,v 1.5 2003/08/17 01:32:26 tanderson Exp $ 45 * 46 * Date Author Changes 47 * Wed 31 Oct 2001 mourikis Created 48 */ 49 50 51 package org.exolab.jms.server.http; 52 53 import org.exolab.jms.config.Configuration; 54 import org.exolab.jms.config.ConfigurationManager; 55 import org.exolab.jms.config.HttpConfiguration; 56 57 58 /*** 59 * A simpler pinger, which runs in its own thread and is responsible for 60 * pinging a client session, if no messages have been sent to the client with a 61 * timeout period. Package protected. 62 * 63 * @version $Revision: 1.5 $ $Date: 2003/08/17 01:32:26 $ 64 * @author <a href="mailto:mourikis@intalio.com">Jim Mourikis</a> 65 * @see HttpJmsSessionSender 66 */ 67 public class HttpJmsSessionPinger implements Runnable { 68 69 // The session we require to ping. 70 private HttpJmsSessionSender session_ = null; 71 72 // The session is closed, finish pinging. 73 private boolean finished_ = false; 74 75 // A message was sent during the timeout period, reset the clock. 76 private boolean reset_ = false; 77 78 // The timeout period for pings. 79 private int timeout_; 80 81 /*** 82 * Construct pinger, with a reference to appropriate session. 83 * 84 * @param session The session we are interested in pinging. 85 * 86 */ 87 HttpJmsSessionPinger(HttpJmsSessionSender session) { 88 session_ = session; 89 HttpConfiguration config = 90 ConfigurationManager.getConfig().getHttpConfiguration(); 91 timeout_ = config.getClientPingInterval() * 1000; 92 if (timeout_ == 0) { 93 timeout_ = 60 * 1000; 94 } 95 } 96 97 /*** 98 * Reset the timeout, client has sent a message. 99 */ 100 void reset() { 101 reset_ = true; 102 } 103 104 105 /*** 106 * Session has closed. Set the flag to stop pining. 107 */ 108 void close() { 109 finished_ = true; 110 } 111 112 /*** 113 * The main loop of the thread which does the pinging. 114 */ 115 public void run() { 116 while (!finished_) { 117 try { 118 reset_ = false; 119 Thread.sleep(timeout_); 120 if (!finished_ && !reset_) { 121 session_.ping(); 122 } 123 } catch (org.exolab.jms.server.ClientDisconnectionException e) { 124 session_.close(); 125 } catch (InterruptedException ignore) { 126 } 127 } 128 session_ = null; 129 } 130 131 132 } // End HttpJmsSessionPinger

This page was automatically generated by Maven