Class CanvasApp

java.lang.Object
pt.unl.fct.di.novasys.babel.core.GenericProtocol
protocols.apps.canvas.CanvasApp

public class CanvasApp extends pt.unl.fct.di.novasys.babel.core.GenericProtocol
The collaborative-canvas application — the top of the stack, and the only protocol a user (or experiment) drives directly. It ties the overlay layers together:
  • Paint operations go out as a BroadcastRequest to the eager-push gossip protocol and come back — to everyone, including us — as BroadcastDelivery notifications. Both are the shared babel-protocols-common dissemination types. Each op is applied to a PixelCanvas under last-writer-wins, so all nodes converge.
  • Snapshot sync (CanvasSyncMessage) is point-to-point over HyParView's channel: on joining, a node asks one neighbour for the current canvas so it sees existing art immediately rather than waiting for new gossip.
  • Presence — this node's HyParView active view — is tracked from NeighborUp/NeighborDown and surfaced in the web UI.

Two faces: interactive and headless

With canvas.ui.enabled (default) an embedded WebUi lets a human paint and watch the canvas + neighbours. With canvas.workload.enabled the node instead paints random cells at a fixed rate from a Babel timer — no UI, no human — which is how babel-canvas-experiments drives load. Both faces funnel through doPaint(int, int, int); structured Telemetry is emitted either way.

Threading note

The web server runs on its own threads; paintFromUi(int, int, int) and stateJson() are called from there. paintFromUi only calls sendRequest (which enqueues onto Babel's event loop) and the thread-safe Telemetry; it never touches the canvas directly — the op is applied when it is delivered back through uponDeliver(pt.unl.fct.di.novasys.babel.protocols.dissemination.notifications.BroadcastDelivery, short) on the event loop. stateJson reads the PixelCanvas (synchronized) and the neighbours set (a CopyOnWriteArraySet). All other state is event-loop-only.
  • Nested Class Summary

    Nested classes/interfaces inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    pt.unl.fct.di.novasys.babel.core.GenericProtocol.ProtocolMetricsBabelMetrics
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default for PAR_DIGEST_INTERVAL: "5000" ms.
    static final String
    Default canvas height: "48".
    static final String
    Default for PAR_SNAPSHOT_SYNC: "true".
    static final String
    Default for PAR_UI_ENABLED: "true".
    static final String
    Default for PAR_UI_OPEN: "true".
    static final int
    Offset added to the bind port to derive the default UI port.
    static final String
    Default canvas width: "48".
    static final String
    Default for PAR_WORKLOAD_CONTROL_FILE: "" (empty → legacy timer mode).
    static final String
    Default for PAR_WORKLOAD_CONTROL_POLL_MS: "250" ms.
    static final String
    Default for PAR_WORKLOAD_DURATION: "0" ms.
    static final String
    Default for PAR_WORKLOAD_ENABLED: "false".
    static final String
    Default for PAR_WORKLOAD_RATE: "2" ops/s.
    static final String
    Default for PAR_WORKLOAD_START_DELAY: "5000" ms.
    static final String
    Property key — period (ms) between convergence-digest telemetry lines; <= 0 disables.
    static final String
    Property key — shared grid height in cells.
    static final String
    Property key — request a canvas snapshot from a neighbour on join.
    static final String
    Property key — enable the embedded web UI.
    static final String
    Property key — open the system browser at the UI on startup (best-effort).
    static final String
    Property key — web UI port.
    static final String
    Property key — shared grid width in cells.
    static final String
    Property key — shared control file (RUN/STOP) the experiment script drives; empty = legacy timer mode.
    static final String
    Property key — how often (ms) to poll the control file in coordinated mode.
    static final String
    Property key — how long (ms) to keep painting; <= 0 = until stopped.
    static final String
    Property key — enable the headless random-paint workload driver.
    static final String
    Property key — workload paint operations per second.
    static final String
    Property key — delay (ms) before the first workload paint, to let the overlay form.
    static final short
     
    static final String
     

    Fields inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    babel, babelSecurity
  • Constructor Summary

    Constructors
    Constructor
    Description
    CanvasApp(Properties props, pt.unl.fct.di.novasys.network.data.Host myself, short broadcastProtoId, short membershipProtoId)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    void
     
    boolean
     
    void
    paintFromUi(int x, int y, int rgb)
    Paint a cell from the web UI.
    A JSON snapshot of canvas + neighbours for the web UI's polling loop.

    Methods inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    addSecret, addSecret, addSecret, addSecret, cancelTimer, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, createChannel, createSecureChannel, createSecureChannel, createSecureChannel, createSecureChannelWithAliases, createSecureChannelWithAliases, createSecureChannelWithIdentities, createSecureChannelWithIdentities, createSecureChannelWithProtoIdentities, enableGenericMetrics, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateSecret, generateSecret, generateSecret, generateSecret, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, getChannelOrThrow, getDefaultChannel, getDefaultProtoIdentity, getDefaultProtoIdentityCrypt, getDefaultProtoSecret, getMillisSinceBabelStart, getOrGenerateDefaultProtoIdentity, getProtoId, getProtoName, hasProtocolThreadStarted, openConnection, openConnection, openConnection, openConnection, registerChannelEventHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageSerializer, registerMetric, registerReplyHandler, registerRequestHandler, registerSharedChannel, registerTimerHandler, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendReply, sendRequest, setDefaultChannel, setDefaultProtoIdentity, setDefaultProtoIdentity, setDefaultProtoSecret, setupPeriodicTimer, setupTimer, startEventThread, subscribeNotification, triggerNotification, unsubscribeNotification

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • CanvasApp

      public CanvasApp(Properties props, pt.unl.fct.di.novasys.network.data.Host myself, short broadcastProtoId, short membershipProtoId) throws pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException, IOException
      Parameters:
      props - protocol configuration; see the PAR_* constants
      myself - this node's membership-space Host (HyParView's bind endpoint)
      broadcastProtoId - the eager-push gossip protocol id (paint ops are sent there)
      membershipProtoId - the HyParView protocol id (its channel is reused for snapshot sync)
      Throws:
      pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException
      IOException
  • Method Details

    • init

      public void init(Properties props)
      Specified by:
      init in class pt.unl.fct.di.novasys.babel.core.GenericProtocol
    • paintFromUi

      public void paintFromUi(int x, int y, int rgb)
      Paint a cell from the web UI. rgb is a 24-bit colour (0xRRGGBB); we force it opaque. Safe to call from the web-server thread (see the class threading note).
    • stateJson

      public String stateJson()
      A JSON snapshot of canvas + neighbours for the web UI's polling loop.
    • getUiPort

      public int getUiPort()
    • isUiEnabled

      public boolean isUiEnabled()