Université de Moncton
Département d'Informatique
Moncton, N.B. Canada E1A 3E9,
tarau@info.umoncton.ca
- Logic and Functional Programming Group
Department of Computing Sciences
Simon Fraser University
Burnaby, B.C. Canada V5A 1S6
veronica@cs.sfu.ca
- Vakgroep Elektronica en Informatiesystemen,
Universiteit Gent
St.-Pietersnieuwstraat 41
B-9000 Gent, Belgium
kdb@elis.rug.ac.be

Remote Execution, Mobile Code and Agents in BinProlog

Paul Tarau1, Veronica Dahl2 and Koen De Bosschere3

Extended version

Abstract:

We describe a set of programming patterns used for implementing remote execution mechanisms, mobile code and agents in a distributed logic programming framework. Some advanced logic programming constructs as intuitionistic implication, high-order call/N cooperate with encapsulated socket-level constructs for maximum configurability and efficiency. Our implementation is part of the BinProlog system ( http://clement.info.umoncton.ca/BinProlog ) as well as with its Java peers built on top of our unification enhanced Java based Linda system ( http://clement.info.umoncton.ca/LindaInteractor ).

Keywords: mobile code, remote execution, metaprogramming, agents, Linda coordination, blackboard-based logic programming, distributed programming in Prolog

Introduction

Although the Internet has been designed to survive nuclear war and its underlying packet switching technology is intrinsically peer-to-peer, fault-tolerant and scalable, successive higher level networking and programming layers have given away (often too easily) these abilities. Among the most annoying and at the same time the most pragmatically well thought decisions dominating the world of the Internet, at various programming and application development layers:

We will show how some standard and some non-standard Logic Programming language tools will be used to elegantly get back the full potential of the Internet for building scalable, peer-to-peer, programmable multi-user communities. The virtual layer we will build is based on a small set of very-high level programming constructs making essential use of meta-programming, which is seen here as the ability to view information either as code or as data, and efficiently switch between these views, on demand. In particular, we will show how powerful remote execution mechanisms, agents and mobile code can be expressed in this framework.

Unification enhanced Linda: a high-level distributed event processor

Linda [4] based frameworks like Multi-BinProlog [5] offer a wide variety of blocking and non-blocking as well as non-deterministic blackboard operations (backtracking through alternative answers).

For reasons of embeddability in multi-paradigm environments and semantic simplicity we have decided to drop non-determinism and return to a subset close to the original Linda operators, while keeping unification as the associative search mechanism.

out(X): puts X on the server
in(X):  waits until it can take an object matching X from the server
all(X,Xs): reads the list Xs matching X currently on the server
run(Goal): starts a thread executing Goal

Note the fundamental link between `event-processing' and the more general Linda protocol: basically an out/1 operation can be seen as generating an event and adding it to the event queue while an in/1 operation can be seen as servicing an event. While usually event-loops switch on numeric event constants in a rather rigid and non-compositional way, Linda-based event dispatching is extensible by adding new patterns. Linda's out/blocking in combination can be seen as automating the complex if-then-else logic of (distributed) hierarchical message dispatching loops through unification.

Metaphorically speaking, using associative search based communication gives to programs something close to what net search tools like Alta Vista give to humans.

Towards a Web of Worlds

The MOOgif inspired `Web of Worlds' metaphor [13] as a set of Linda blackboards storing state information on servers connected over the the Internet allows a simple and secure remote execution mechanism through specialized server-side interpreters.

Servers as specialized interpreters

The code for our `generic' server, with various components which are overridden through the use of intuitionistic implication to obtain customized special purpose servers at user level, follows. Higher order call/N combined to intuitionistic assumptions are used to pass arbitrary interactors to this generic server code.

run_server(Port):-
  new_server(Port,NewServer),
  register_server(Port),
    server(NewServer)=>>server_loop(NewServer),
  close_socket(NewServer).

server_loop(Server,Fuel):-
  repeat,
    interact(Server),   
  assumed(server_done(_)),
  !.

interact(Server):-
  default_server_action(Interactor),
  call(Interactor,Server), % higher-order call to interactor
  !.

Note the use of a specialized server-side interpreter server_loop, configurable through the use of higher-order `question/answer' closures we have called interactors.

Intuitionistic implication (pioneered by Miller's work [9]) is used to override the generic server's interactor, i.e., the inner server operation filtering allowed requests, while allowing reuse of most of the generic server's code in an object oriented programming style. BinProlog's =>> temporarily assumes a clause in `asserta' order, i.e., at the beginning of the predicate. The assumption is scoped to be only usable to prove its right side goal and vanishes on backtracking. We refer to [10, 11] for more information on assumptions and their applications.

Security is achieved by having specialized interpreters `filtering' requests on the server side. The code of a chat server built on top of this mechanism, for instance, looks as follows:

chat_server_interactor(mes(From,Cs),Answer):-show_mes(From,Cs,Answer).
chat_server_interactor(ping(T),R):-term_server_interactor(ping(T),R).

chat_server:-
  server_interactor(chat_server_interactor)=>>
  run_server.

By overriding the default server_interactor with our chat_server_interactor we tell to chat_server that only commands matching known, secure operations (i.e. mes/2 and ping/1) can be performed on behalf of remote users.

Mobile Code

Implementation of arbitrary remote execution is easy in a Linda + Prolog through metaprogramming. No complex serialization or remote procedure/method call packages are needed.

Remote code fetching

The following operations

host(Other_machine)=>>rload(File).
host(Other_machine)=>>code(File)=>>TopGoal.

allow fetching remote files or on-demand fetching of a-predicate-at-a-time from a remote host during execution of TopGoal. This is basically the same mechanism as the one implemented for Java applet code fetching, except that we have also implemented a caching mechanism, both at predicate level (predicates are cached as dynamic code on the server to efficiently serve multiple clients) and at file level, on the client side.

Dynamic recompilation

Dynamic recompilation is used on the client side to speed-up heavily used relatively non-volatile predicates. With dynamically recompiled consulted code, the source code of the predicates and dynamic modification to any predicate are still available while average performance stays close to statically compiled code (usually within a factor of 2-3). Although when code comes over the network, code fetching time becomes more significant, the combination of remote code fetching and dynamic recompilation is a powerful accelerator for distributed network applications comparable with Java's just-in-time (JIT) compilation technology.

(Virtual) Mobile Agents

Implementing agents `roaming over' a set of servers is a simple and efficient high-level operation. First, we get the list of servers from the master server. Then we iterate through the appropriate remote-call negotiation with each site. Our agent's behavior is constrained through security and resource limitations of participating interpreters, having their own command filtering policies.

For instance, on a chat-only server, our roaming agent can only display a message. If the local interpreter allows gathering user information then our agent can collect it. If the local interpreter allows question/answering our agent will actually interact with the human user through the local server window.

Note that `mobile agents' do not have to be implemented as code physically moved from one site to another. In this sense we can talk about virtual mobile agents which are actually sets of synchronized remote predicate calls originating from a unique site, where most of the code is based/executed, while code actually moved can be kept to strict minimum, i.e. only a few remotely asserted clausesgif.

Our mobile agents are seen as `connection brokers' between participating independent server/client sites. For instance if two sites are willing to have a private conversation or code exchange they can do so by simply using the server/port/password information our agent can help them to exchange.

Related work

A very large number of research projects have recently started on mobile agent programming. Among the pioneers, Kahn and Cerf's Knowbots [7] Among the most promising recent developments Luca Cardelli's Oblique project at Digital and mobile agent applications [1] and IBM Japan's aglets [6]. We share their emphasis on going beyond code mobility as present in Java, for instance, towards control mobility. A growing number of sophisticated Web-based applications and tools are on the way to be implemented in LP/CLP languages. Among them, work with a similar emphasis on remote execution, agents, virtual worlds can be found in [3, 2, 8, 13].

Conclusion and future work

Our remote execution mechanisms are based on a set of filtering interpreters which can be customized to support arbitrary negotiations with remote agents and are plugged in generic servers. The practical implementation is built on proven client/server technology, on top of a generic socket package, while giving the illusion of a `Web of MOOs' with roaming mobile agents at the next level of abstraction.

A Java based Linda implementation, using a minimal set of logic programming components (unification, associative search) has been recently released (the Java TermServer, available at http://clement.info.umoncton.ca/BinProlog ). It allows to communicate bidirectionally with BinProlog, allowing the creation of combined Java/Prolog mobile-agent programs. In particular, Java applets can be used as front end in browsers instead of the more resource consuming CGIs.

Future work will focus on intelligent mobile agents integrating knowledge and controlled natural language processing abilities.

Acknowledgement

We thank for support from NSERC (grants OGP0107411 and 611024), and from the FESR of the Université de Moncton. Koen De Bosschere is research associate with the Fund for Scientific Research - Flanders.

References

1
K. A. Bharat and L. Cardelli. Migratory applications. In Proceedings of the 8th Annual ACM Symposium on User Interface Software and Technology, Nov. 1995.

see https://digital.com/about/dec/

2
P. Bonnet, L. Bressnan S., Leth, and B. Thomsen. Towards ECLIPSE Agents on the Internet. In Tarau et al. [12]. http://clement.info.umoncton.ca/lpnet.

3
D. Cabeza and M. Hermenegildo. The Pillow/CIAO Library for Internet/WWW Programming using Computational Logic Systems. In Tarau et al. [12]. http://clement.info.umoncton.ca/lpnet.

4
N. Carriero and D. Gelernter. Linda in context. CACM, 32(4):444-458, 1989.

5
K. De Bosschere and P. Tarau. Blackboard-based Extensions in Prolog. Software -- Practice and Experience, 26(1):49-69, Jan. 1996.

6
IBM. Aglets. . http://www.trl.ibm.co.jp/aglets.

7
R. E. Kahn and V. G. Cerf. The digital library project, volume i: The world of knowbots. 1988. Unpublished manuscript, Corporation for National Research Initiatives, Reston, Va., Mar.

8
S. W. Locke, A. Davison, and S. L. Lightweight Deductive Databases for the World-Wide Web. In Tarau et al. [12]. http://clement.info.umoncton.ca/ lpnet.

9
D. Miller. A logical analysis of modules in logic programming. Journal of Logic Programming, 6(1 and 2):79-108, January/March 1989.

10
P. Tarau. BinProlog 5.40 User Guide. Technical Report 97-1, Département d'Informatique, Université de Moncton, Apr. 1997. Available from http://clement.info.umoncton.ca/BinProlog.

11
P. Tarau, V. Dahl, and A. Fall. Backtrackable State with Linear Affine Implication and Assumption Grammars. In J. Jaffar and R. H. Yap, editors, Concurrency and Parallelism, Programming, Networking, and Security, Lecture Notes in Computer Science 1179, pages 53-64, Singapore, Dec. 1996. Springer.

12
P. Tarau, A. Davison, K. De Bosschere, and M. Hermenegildo, editors. Proceedings of the 1st Workshop on Logic Programming Tools for INTERNET Applications, JICSLP'96, Bonn, Sept. 1996. http://clement.info.umoncton.ca/ lpnet.

13
P. Tarau and K. De Bosschere. Virtual World Brokerage with BinProlog and Netscape. In Tarau et al. [12]. http://clement.info.umoncton.ca/ lpnet.

...MOO
Multi User Domains (MUDs), Object Oriented - venerable but still well doing ancestors of more recent multi-user Virtual Worlds, which are usually 3D-animation (VRML) based
...clauses
Note however that suspending execution at one site, and then restarting it at another site can be done quite efficiently in BinProlog, where continuations are first order objects which can be put into a term to be sent over a socket, then read in and executed.
 


Paul Tarau
Mon Mar 17 08:06:15 AST 1997