{"data":{"markdownRemark":{"html":"<p>You have the possibility to apply certain modifications on an Agent before the beginning of a phase or after its end .</p>\n<p>The <code class=\"language-text\">SystemMessage</code> is a new subtype of Message processed before the beginning of the Actions. You can use them to apply changes before the phase even begins.</p>\n<p>The new method <code class=\"language-text\">deferTask(Consumer&lt; Vertex&lt; ? extends Serializable&gt;&gt;)</code> postpones the application of a modification after the end of the phase.</p>\n<h2 id=\"defertask\"><a href=\"#defertask\" 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>deferTask</h2>\n<p>The method <code class=\"language-text\">deferTask</code> is a member of the interface <code class=\"language-text\">Environment</code>, see its declaration below.</p>\n<h5 class=\"ui top attached header\">Declaration of <i>deferTask()</i> in <i>Environment</i> (Java)</h5>\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\">interface</span> <span class=\"token class-name\">Environment</span><span class=\"token operator\">&lt;</span>S <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Serializable</span><span class=\"token operator\">></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><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n\n\t<span class=\"token keyword\">void</span> <span class=\"token function\">deferTask</span><span class=\"token punctuation\">(</span>Consumer<span class=\"token operator\">&lt;</span>Vertex<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>S<span class=\"token punctuation\">></span></span><span class=\"token operator\">></span> dataInjector<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>You can call this method from an <code class=\"language-text\">Agent</code>, and use a lambda as argument.\nThe lambda will be processed right after the Actions, at the end of the phase.</p>\n<h5 class=\"ui top attached header\">Example of use of <i>deferTask()</i> (Java)</h5>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token function\">deferTask</span><span class=\"token punctuation\">(</span>vertex <span class=\"token operator\">-</span><span class=\"token operator\">></span> vertex<span class=\"token punctuation\">.</span><span class=\"token function\">getLinks</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This will remove a <code class=\"language-text\">Link</code> of the <code class=\"language-text\">Vertex</code> at the end of the phase, but the <code class=\"language-text\">Link</code> would still exist and would still be available during this phase.</p>\n<h2 id=\"systemmessage\"><a href=\"#systemmessage\" 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>SystemMessage</h2>\n<p><code class=\"language-text\">SystemMessage</code> is a Java Interface. It is used to define Messages that are processed automatically right at the beginning of the phase, before the Actions.</p>\n<h5 class=\"ui top attached header\">The SystemMessage Interface (Java)</h5>\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\">interface</span> <span class=\"token class-name\">SystemMessage</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">boolean</span> <span class=\"token function\">receivedByVertex</span><span class=\"token punctuation\">(</span>Agent<span class=\"token operator\">&lt;</span><span class=\"token operator\">?</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">GlobalState</span><span class=\"token operator\">></span> agent<span class=\"token punctuation\">,</span> Environment<span class=\"token operator\">&lt;</span><span class=\"token operator\">?</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">GlobalState</span><span class=\"token operator\">></span> env<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The only method you must implement is <code class=\"language-text\">receivedByVertex</code>. This method will be called by the <code class=\"language-text\">Agent</code> receiving the message.\nYou must describe the modification you want to apply on the Agent receiving the message in this method (note that the argument <code class=\"language-text\">agent</code> represents the Agent receiving the message).</p>\n<p>The method returns a boolean deciding whether or not the Agent will handle its Actions.\nIf an Agent receives a SystemMessage with a <code class=\"language-text\">receivedByVertex</code> returning false, then its Actions will not be processed for this phase.\nIf you do not wish to prevent the execution of the Actions, return <code class=\"language-text\">true</code> for all your receivedByVertex methods.\nNote that you only need one <code class=\"language-text\">receivedByVertex</code> returning <code class=\"language-text\">false</code> to prevent the Actions being processed, even if all the other <code class=\"language-text\">receivedByVertex</code> methods called by the Agent return <code class=\"language-text\">true</code>.</p>\n<div class=\"ui segment warningmessage\">\n<h5>SystemMessages are used for lot of purposes</h5>\nBe careful when using a SystemMessage , as some other functionalities are using this method.\nFor instance, the PoisonPill feature is using SystemMessage.\nYou should therefore be careful if you try to access data with a SystemMessage. Agents may be in an 'intermediate' state and not ready yet for Actions.\n</div>\n<h5 class=\"ui top attached header\">Example of custom SystemMessage (Java)</h5>\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\">static</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">MyMessage</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Message</span> <span class=\"token keyword\">implements</span> <span class=\"token class-name\">SystemMessage</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">int</span> field1<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">int</span> field2<span class=\"token punctuation\">;</span>\n\n    <span class=\"token annotation punctuation\">@Override</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">boolean</span> <span class=\"token function\">receivedByVertex</span><span class=\"token punctuation\">(</span>Agent<span class=\"token operator\">&lt;</span><span class=\"token operator\">?</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">GlobalState</span><span class=\"token operator\">></span> agent<span class=\"token punctuation\">,</span> Environment<span class=\"token operator\">&lt;</span><span class=\"token operator\">?</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">GlobalState</span><span class=\"token operator\">></span> env<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"ui segment warningmessage\">\n<h5>SystemMessages cannot begin a phase</h5>\nA SystemMessage will not be put into the Agent's inbox. This allows you to send 'invisible' messages to an Agent, as the Agent will not react to it.\nFor instance, you could send a SystemMessage to an `Agent` to update one of its fields, and do so without triggering a phase for this `Agent` (because his inbox would still be empty).\n</div>","headings":[{"value":"deferTask","depth":2},{"value":"SystemMessage","depth":2}],"frontmatter":{"title":"System Messaging","toc":null,"experimental":true}},"site":{"siteMetadata":{"title":"Simudyne Docs","latestVersion":"2.6"}}},"pageContext":{"absolutePath":"/home/vsts/work/1/s/content/2.5/reference/experimental/system_messaging.md","versioned":true,"version":"2.5","kind":"reference","pagePath":"/reference/experimental/system_messaging","chronology":{"prev":{"name":"Model Scaffolding","path":"/reference/experimental/scaffolding"},"next":{"name":"SDK with Jupyter Notebook","path":"/reference/experimental/jupyter_notebook"}},"lastUpdated":"2026-04-21T13:56:54.861Z"}}