Re: [Factor-talk] Hooking the Back End

2016-06-13 Thread John Benediktsson
The delegate vocabulary might work. Also could initialed the Windows backend 
and then set yours and for all words you hart implemented just call the Windows 
one. 

> On Jun 13, 2016, at 11:28 AM, Alexander Ilin  wrote:
> 
> Hello!
> 
>  I'm having a bit of a fun problem, and I'd like you to help me with a 
> solution.
> 
>  I want to create a custom io-backend. In my implementation all calls to 
> copy-file, move-file and delete-file should be captured and queued for 
> deferred and/or background batch processing.
> 
>  The problem: the current implementation of copy-file calls WinAPI's 
> CopyFile, which blocks for the duration of the operation. For big files that 
> takes time. I want to create my own implementation that would copy the file 
> piece by piece in a Factor's cooperative non-blocking asynchronous background 
> super-awesome thread.
> 
>  The solution: I have created a custom backend singleton and intercepted the 
> necessary methods. I'm advancing my implementation carefully one step at a 
> time. Currently I'm making the copy-file calculate a sha-256 hash of the 
> file, just to make sure it reads all of the contents correctly. Next step 
> will be writing the data to the new location.
> 
>  Already I have a problem: with-file-reader calls (file-reader) internally, 
> which is hooked on io-backend. But my custom backend doesn't provide an 
> implementation for (file-reader). The way I want this to work is this: my 
> custom backend is to only intercept the methods I override (delete-file, 
> copy-file and move-file), and all the other methods are to be handled by the 
> previously installed backend. Kinda like an inheritance-type thing. Is there 
> a way to do this?
> 
>  Is there a better approach to the whole problem?
> 
>  My code so far:
> 
> USING: kernel namespaces
>formatting prettyprint
>checksums checksums.sha
>io.backend io.files io.directories io.encodings.binary ;
> 
> IN: batch
> 
> SINGLETON: batch-io-backend
> 
> : with-batch-io-backend ( quot -- )
>[ batch-io-backend io-backend ] dip with-variable ; inline
> 
> M: batch-io-backend delete-file ( path -- )
>"TODO: batch delete file (%s)" sprintf . ;
> 
> M: batch-io-backend copy-file ( from to -- )
>2dup "batch copy file (%s -> %s)" sprintf .
>drop binary [
>sha-256 initialize-checksum-state
>"hello" add-checksum-bytes
>get-checksum .
>] with-file-reader ;
> 
> M: batch-io-backend move-file ( from to -- )
>"TODO: batch move file (%s -> %s)" sprintf . ;
> 
> 
> IN: scratchpad [ "README.md" "dst" copy-file ] with-batch-io-backend
> 
> ---=---
> Александр
> 
> --
> What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
> patterns at an interface-level. Reveals which users, apps, and protocols are 
> consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
> J-Flow, sFlow and other flows. Make informed decisions using capacity 
> planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk

--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Hooking the Back End

2016-06-13 Thread Alexander Ilin
Hello!

  I'm having a bit of a fun problem, and I'd like you to help me with a 
solution.

  I want to create a custom io-backend. In my implementation all calls to 
copy-file, move-file and delete-file should be captured and queued for deferred 
and/or background batch processing.

  The problem: the current implementation of copy-file calls WinAPI's CopyFile, 
which blocks for the duration of the operation. For big files that takes time. 
I want to create my own implementation that would copy the file piece by piece 
in a Factor's cooperative non-blocking asynchronous background super-awesome 
thread.

  The solution: I have created a custom backend singleton and intercepted the 
necessary methods. I'm advancing my implementation carefully one step at a 
time. Currently I'm making the copy-file calculate a sha-256 hash of the file, 
just to make sure it reads all of the contents correctly. Next step will be 
writing the data to the new location.

  Already I have a problem: with-file-reader calls (file-reader) internally, 
which is hooked on io-backend. But my custom backend doesn't provide an 
implementation for (file-reader). The way I want this to work is this: my 
custom backend is to only intercept the methods I override (delete-file, 
copy-file and move-file), and all the other methods are to be handled by the 
previously installed backend. Kinda like an inheritance-type thing. Is there a 
way to do this?

  Is there a better approach to the whole problem?

  My code so far:

USING: kernel namespaces
formatting prettyprint
checksums checksums.sha
io.backend io.files io.directories io.encodings.binary ;

IN: batch

SINGLETON: batch-io-backend

: with-batch-io-backend ( quot -- )
[ batch-io-backend io-backend ] dip with-variable ; inline

M: batch-io-backend delete-file ( path -- )
"TODO: batch delete file (%s)" sprintf . ;

M: batch-io-backend copy-file ( from to -- )
2dup "batch copy file (%s -> %s)" sprintf .
drop binary [
sha-256 initialize-checksum-state
"hello" add-checksum-bytes
get-checksum .
] with-file-reader ;

M: batch-io-backend move-file ( from to -- )
"TODO: batch move file (%s -> %s)" sprintf . ;


IN: scratchpad [ "README.md" "dst" copy-file ] with-batch-io-backend

---=---
 Александр

--
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk