1 21 package com.db4o.cs; 22 23 import com.db4o.cs.messages.*; 24 import com.db4o.foundation.*; 25 import com.db4o.foundation.network.*; 26 27 class YapClientBlobThread extends Thread { 28 private YapClient stream; 29 private Queue4 queue = new Queue4(); 30 private boolean terminated = false; 31 32 YapClientBlobThread(YapClient aStream){ 33 stream = aStream; 34 setPriority(MIN_PRIORITY); 35 } 36 37 void add(MsgBlob msg){ 38 synchronized(queue){ 39 queue.add(msg); 40 } 41 } 42 43 synchronized boolean isTerminated(){ 44 return terminated; 45 } 46 47 public void run(){ 48 try{ 49 YapSocket socket = stream.createParalellSocket(); 50 51 MsgBlob msg = null; 52 53 synchronized(queue){ 55 msg = (MsgBlob)queue.next(); 56 } 57 58 while(msg != null){ 59 msg.write(stream, socket); 60 msg.processClient(socket); 61 synchronized(stream.blobLock){ 62 synchronized(queue){ 63 msg = (MsgBlob)queue.next(); 64 } 65 if(msg == null){ 66 terminated = true; 67 Msg.CLOSE.write(stream, socket); 68 try{ 69 socket.close(); 70 }catch(Exception e){ 71 } 72 } 73 } 74 } 75 }catch(Exception e){ 76 e.printStackTrace(); 77 } 78 } 79 80 } 81 | Popular Tags |