Package protocols.apps.canvas
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
BroadcastRequestto the eager-push gossip protocol and come back — to everyone, including us — asBroadcastDeliverynotifications. Both are the sharedbabel-protocols-commondissemination types. Each op is applied to aPixelCanvasunder 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/NeighborDownand surfaced in the web UI.
Two faces: interactive and headless
Withcanvas.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
FieldsModifier and TypeFieldDescriptionstatic final StringDefault forPAR_DIGEST_INTERVAL: "5000" ms.static final StringDefault canvas height: "48".static final StringDefault forPAR_SNAPSHOT_SYNC: "true".static final StringDefault forPAR_UI_ENABLED: "true".static final StringDefault forPAR_UI_OPEN: "true".static final intOffset added to the bind port to derive the default UI port.static final StringDefault canvas width: "48".static final StringDefault forPAR_WORKLOAD_CONTROL_FILE: "" (empty → legacy timer mode).static final StringDefault forPAR_WORKLOAD_CONTROL_POLL_MS: "250" ms.static final StringDefault forPAR_WORKLOAD_DURATION: "0" ms.static final StringDefault forPAR_WORKLOAD_ENABLED: "false".static final StringDefault forPAR_WORKLOAD_RATE: "2" ops/s.static final StringDefault forPAR_WORKLOAD_START_DELAY: "5000" ms.static final StringProperty key — period (ms) between convergence-digest telemetry lines;<= 0disables.static final StringProperty key — shared grid height in cells.static final StringProperty key — request a canvas snapshot from a neighbour on join.static final StringProperty key — enable the embedded web UI.static final StringProperty key — open the system browser at the UI on startup (best-effort).static final StringProperty key — web UI port.static final StringProperty key — shared grid width in cells.static final StringProperty key — shared control file (RUN/STOP) the experiment script drives; empty = legacy timer mode.static final StringProperty key — how often (ms) to poll the control file in coordinated mode.static final StringProperty key — how long (ms) to keep painting;<= 0= until stopped.static final StringProperty key — enable the headless random-paint workload driver.static final StringProperty key — workload paint operations per second.static final StringProperty key — delay (ms) before the first workload paint, to let the overlay form.static final shortstatic final StringFields inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol
babel, babelSecurity -
Constructor Summary
ConstructorsConstructorDescriptionCanvasApp(Properties props, pt.unl.fct.di.novasys.network.data.Host myself, short broadcastProtoId, short membershipProtoId) -
Method Summary
Modifier and TypeMethodDescriptionintvoidinit(Properties props) booleanvoidpaintFromUi(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
-
Field Details
-
PROTO_ID
public static final short PROTO_ID- See Also:
-
PROTO_NAME
- See Also:
-
PAR_WIDTH
Property key — shared grid width in cells. Must match across all nodes.- See Also:
-
DEFAULT_WIDTH
Default canvas width: "48".- See Also:
-
PAR_HEIGHT
Property key — shared grid height in cells. Must match across all nodes.- See Also:
-
DEFAULT_HEIGHT
Default canvas height: "48".- See Also:
-
PAR_UI_ENABLED
Property key — enable the embedded web UI.- See Also:
-
DEFAULT_UI_ENABLED
Default forPAR_UI_ENABLED: "true".- See Also:
-
PAR_UI_PORT
Property key — web UI port. Defaults tobabel.port + 2000when unset.- See Also:
-
DEFAULT_UI_PORT_OFFSET
public static final int DEFAULT_UI_PORT_OFFSETOffset added to the bind port to derive the default UI port.- See Also:
-
PAR_UI_OPEN
Property key — open the system browser at the UI on startup (best-effort).- See Also:
-
DEFAULT_UI_OPEN
Default forPAR_UI_OPEN: "true".- See Also:
-
PAR_SNAPSHOT_SYNC
Property key — request a canvas snapshot from a neighbour on join.- See Also:
-
DEFAULT_SNAPSHOT_SYNC
Default forPAR_SNAPSHOT_SYNC: "true".- See Also:
-
PAR_DIGEST_INTERVAL
Property key — period (ms) between convergence-digest telemetry lines;<= 0disables.- See Also:
-
DEFAULT_DIGEST_INTERVAL
Default forPAR_DIGEST_INTERVAL: "5000" ms.- See Also:
-
PAR_WORKLOAD_ENABLED
Property key — enable the headless random-paint workload driver.- See Also:
-
DEFAULT_WORKLOAD_ENABLED
Default forPAR_WORKLOAD_ENABLED: "false".- See Also:
-
PAR_WORKLOAD_RATE
Property key — workload paint operations per second.- See Also:
-
DEFAULT_WORKLOAD_RATE
Default forPAR_WORKLOAD_RATE: "2" ops/s.- See Also:
-
PAR_WORKLOAD_DURATION
Property key — how long (ms) to keep painting;<= 0= until stopped.- See Also:
-
DEFAULT_WORKLOAD_DURATION
Default forPAR_WORKLOAD_DURATION: "0" ms.- See Also:
-
PAR_WORKLOAD_START_DELAY
Property key — delay (ms) before the first workload paint, to let the overlay form. Legacy/fallback path only: ignored whenPAR_WORKLOAD_CONTROL_FILEis set (then the orchestrator's RUN/STOP drives start/stop).- See Also:
-
DEFAULT_WORKLOAD_START_DELAY
Default forPAR_WORKLOAD_START_DELAY: "5000" ms.- See Also:
-
PAR_WORKLOAD_CONTROL_FILE
Property key — shared control file (RUN/STOP) the experiment script drives; empty = legacy timer mode.- See Also:
-
DEFAULT_WORKLOAD_CONTROL_FILE
Default forPAR_WORKLOAD_CONTROL_FILE: "" (empty → legacy timer mode).- See Also:
-
PAR_WORKLOAD_CONTROL_POLL_MS
Property key — how often (ms) to poll the control file in coordinated mode.- See Also:
-
DEFAULT_WORKLOAD_CONTROL_POLL_MS
Default forPAR_WORKLOAD_CONTROL_POLL_MS: "250" ms.- See Also:
-
-
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 thePAR_*constantsmyself- this node's membership-spaceHost(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.HandlerRegistrationExceptionIOException
-
-
Method Details
-
init
- Specified by:
initin classpt.unl.fct.di.novasys.babel.core.GenericProtocol
-
paintFromUi
public void paintFromUi(int x, int y, int rgb) Paint a cell from the web UI.rgbis a 24-bit colour (0xRRGGBB); we force it opaque. Safe to call from the web-server thread (see the class threading note). -
stateJson
A JSON snapshot of canvas + neighbours for the web UI's polling loop. -
getUiPort
public int getUiPort() -
isUiEnabled
public boolean isUiEnabled()
-