1 38 39 40 package org.jahia.services.cache; 41 42 43 59 class JMSHubPublisher { 60 61 62 final private static org.apache.log4j.Logger logger = 63 org.apache.log4j.Logger.getLogger (JMSHubPublisher.class); 64 65 66 private Thread thread; 67 68 69 private JMSHubPublisherHandler handler; 70 71 72 protected JMSHubPublisher () { 73 74 logger.debug ("JMSHubPublisher successfully instanciated!"); 76 } 77 78 79 86 public synchronized void connect (JMSHub hub) 87 throws JMSConnectionException 88 { 89 if (((thread != null) && thread.isAlive()) && (handler != null)) { 91 return; 92 } 93 94 if (handler != null) { 96 handler.stop(); 97 } 98 99 if (thread != null) { 101 try { 102 thread.interrupt(); 103 thread.join(); 104 } catch (InterruptedException ex) { 105 } 107 } 108 109 handler = new JMSHubPublisherHandler (); 110 handler.init (hub); 111 112 thread = new Thread (handler, "JMS Publisher"); 113 thread.start(); 114 115 logger.info("JMS Message Publisher successfully started."); 116 } 117 118 121 public synchronized void disconnect () { 122 if (thread == Thread.currentThread()) { 123 thread = null; 124 handler = null; 125 return; 126 } 127 128 if (handler != null) 129 handler.stop(); 130 131 if (thread != null) { 132 try { 133 thread.join(); 134 135 } catch (InterruptedException ex) { 136 } 138 } 139 140 thread = null; 141 handler = null; 142 } 143 144 148 public synchronized void publishMessage (JMSCacheMessage message) { 149 if (message == null) 150 return; 151 152 if ((handler != null) && ((thread != null) && (thread.isAlive()))) { 153 handler.publishMessage (message); 154 155 } else { 156 logger.debug("The Message Publisher is not connected. Message dropped."); 157 } 158 } 159 160 164 public synchronized void sendNow () { 165 166 if ((handler != null) && ((thread != null) && (thread.isAlive()))) { 167 handler.sendNow(); 168 169 } else { 170 logger.debug("The Message Publisher is not connected. Message dropped."); 171 } 172 } 173 } 174 | Popular Tags |