ServiceRequest.java

  1. package org.drip.zen.grid;

  2. import java.time.Instant;
  3. import java.util.Date;
  4. import java.util.UUID;

  5. public class ServiceRequest {
  6.     private UUID _id = null;
  7.     private Date _timeStamp = null;
  8.     private String _type = "";
  9.     private String _body = "";

  10.     public static ServiceRequest CreateFromString (
  11.         String request)
  12.     {
  13.         String[] requestFields = request.split ("@");

  14.         return new ServiceRequest (
  15.             UUID.fromString (requestFields[0]),
  16.             Date.from (Instant.ofEpochMilli (Long.parseLong (requestFields[1]))),
  17.             requestFields[2],
  18.             requestFields[3]
  19.         );
  20.     }

  21.     public static ServiceRequest Create (
  22.         String type,
  23.         String body)
  24.     {
  25.         return new ServiceRequest (
  26.             UUID.randomUUID(),
  27.             new Date(),
  28.             type,
  29.             body
  30.         );
  31.     }

  32.     public ServiceRequest (
  33.         UUID id,
  34.         Date timeStamp,
  35.         String type,
  36.         String body)
  37.     {
  38.         _id = id;
  39.         _type = type;
  40.         _body = body;
  41.         _timeStamp = timeStamp;
  42.     }

  43.     public UUID id()
  44.     {
  45.         return _id;
  46.     }

  47.     public Date timeStamp()
  48.     {
  49.         return _timeStamp;
  50.     }

  51.     public String type()
  52.     {
  53.         return _type;
  54.     }

  55.     public String body()
  56.     {
  57.         return _body;
  58.     }

  59.     public String display()
  60.     {
  61.         return _id.toString() + "|" + _timeStamp.toString() + "|" + _type + "|" + _body;
  62.     }

  63.     public String toString()
  64.     {
  65.         return _id.toString() + "@" + _timeStamp.toInstant().toEpochMilli() + "@" + _type + "@" + _body;
  66.     }

  67.     public static void main (
  68.         String[] input)
  69.     {
  70.         String serviceType = "SSRN";
  71.         String serviceInput = "JQP";

  72.         ServiceRequest sr = ServiceRequest.Create (
  73.             serviceType,
  74.             serviceInput
  75.         );

  76.         System.out.println (sr.display());

  77.         String serviceRequestString = sr.toString();

  78.         System.out.println (serviceRequestString);

  79.         ServiceRequest srUnpack = ServiceRequest.CreateFromString (serviceRequestString);

  80.         System.out.println (srUnpack.display());
  81.     }
  82. }