{"data":{"markdownRemark":{"html":"<h2 id=\"messaging-semantics\"><a href=\"#messaging-semantics\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Messaging Semantics</h2>\n<p>The <em>Simudyne SDK</em> adopts the <a href=\"%22https://dl.acm.org/citation.cfm?id=1582723%22\">Pregel</a> approach to graph processing. This means that all computation is driven by messages. At every <code class=\"language-text\">action</code> in the <code class=\"language-text\">sequence</code>, every agent will process its action <strong>only if it has received a message</strong>.</p>\n<p>In addition to this, Pregel adopts a pure message passing model that eliminates the need of shared memory and remote read, so all sharing of information between agents is done by message passing.</p>\n<h2 id=\"message-types\"><a href=\"#message-types\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Message Types</h2>\n<p>All messages sent must extend Message. There are a number of ways in which you may do so, each suitable for different scenarios.</p>\n<h3 id=\"empty-messages\"><a href=\"#empty-messages\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Empty Messages</h3>\n<p>For messages that have no value one can extend <code class=\"language-text\">Message.Empty</code>. This is useful if your message type alone is sufficient to convey the required semantics.</p>\n<h3 id=\"single-primitive-type-messages\"><a href=\"#single-primitive-type-messages\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Single Primitive Type Messages</h3>\n<p>For messages that contain only a single primitive value, the Simudyne SDK provides <code class=\"language-text\">Integer</code>, <code class=\"language-text\">Long</code>, <code class=\"language-text\">Float</code>, <code class=\"language-text\">Double</code>, and <code class=\"language-text\">Boolean</code> message classes that can be extended. They all provide a <code class=\"language-text\">getBody()</code> method that returns the primitive value. Use this whenever you need to send only one field.</p>\n<h3 id=\"complex-data-types\"><a href=\"#complex-data-types\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Complex Data Types</h3>\n<p>For messages that require sending complex data types extend <code class=\"language-text\">Message.Object&lt;T&gt;</code>. This will allow you to send a message who's body is the object. It also allows the receiver access to methods on the object.</p>\n<h3 id=\"messages-with-arbitrary-fields\"><a href=\"#messages-with-arbitrary-fields\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Messages with Arbitrary Fields</h3>\n<p>If your message needs to send an arbitrary amount of data, but no explicit type exists, consider extending Message.</p>\n<p>For organising custom message classes, see Message Organisation.</p>\n<div class=\"ui warning message\">\nWhen running the model in distributed mode, all message types need to be registered with the model. This isn't necessary if running the model locally.\n</div>\n<p>Registering messages</p>\n<p class=\"code-header\">(Java)</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">MyClass</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">AgentBasedModel</span><span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>GlobalState<span class=\"token punctuation\">></span></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n  <span class=\"token function\">registerMessageTypes</span><span class=\"token punctuation\">(</span>Boolean<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> Messages<span class=\"token punctuation\">.</span>Vacancy<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"advanced-message-manipulation\"><a href=\"#advanced-message-manipulation\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Advanced Message Manipulation</h2>\n<p>There are other lower level ways of manipulating messages and action sequencing - please refer to <a href=\":version/reference/experimental/system_messaging\">System Messages</a></p>","headings":[{"value":"Messaging Semantics","depth":2},{"value":"Message Types","depth":2},{"value":"Empty Messages","depth":3},{"value":"Single Primitive Type Messages","depth":3},{"value":"Complex Data Types","depth":3},{"value":"Messages with Arbitrary Fields","depth":3},{"value":"Advanced Message Manipulation","depth":2}],"frontmatter":{"title":"Messaging","toc":null,"experimental":null}},"site":{"siteMetadata":{"title":"Simudyne Docs","latestVersion":"2.6"}}},"pageContext":{"absolutePath":"/home/vsts/work/1/s/content/2.6/reference/modelling/messaging.md","versioned":false,"version":"2.6","kind":"reference","pagePath":"/reference/modelling/messaging","chronology":{"prev":{"name":"Actions & Sequencing","path":"/reference/modelling/actions"},"next":{"name":"Random Number Generation","path":"/reference/modelling/prng"}},"lastUpdated":"2026-04-21T13:56:54.869Z"}}