Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

The Agent is a special-purpose thread-safe non-blocking implementation inspired by Agents in Clojure.

Introduction

Agents safe-guard mutable values by allowing only a single agent-managed thread to make modifications to them. The mutable values are not directly accessible from outside, but instead requests have to be sent to the agent and the agent guarantees to process the requests sequentially on behalf of the callers. Agents guarantee sequential execution of all requests and so consistency of the values.

Agents are asynchronous active objects that accept code (functions) as messages. After reception the function is run against the internal state of the Agent and the return value of the function is considered to be the new internal state of the Agent.

Schematically:

To wrap integers, we can certainly use AtomicXXX types of the Java platform. When the state or the update algorithms become more complex we need more support.

Examples

For latest update, see the Agent section of the User Guide and the respective Demos.

  • No labels