Remote sub invocation

Advanced topics

1. Introduction
2. The predefined subs that do it
3. Scope


1. Introduction
Remote sub invocation allows to call a sub in another aptilis program that runs on the same machine, or on a different machine, on your Intranet or on the Internet.


2. The predefined subs that do it
The subs that allow you to use the remote sub invocation mechanism are:
- TakeCalls()
- Call()
TakeCalls will block the program until it is called by another program.
By default, RSI (Remote Sub Invocation) uses port 1108, but you can change that to any valid port value (1 - 65535) through the second optional parameter of TakeCalls(). However, you need to be superuser on most Unix systems to be allowed to use ports below 1024.


3. Scope
There are plenty of things you can do with that! There is the obvious 'Talk' program listed on the Call() page, but you can also imagine dividing a complex task onto several computers, and then query them through a call to an 'aptilis watchdog' that could tell, for example, if such or such file has been created.
I use it for the word search of my website at http://village.glaine.net/.
I have an aptilis script that has indexed all the words of the site and which then sits idle, waiting for calls.
The script requested by the search page calls the dormant script which returns a list of all the pages where the searched word appears. Because the indexer stays in memory, no disk operation is required for the search so it's quite fast!
For the moment however, calls are replied to sequentially, not asynchronously, in other words, if several calls are sent at the sent time, they will be queued and answered to one after the other. Depending on how people use this feature, I may implement a multi-threaded version of aptilis that could answer several calls at the same time.