Fork me on GitHub

Looks like some of the java.nio classes and interfaces are missing, or did I miss something:

❯ bb
Babashka v1.3.190 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> java.nio.channels.ByteChannel
Could not resolve symbol: java.nio.channels.ByteChannel [at <repl>:2:-29]


Same in clj:

❯ clj
Clojure 1.12.0-alpha12
user=> java.nio.channels.ByteChannel


It's strange, as the java.nio.channels.SocketChannel is available, and it implements the ByteChannel(which is missing)


Also, the utility class java.nio.channels.Channels is not available


> Same in clj Perhaps you're using a very old Java version?


ByteChannel isn't yet included in bb, but I could add it. Can you make a minimum viable snippet that demonstrates how you would like to use it, so I can add a test for it?


I understand that improving the proxy support in bb you help many users, but for my use-case adding support for java.nio.channels.Channels, and maybe even ByteChannel too, would be ideal


yes, all of the above, but they are separate issues. I'll have a look at this hopefully soon

👍 1

I've made an issue here: If you want to help speed up things, you can help trying to make a test case which can be run as a standalone without docker. I have a similar test, which is linked in the issue.

👍 1

With that test in place, I can fix the rest relatively quickly


I'll take a look today


@U0GE2JPNC This example code looks interesting. I've been making a sort of Clojure adaptation of Python Pexpect library "replwrap" using pty4java library for controlling some interactive shell processes over SSH, eg. PHP repls (`php -a` or wp shell). New to stream IO processing and had bit of problems getting similar end of file indication (-1) from the PtyProcess output stream, having to continuously scan for the certain newline and prompt character sequences to recognize when it's ready for new input and often ending up with the process hanging on SSH welcome messages, random notices and having to manually empty it character by character etc.. Anyways, I think I might be able to improve my code based on these examples and maybe reason about it better next time.


Interesting @U06C3BLAH98. This reminds me of a project I worked in many many moons ago. We had a software that was managing various network equipments over RS232 serial connection. The devices expected to have a human on terminal, so for example when they we instructed to list interfaces, they might stop the listing and print "---MORE? (y/n)--", and expect to get "y" to continue. I ended up implementing finite state machine, where each state represented one expected state the device terminal was. Each state had a set of strings for expected device output that was then mapped to next state.


I parse the expected strings into a tree, so that for each input I checked what strings match so far, dropped the ones that did not match, and continues until one of the strings matched.


I also has a "super" states in the FSM, so for example I had just one super state that matched input -1 that transitioned the machine to state "EOF"


btw @U0GE2JPNC if you need a working bb for the above use case for other architectures you can use this install method:

bash <(curl ) --dev-build --dir /tmp
it installs the development version of bb in the /tmp directory

👍 1

Sounds pretty complicated, but it was actually quite easy abstraction to do and test. And it was super flexible, when ever we learned a new things from devices it was really easy to add the expected string to state transfer,


This was years ago and I implemented it with Java


@U04V15CAJ I'll keep an eye on bb releases and update installs to use released version once this hits a release. Again, huge thank you for this, I'm really glad I can continue my experiments with bb


I guess main issue was that for whatever reason the Pty4java's process output stream does not return -1 to indicate end of stream, but hangs instead. With that, had to always match the repl prompt characters in latest read output bytes and stop before calling (.read in-s) again which would hang the program. Maybe there could be a timeout added somehow that would fallback to giving -1.. @U0GE2JPNC FSM might help at some situations so will keep that in mind, thank's. I also received your DM so we can talk about it further in a bit.. Example usage of wrapper I built with it so far:

(testing "wp api function returning string"
    (is (= (php-eval "get_category_link(1)")
           "=> string(45) \"\"")))

(testing "basic arithmetics return int"
    (is (= (php-eval "3 + 3;") 6)))

(testing "multiple evaluation with variable"
    (is (= (do (php-eval "$a = 5;")
               (php-eval "$a * 3;")) 15)))


I've been also looking at the Pods protocol and wondering if it could provide a neater solution for "WordPress batch processing", so that I could get data from the DB, analyse in Clojure and submit results back nicely. Using PHP scripts for now with wp eval exporting/importing data with intermediary CSV files. Enjoyed interfacing with the DB with SQL directly, but many queries have to go through the PHP "ORM layer" or WP Crud API as it is called.


New bb is released @U0GE2JPNC