Package titan.network

Class TitanProtocol

java.lang.Object
titan.network.TitanProtocol

public class TitanProtocol extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Represents a parsed Titan Protocol packet, containing its operation code and payload.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final byte
    The current version of the Titan Protocol.
    static final byte
    Response OpCode indicating a successful operation (acknowledgment).
    static final byte
    OpCode for clearing or resetting collected statistics.
    static final byte
    Response OpCode for sending generic data or a string response.
    static final byte
    OpCode for deploying an application or service artifact.
    static final byte
    Response OpCode indicating a failure or error during an operation.
    static final byte
    OpCode for fetching an asset from the system.
    static final byte
    OpCode for requesting the current status of a specific job.
    static final byte
    OpCode for requesting historical logs for a specific job or service.
    static final byte
    OpCode for a heartbeat message.
    static final byte
    OpCode indicating that a job has completed its execution.
    static final byte
    OpCode for forcefully terminating a worker process.
    static final byte
    OpCode for retrieving the value associated with a key from a distributed key-value store.
    static final byte
    OpCode for adding a member to a set associated with a key in a distributed key-value store.
    static final byte
    OpCode for setting a key-value pair in a distributed key-value store.
    static final byte
    OpCode for retrieving all members of a set associated with a key from a distributed key-value store.
    static final byte
    OpCode for sending a batch of log entries.
    static final byte
    OpCode for initiating a stream of logs from a running process or service.
    static final byte
    OpCode for registering a service or worker with the orchestrator.
    static final byte
    OpCode for initiating the execution of a deployed application or job.
    static final byte
    OpCode for running a job from an archived state or with archived data.
    static final byte
    OpCode for staging assets or data required for a job or deployment.
    static final byte
    OpCode for starting a specific service.
    static final byte
    OpCode for starting a service from an archived state or with archived configurations.
    static final byte
    OpCode for requesting general statistics about the system or a specific entity.
    static final byte
    OpCode for requesting statistics in JSON format.
    static final byte
    OpCode for stopping a running application or job.
    static final byte
    OpCode for submitting a Directed Acyclic Graph (DAG) of jobs to the Titan orchestrator.
    static final byte
    OpCode for submitting a single job to the Titan orchestrator.
    static final byte
    OpCode for unregistering a service or worker from the orchestrator.
    static final byte
    OpCode for uploading an asset (e.g., a binary, configuration file) to the system.
    static final String
    String identifier for the 'run archive' job type, typically used within payload data.
    static final String
    String identifier for the 'start archive service' job type, typically used within payload data.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main(String[] args)
    Main method for demonstrating the Titan Protocol's send and read functionality.
    Reads an incoming message from the network, parsing the Titan Protocol header and payload.
    static void
    send(DataOutputStream out, byte opCode, String payload)
    Sends a message over the network using the Titan Protocol.

    Methods inherited from class java.lang.Object

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

    • CURRENT_VERSION

      private static final byte CURRENT_VERSION
      The 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_HEARTBEAT
      OpCode for a heartbeat message. Used to keep connections alive and signal liveness.
      See Also:
    • OP_REGISTER

      public static final byte OP_REGISTER
      OpCode for registering a service or worker with the orchestrator.
      See Also:
    • OP_SUBMIT_JOB

      public static final byte OP_SUBMIT_JOB
      OpCode for submitting a single job to the Titan orchestrator.
      See Also:
    • OP_SUBMIT_DAG

      public static final byte OP_SUBMIT_DAG
      OpCode for submitting a Directed Acyclic Graph (DAG) of jobs to the Titan orchestrator.
      See Also:
    • OP_DEPLOY

      public static final byte OP_DEPLOY
      OpCode for deploying an application or service artifact.
      See Also:
    • OP_RUN

      public static final byte OP_RUN
      OpCode for initiating the execution of a deployed application or job.
      See Also:
    • OP_STOP

      public static final byte OP_STOP
      OpCode for stopping a running application or job.
      See Also:
    • OP_STATS

      public static final byte OP_STATS
      OpCode for requesting general statistics about the system or a specific entity.
      See Also:
    • OP_STATS_JSON

      public static final byte OP_STATS_JSON
      OpCode for requesting statistics in JSON format.
      See Also:
    • OP_UNREGISTER_SERVICE

      public static final byte OP_UNREGISTER_SERVICE
      OpCode for unregistering a service or worker from the orchestrator.
      See Also:
    • OP_CLEAN_STATS

      public static final byte OP_CLEAN_STATS
      OpCode for clearing or resetting collected statistics.
      See Also:
    • OP_STAGE

      public static final byte OP_STAGE
      OpCode for staging assets or data required for a job or deployment.
      See Also:
    • OP_START_SERVICE

      public static final byte OP_START_SERVICE
      OpCode for starting a specific service.
      See Also:
    • OP_KILL_WORKER

      public static final byte OP_KILL_WORKER
      OpCode for forcefully terminating a worker process.
      See Also:
    • OP_JOB_COMPLETE

      public static final byte OP_JOB_COMPLETE
      OpCode indicating that a job has completed its execution.
      See Also:
    • OP_LOG_STREAM

      public static final byte OP_LOG_STREAM
      OpCode for initiating a stream of logs from a running process or service.
      See Also:
    • OP_GET_LOGS

      public static final byte OP_GET_LOGS
      OpCode for requesting historical logs for a specific job or service.
      See Also:
    • OP_UPLOAD_ASSET

      public static final byte OP_UPLOAD_ASSET
      OpCode for uploading an asset (e.g., a binary, configuration file) to the system.
      See Also:
    • OP_FETCH_ASSET

      public static final byte OP_FETCH_ASSET
      OpCode for fetching an asset from the system.
      See Also:
    • OP_LOG_BATCH

      public static final byte OP_LOG_BATCH
      OpCode for sending a batch of log entries.
      See Also:
    • OP_RUN_ARCHIVE

      public static final byte OP_RUN_ARCHIVE
      OpCode 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_ARCHIVE
      OpCode for starting a service from an archived state or with archived configurations.
      See Also:
    • RUN_ARCHIVE

      public static final String RUN_ARCHIVE
      String identifier for the 'run archive' job type, typically used within payload data.
      See Also:
    • START_ARCHIVE_SERVICE

      public static final String 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_ACK
      Response OpCode indicating a successful operation (acknowledgment).
      See Also:
    • OP_ERROR

      public static final byte OP_ERROR
      Response OpCode indicating a failure or error during an operation.
      See Also:
    • OP_DATA

      public static final byte OP_DATA
      Response OpCode for sending generic data or a string response.
      See Also:
    • OP_KV_SET

      public static final byte OP_KV_SET
      OpCode for setting a key-value pair in a distributed key-value store.
      See Also:
    • OP_KV_GET

      public static final byte OP_KV_GET
      OpCode 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_SADD
      OpCode 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_SMEMBERS
      OpCode 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_STATUS
      OpCode for requesting the current status of a specific job.
      See Also:
  • Constructor Details

    • TitanProtocol

      public TitanProtocol()
  • Method Details

    • send

      public static void send(DataOutputStream out, byte opCode, String payload) throws IOException
      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 - The DataOutputStream to 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

      public static TitanProtocol.TitanPacket read(DataInputStream in) throws Exception
      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 - The DataInputStream to read the message from.
      Returns:
      A TitanProtocol.TitanPacket object 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

      public static void main(String[] args)
      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).