1 24 33 34 package org.datashare; 35 36 import org.datashare.objects.DataShareObject; 37 38 45 class TransmitDataThread extends Thread 46 { 47 private boolean running = true; 48 private SocketAdapter sa; 49 private DataShareObject dso; 50 private FifoQueue pipe = new FifoQueue(); 51 52 57 public TransmitDataThread(SocketAdapter sa) 58 { 59 this.sa = sa; 60 } 61 62 67 public void addData(DataShareObject dso) 68 { 69 pipe.write(dso); 70 } 71 72 75 public void stopThread() 76 { 77 SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG, 78 SessionUtilities.getLoggingInterface().NETWORK, 79 "stopThread() called for " + getName()); 80 running = false; 81 pipe.close(); 82 } 83 84 88 public void run() 89 { 90 while(running) 91 { 92 if(running) 93 { 94 dso = (DataShareObject)pipe.read(); if(dso != null) 96 { 97 if(SessionUtilities.getVerbose()) 98 { 99 int count = pipe.size(); 100 SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG, 101 SessionUtilities.getLoggingInterface().NETWORK, 102 "4-Xmitting " + dso.sendingClientKey + " object to " + sa.getKeyValue() + ((count>1)?(", " + count + " objects backlogged"):"")); 103 } 104 sa.xmitData(dso); 105 yield(); 106 } 107 else 108 { 109 SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG, 110 SessionUtilities.getLoggingInterface().NETWORK, 111 "TransmitDataThread pipe returned null for " + this.getName() + ", closing xmitThread..."); 112 this.stopThread(); 113 } 114 } 115 } SessionUtilities.getLoggingInterface().debugMsg(SessionUtilities.getLoggingInterface().DEBUG, 117 SessionUtilities.getLoggingInterface().NETWORK, 118 "Thread " + getName() + " has stopped"); 119 } 120 121 } 122 | Popular Tags |