1 26 27 package chat; 28 29 import com.lutris.appserver.server.*; 30 import com.lutris.appserver.server.httpPresentation.*; 31 import com.lutris.appserver.server.session.*; 32 import com.lutris.util.*; 33 34 import chat.spec.*; 35 36 40 public class ChatApplication extends StandardApplication { 41 42 private String roomName = "Chat Room"; 43 private String bgColor = ""; 44 private String clearCommand = ""; 45 46 52 public void startup(Config appConfig) throws ApplicationException { 53 super.startup(appConfig); 57 try { 58 roomName = appConfig.getString("RoomName", "Chat Room"); 59 } catch (ConfigException e) { 60 throw new ApplicationException("Bogus RoomName in config file.", e); 61 } 62 65 int messageLifetimeSecs; 66 try { 67 messageLifetimeSecs = appConfig.getInt("MessageLifetimeSecs", 300); 68 } catch (ConfigException e) { 69 throw new ApplicationException( 70 "Bogus MessageLifetimeSecs in config file.", e); 71 } 72 75 int harvestIntervalSecs; 76 try { 77 harvestIntervalSecs = appConfig.getInt("HarvestIntervalSecs", 55); 78 } catch (ConfigException e) { 79 throw new ApplicationException("Bogus HarvestIntervalSecs in config file.", e); 80 } 81 87 int maxQueueSize; 88 try { 89 maxQueueSize = appConfig.getInt("MaxQueueSize", 200); 90 } catch (ConfigException e) { 91 throw new ApplicationException( 92 "Bogus MaxQueueSize in config file.", e); 93 } 94 97 try { 98 bgColor = appConfig.getString("BackgroundColor", "#99CCFF"); 99 } catch (ConfigException e) { 100 throw new ApplicationException( 101 "Bogus BackgroundColor in config file.", e); 102 } 103 106 try { 107 clearCommand = appConfig.getString("ResetCommand", ""); 108 } catch (ConfigException e) { 109 throw new ApplicationException( 110 "Bogus ResetCommand in config file.", e); 111 } 112 116 117 DiscussionManager discussionManager = DiscussionManagerFactory.getDiscussionManager("chat.business.DiscussionManagerImpl"); 118 119 123 try{ 124 discussionManager.setMaxQueueSize(maxQueueSize); 125 126 if (harvestIntervalSecs < 1) 127 harvestIntervalSecs = 1; 128 if (messageLifetimeSecs > 0) 129 130 discussionManager.startHarvester(messageLifetimeSecs, harvestIntervalSecs); 131 132 }catch(NullPointerException e){} 133 134 } 135 136 137 public boolean requestPreprocessor(HttpPresentationComms comms) 138 throws Exception { 139 return super.requestPreprocessor(comms); 140 } 141 142 143 public void shutdown(){ 144 DiscussionManager discussionManager = DiscussionManagerFactory.getDiscussionManager("chat.business.DiscussionManagerImpl"); 145 try{ 146 discussionManager.stopHarvester(); 147 }catch(NullPointerException e){} 148 } 149 152 public String getRoomName() { 153 return roomName; 154 } 155 156 157 161 public String getBgColor() { 162 return bgColor; 163 } 164 165 170 public String getClearCommand() { 171 return clearCommand; 172 } 173 174 175 186 public String toHtml() { 187 String response; 188 189 190 191 DiscussionManager discussionManager = DiscussionManagerFactory.getDiscussionManager("chat.business.DiscussionManagerImpl"); 192 int n = discussionManager.getNumWaiting(); 193 194 if (n == 1) 195 response = "There is 1 person listening."; 196 else 197 response = "There are " + n + " people listening."; 198 199 long l = discussionManager.getTotalReceived(); 200 201 if (l == 1) 202 response += "<br>A total of 1 message has been received so far."; 203 else 204 response += "<br>A total of " + l + " messages have been received."; 205 206 l = discussionManager.getCurrentSize(); 207 if (l == 1) 208 response += "<br>There is currently 1 message."; 209 else 210 response += "<br>There are currently " + l + " messages."; 211 return response; 212 } 213 214 } 215 216 | Popular Tags |