zD12 / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Thread safe DCC file send packet delay and progress #145

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Start a DCC file send. 
2. Get progress or set packet delay while transfer in progress.

What is the expected output? What do you see instead?

Expect to get progress or set packet delay in a thread safe manner.

What version of the product are you using? On what operating system?

1.9. Windows x64

Please provide any additional information below.

In my application, I might have multiple DCC file transfers which are running. 
I need to be able to get progress and/or throttle internet usage in a thread 
safe manner. The DccFileTransfer class does not meet this requirement.

This can be rectified by using variable type AtomicLong for variables: 

packetDelay
progress

And changing the associated methods to 

AtomicLong#get()
AtomicLong#getAndSet(long value)

Or you can synchronize.

Original issue reported on code.google.com by jely.chr...@gmail.com on 1 Oct 2013 at 8:38

GoogleCodeExporter commented 9 years ago
Well 2.0 handles things a bit differently. There's only a bytesTransfered 
field; progress is calculated if PircBotX knows the final size of the file. You 
shouldn't have any concurrency issues since your only reading a value, not 
writing to it. 

Instead of bringing back packetDelay which might not fit your needs I've added 
a callback method onAfterSend() to the FileTransfer abstract class. You can 
implement your own delay algorithm without having to hack around a single delay 
field or synchronization nonsense. Just remember you have to create your 
subclass in BotFactory so PircBotX uses the correct one. 

Added in Revision 14ee2104f6be

Original comment by Lord.Qua...@gmail.com on 15 Oct 2013 at 2:04