KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > cache > JMSHubLookup


1 /*
2  * ____.
3  * __/\ ______| |__/\. _______
4  * __ .____| | \ | +----+ \
5  * _______| /--| | | - \ _ | : - \_________
6  * \\______: :---| : : | : | \________>
7  * |__\---\_____________:______: :____|____:_____\
8  * /_____|
9  *
10  * . . . i n j a h i a w e t r u s t . . .
11  *
12  *
13  *
14  * ----- BEGIN LICENSE BLOCK -----
15  * Version: JCSL 1.0
16  *
17  * The contents of this file are subject to the Jahia Community Source License
18  * 1.0 or later (the "License"); you may not use this file except in
19  * compliance with the License. You may obtain a copy of the License at
20  * http://www.jahia.org/license
21  *
22  * Software distributed under the License is distributed on an "AS IS" basis,
23  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
24  * for the rights, obligations and limitations governing use of the contents
25  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
26  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
27  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
28  *
29  * The Developer of the Shared Modifications is Jahia Solution Sarl.
30  * Portions created by the Initial Developer are Copyright (C) 2002 by the
31  * Initial Developer. All Rights Reserved.
32  *
33  * Contributor(s):
34  * 07-SEP-2003, Jahia Solutions Sarl, Fulco Houkes : Initial version
35  *
36  * ----- END LICENSE BLOCK -----
37  */

38
39 package org.jahia.services.cache;
40
41 import org.jahia.exceptions.JahiaInitializationException;
42
43
44 /** This class is used when the connection to the JMS server was lost or when the server
45  * could not be found. This class will attempt to reconnect to the server each n milliseconds,
46  * as defined in the Jahia configuration file. As soon as a connection to the server could
47  * be made, the lookup process will stop and the associated thread will be destroyed.
48  *
49  * @author Fulco Houkes, Copyright (c) 2003 by Jahia Ltd.
50  * @version 1.0
51  * @since Jahia 4.0
52  */

53 class JMSHubLookup implements Runnable JavaDoc {
54
55     /** logging. */
56     final private static org.apache.log4j.Logger logger =
57             org.apache.log4j.Logger.getLogger (JMSHubLookup.class);
58
59     /** thread sleep time between 2 tries. */
60     private long sleep;
61
62     /** <code>true</code> when the thread is running. */
63     private boolean running;
64
65     /** Reference to the JMSHub. */
66     private JMSHub jmsHub;
67
68
69     /** Default constructor, creates a new <code>JMSHubLookup</code> instance.
70      *
71      * @param hub the JMS Hub to use for cache synchronization
72      * @param sleep the milliseconds to wait between to reconnection retries
73      */

74     public JMSHubLookup (JMSHub hub, long sleep) {
75         this.sleep = sleep;
76         this.jmsHub = hub;
77         running = false;
78
79         logger.debug ("New JMSHubLookup successfully instanciated!");
80     }
81
82     /** Starts the JMS Server lookup process. This method should not be called as it
83      * will be called by the associated thread's <code>start()</code> method.
84      */

85     public void run () {
86         running = true;
87         while (running) {
88
89             try {
90                 jmsHub.internalConnect();
91                 running = false;
92
93             } catch (JahiaInitializationException e) {
94                 logger.warn (e);
95
96             } catch (JMSConnectionException e) {
97                 logger.warn (e);
98             }
99
100             synchronized (this) {
101                 try {
102                     if (running) {
103                         logger.info ("Try to recontact the JMS Server in "+ sleep +" milliseconds.");
104                         wait (sleep); // wait for next notify
105
}
106                 } catch (InterruptedException JavaDoc ie) {
107                     // it's what we were waiting for...
108
}
109             }
110         }
111     }
112
113
114     /** Stops the JMS Server lookup process.
115      */

116     public synchronized void stop () {
117         running = false;
118         notifyAll();
119     }
120
121 }
122
Popular Tags