|
-
November 27th, 2003, 09:49 AM
#6
Design Consulting:
Hi!
My sever may send a large packets of data using DataOutputStream, and i want the client to be able to abort from the sending in the middle if it takes too much time.
So what i want to do is to add a special flag in the method and then when the clients send a special token the flag will be raised and the server will abort from the sending.
this is my design for it :
I have a connection class -when ever a client connects the server creates a new connection object that is also a thread.
the connection recieves data ,process it using ProcessData object and returns it to the client.
In order to be able to reiceve the abort token i consider to create another thread in a private class inside the Connection class that will then again listen to the inputstream and recieve the speical token if it is sent.
then ,i also need to add the flag,
i tracked the writeUTF(String s) method in the DataOutputStream object and saw that in the end of the encoding it sends its bytes using a method it recieves from FilterOutputStream
in this method :
Code:
public void write(byte b[], int off, int len) throws IOException {
if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
throw new IndexOutOfBoundsException();
for (int i = 0 ; i < len ; i++) {
write(b[off + i]);
}
}
so basicly i need to add the flag to the for loop .
so what im going to do is to extend the FilterOutputStream class in a private class in the Connection Class and override that method adding the flag .
then im going to extend that private class with another private class which will add the writeUTF() functionallity -taken from the DataOutputStream class in the old fushiond copy&paste way (kill bill)
The second private class is no longer DataOutputStream by any chance ,its just a class that supports writing Strings so i feel like im moving into deep water around here as im not sure what exactly happens behind stage when the communication takes place.
what do you think of my design ?
including the abort thread listener and the outputstream abort flag functionallity ?
do you have any better design that i can use ? cuz this seems a little off bounds .
but ofcourse i will use it if ill have to.
what bothers me even more is how do i avoid exceptions on the client side when the server suddenly stops sending data ?
also i want to add a Gauge that will show how much has been completed.
for that im going to extend the DataInputStream on the client side and count how much data recieved ,then add a status method that will simply return me a double precentege number.
Thank You !
Vision.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|