1 24 36 37 package org.datashare; 38 39 40 import java.util.Date ; 41 import java.util.Hashtable ; 42 import org.datashare.objects.ChannelDescription; 43 import org.datashare.objects.DefaultObjectInfo; 44 import org.datashare.objects.DataShareConnectionDescriptor; 45 46 55 public class ChannelInfo extends DefaultObjectInfo implements PersistDataCallbackInterface, 56 java.io.Serializable 57 { 58 62 static final long serialVersionUID = 9030593814524545453L; 63 64 67 transient private DataReceiverAdapter dataReceiverAdapter = null; 68 69 72 private DataShareConnectionDescriptor connectionDescriptor = null; 73 74 78 transient private SessionInfo parentSession = null; 80 84 transient private Hashtable consumerTable = new Hashtable (); 86 90 private boolean saveData = true; 91 92 96 private ChannelInfo() 97 { 98 originalType = CHANNELTYPE; 99 } 100 101 106 private ChannelInfo(String name) 107 { 108 this(); 109 this.name = name; 110 keyValue = name; 111 toString = name; 112 } 113 114 117 public ChannelInfo(DataShareConnectionDescriptor connectionDescriptor, 118 DataReceiverAdapter dataReceiverAdapter, 119 SessionInfo parentSession, 120 boolean tryToSaveData) 121 { 122 this(connectionDescriptor.name); 123 this.connectionDescriptor = connectionDescriptor; 124 this.parentSession = parentSession; 125 this.parentKeyValue = parentSession.getKeyValue(); 126 this.dataReceiverAdapter = dataReceiverAdapter; 127 this.ownerName = parentSession.getOwnerName(); 128 if(connectionDescriptor.channelDescription.allowPersistSelection) 129 this.saveData = connectionDescriptor.channelDescription.persist && tryToSaveData; 130 else 131 this.saveData = false; 132 this.clientClass = parentSession.getClientClass(); 133 } 134 135 139 public DataShareConnectionDescriptor 140 getConnectionDescriptor() 141 { 142 return connectionDescriptor; 143 } 144 145 148 public DataReceiverAdapter 149 getDataReceiverAdapter() 150 { 151 return dataReceiverAdapter; 152 } 153 154 160 public SessionInfo 161 getSessionInfo() 162 { 163 return parentSession; 164 } 165 166 173 public void 174 setSessionInfo(SessionInfo sessionInfo) 175 { 176 parentSession = sessionInfo; 177 } 178 179 187 public Object 188 getObject() 189 { 190 return connectionDescriptor; 191 } 192 193 200 public String 201 getType() 202 { 203 return CHANNELTYPE; 204 } 205 206 209 public void 210 shutDown() 211 { 212 this.dataReceiverAdapter.removeAllConsumerConnections(); 213 this.dataReceiverAdapter.getSocketServer().close(); 214 this.setActive(false); 215 } 216 217 223 public String 224 getFunction() 225 { 226 return name; 227 } 228 229 234 public String 235 getInfo() 236 { 237 String filename = ""; 238 if(this.connectionDescriptor.channelDescription.channelJarFileName.equals("")) 239 filename = ""; 240 else 241 filename = "<tr><td>Jar Filename</td><td>" + this.connectionDescriptor.channelDescription.channelJarFileName + "</td></tr>"; 242 243 return "<tr><td>Function Name</td><td>" + this.name + "</td></tr>" + 244 "<tr><td>Description</td><td>" + this.connectionDescriptor.channelDescription.channelDescription + "</td></tr>" + 245 filename + 246 "<tr><td>Socket type</td><td>" + ChannelDescription.validTypes[this.connectionDescriptor.type] + "</td></tr>" + 247 "<tr><td>Server port</td><td>" + this.connectionDescriptor.serverPort + "</td></tr>" + 248 "<tr><td>Data persistance</td><td>" + (this.getSaveDataForThisChannel() ? "Data is " : "Data is not ") + "being saved</td></tr>" + 249 "<tr><td>Allowed to record history</td><td>"+(this.connectionDescriptor.channelDescription.allowPersistSelection? "Yes":"No") +"</td></tr>" + 250 "<tr><td>Creation date</td><td>" + this.getDate().toString() +"</td></tr>"; 251 } 252 253 258 public void 259 addConsumerClient(ConsumerInfo consumer) 260 { 261 SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG, 262 SessionUtilities.getLoggingInterface().CLIENT, 263 "channelInfo.addConsumerClient (" + consumer.getKeyValue() + 264 ") to Session " + this.parentSession.getName() + ", Channel " + 265 this.toString() + " table of Consumers"); 266 267 if(consumerTable == null) 269 consumerTable = new Hashtable (); 270 271 consumerTable.put(consumer.getKeyValue(), consumer); 272 } 273 274 279 public void 280 removeConsumerClient(ConsumerInfo consumer) 281 { 282 this.dataReceiverAdapter.removeConsumerConnection(consumer.getKeyValue()); 284 285 SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG, 286 SessionUtilities.getLoggingInterface().CLIENT, 287 "Removing consumer (" + consumer.getKeyValue() + 288 ") from Session " + this.parentSession.getName() + ", Channel " + 289 this.toString() + " ChannelInfo table of consumers"); 290 consumerTable.remove(consumer.getKeyValue()); 291 } 292 293 296 public boolean 297 checkForConsumer(ConsumerInfo consumer) 298 { 299 boolean retValue = false; 300 if(consumerTable.contains(consumer.getKeyValue())) 301 retValue = true; 302 return retValue; 303 } 304 305 310 public Hashtable 311 getConsumerTable() 312 { 313 return consumerTable; 314 } 315 316 322 public void 323 setSaveDataForThisChannel(boolean saveData) 324 { 325 this.saveData = saveData; 326 } 327 328 333 public boolean 334 getSaveDataForThisChannel() 335 { 336 return saveData; 337 } 338 339 345 public void 346 setDatabaseID(String ak) 347 { 348 SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG, 349 SessionUtilities.getLoggingInterface().DATABASE, 350 "setDatabaseID(): EJB Key for " + this.getKeyValue() + " has value of " + ak); 351 databaseID = ak; 352 waitingForKey = false; 353 keyHasBeenReturned = true; 354 } 355 356 362 public String 363 getDatabaseID() 364 { 365 String thisKey = null; 366 if(this.saveData) 367 if(this.databaseID != null) 368 thisKey = databaseID; 369 else 370 thisKey = retrieveEJB(); 371 return thisKey; 372 } 373 374 } 375 | Popular Tags |