Package titan.network
Class TitanProtocol
java.lang.Object
titan.network.TitanProtocol
TitanProtocol defines the communication protocol for the Titan network.
It specifies the structure of messages, including header information (version, opcode, flags, length)
and the payload, for various operations within the Titan ecosystem.
This class provides static utility methods for sending and receiving protocol-compliant messages.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a parsed Titan Protocol packet, containing its operation code and payload. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byteThe current version of the Titan Protocol.static final byteResponse OpCode indicating a successful operation (acknowledgment).static final byteOpCode for clearing or resetting collected statistics.static final byteResponse OpCode for sending generic data or a string response.static final byteOpCode for deploying an application or service artifact.static final byteResponse OpCode indicating a failure or error during an operation.static final byteOpCode for fetching an asset from the system.static final byteOpCode for requesting the current status of a specific job.static final byteOpCode for requesting historical logs for a specific job or service.static final byteOpCode for a heartbeat message.static final byteOpCode indicating that a job has completed its execution.static final byteOpCode for forcefully terminating a worker process.static final byteOpCode for retrieving the value associated with a key from a distributed key-value store.static final byteOpCode for adding a member to a set associated with a key in a distributed key-value store.static final byteOpCode for setting a key-value pair in a distributed key-value store.static final byteOpCode for retrieving all members of a set associated with a key from a distributed key-value store.static final byteOpCode for sending a batch of log entries.static final byteOpCode for initiating a stream of logs from a running process or service.static final byteOpCode for registering a service or worker with the orchestrator.static final byteOpCode for initiating the execution of a deployed application or job.static final byteOpCode for running a job from an archived state or with archived data.static final byteOpCode for staging assets or data required for a job or deployment.static final byteOpCode for starting a specific service.static final byteOpCode for starting a service from an archived state or with archived configurations.static final byteOpCode for requesting general statistics about the system or a specific entity.static final byteOpCode for requesting statistics in JSON format.static final byteOpCode for stopping a running application or job.static final byteOpCode for submitting a Directed Acyclic Graph (DAG) of jobs to the Titan orchestrator.static final byteOpCode for submitting a single job to the Titan orchestrator.static final byteOpCode for unregistering a service or worker from the orchestrator.static final byteOpCode for uploading an asset (e.g., a binary, configuration file) to the system.static final StringString identifier for the 'run archive' job type, typically used within payload data.static final StringString identifier for the 'start archive service' job type, typically used within payload data. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidMain method for demonstrating the Titan Protocol's send and read functionality.static TitanProtocol.TitanPacketread(DataInputStream in) Reads an incoming message from the network, parsing the Titan Protocol header and payload.static voidsend(DataOutputStream out, byte opCode, String payload) Sends a message over the network using the Titan Protocol.
-
Field Details
-
CURRENT_VERSION
private static final byte CURRENT_VERSIONThe current version of the Titan Protocol. This byte is included in the header to ensure compatibility between communicating entities.- See Also:
-
OP_HEARTBEAT
public static final byte OP_HEARTBEATOpCode for a heartbeat message. Used to keep connections alive and signal liveness.- See Also:
-
OP_REGISTER
public static final byte OP_REGISTEROpCode for registering a service or worker with the orchestrator.- See Also:
-
OP_SUBMIT_JOB
public static final byte OP_SUBMIT_JOBOpCode for submitting a single job to the Titan orchestrator.- See Also:
-
OP_SUBMIT_DAG
public static final byte OP_SUBMIT_DAGOpCode for submitting a Directed Acyclic Graph (DAG) of jobs to the Titan orchestrator.- See Also:
-
OP_DEPLOY
public static final byte OP_DEPLOYOpCode for deploying an application or service artifact.- See Also:
-
OP_RUN
public static final byte OP_RUNOpCode for initiating the execution of a deployed application or job.- See Also:
-
OP_STOP
public static final byte OP_STOPOpCode for stopping a running application or job.- See Also:
-
OP_STATS
public static final byte OP_STATSOpCode for requesting general statistics about the system or a specific entity.- See Also:
-
OP_STATS_JSON
public static final byte OP_STATS_JSONOpCode for requesting statistics in JSON format.- See Also:
-
OP_UNREGISTER_SERVICE
public static final byte OP_UNREGISTER_SERVICEOpCode for unregistering a service or worker from the orchestrator.- See Also:
-
OP_CLEAN_STATS
public static final byte OP_CLEAN_STATSOpCode for clearing or resetting collected statistics.- See Also:
-
OP_STAGE
public static final byte OP_STAGEOpCode for staging assets or data required for a job or deployment.- See Also:
-
OP_START_SERVICE
public static final byte OP_START_SERVICEOpCode for starting a specific service.- See Also:
-
OP_KILL_WORKER
public static final byte OP_KILL_WORKEROpCode for forcefully terminating a worker process.- See Also:
-
OP_JOB_COMPLETE
public static final byte OP_JOB_COMPLETEOpCode indicating that a job has completed its execution.- See Also:
-
OP_LOG_STREAM
public static final byte OP_LOG_STREAMOpCode for initiating a stream of logs from a running process or service.- See Also:
-
OP_GET_LOGS
public static final byte OP_GET_LOGSOpCode for requesting historical logs for a specific job or service.- See Also:
-
OP_UPLOAD_ASSET
public static final byte OP_UPLOAD_ASSETOpCode for uploading an asset (e.g., a binary, configuration file) to the system.- See Also:
-
OP_FETCH_ASSET
public static final byte OP_FETCH_ASSETOpCode for fetching an asset from the system.- See Also:
-
OP_LOG_BATCH
public static final byte OP_LOG_BATCHOpCode for sending a batch of log entries.- See Also:
-
OP_RUN_ARCHIVE
public static final byte OP_RUN_ARCHIVEOpCode for running a job from an archived state or with archived data.- See Also:
-
OP_START_SERVICE_ARCHIVE
public static final byte OP_START_SERVICE_ARCHIVEOpCode for starting a service from an archived state or with archived configurations.- See Also:
-
RUN_ARCHIVE
String identifier for the 'run archive' job type, typically used within payload data.- See Also:
-
START_ARCHIVE_SERVICE
String identifier for the 'start archive service' job type, typically used within payload data.- See Also:
-
OP_ACK
public static final byte OP_ACKResponse OpCode indicating a successful operation (acknowledgment).- See Also:
-
OP_ERROR
public static final byte OP_ERRORResponse OpCode indicating a failure or error during an operation.- See Also:
-
OP_DATA
public static final byte OP_DATAResponse OpCode for sending generic data or a string response.- See Also:
-
OP_KV_SET
public static final byte OP_KV_SETOpCode for setting a key-value pair in a distributed key-value store.- See Also:
-
OP_KV_GET
public static final byte OP_KV_GETOpCode for retrieving the value associated with a key from a distributed key-value store.- See Also:
-
OP_KV_SADD
public static final byte OP_KV_SADDOpCode for adding a member to a set associated with a key in a distributed key-value store.- See Also:
-
OP_KV_SMEMBERS
public static final byte OP_KV_SMEMBERSOpCode for retrieving all members of a set associated with a key from a distributed key-value store.- See Also:
-
OP_GET_JOB_STATUS
public static final byte OP_GET_JOB_STATUSOpCode for requesting the current status of a specific job.- See Also:
-
-
Constructor Details
-
TitanProtocol
public TitanProtocol()
-
-
Method Details
-
send
Sends a message over the network using the Titan Protocol. The message is wrapped in an 8-byte header consisting of: [ Version(1) | OpCode(1) | Flags(1) | Spare(1) | Length(4) ] followed by the UTF-8 encoded payload.- Parameters:
out- TheDataOutputStreamto write the message to.opCode- The operation code for the message.payload- The string payload of the message.- Throws:
IOException- If an I/O error occurs during writing to the stream.
-
read
Reads an incoming message from the network, parsing the Titan Protocol header and payload. It expects an 8-byte header followed by the payload data.- Parameters:
in- TheDataInputStreamto read the message from.- Returns:
- A
TitanProtocol.TitanPacketobject containing the parsed opcode and payload. - Throws:
Exception- If a version mismatch occurs, the packet is too large, or an I/O error occurs.
-
main
Main method for demonstrating the Titan Protocol's send and read functionality. It simulates sending a heartbeat message with a payload and then reading it back to verify the protocol implementation.- Parameters:
args- Command line arguments (not used).
-