Ejemplo n.º 1
0
  /**
   * Creates a ModuleSpecID in a given class, with a given class unique id. A UUID of a class and
   * another UUID are provided.
   *
   * @param classUUID the class to which this will belong.
   * @param specUUID the unique id of this spec in that class.
   */
  protected ModuleSpecID(UUID classUUID, UUID specUUID) {

    this();
    id.longIntoBytes(ModuleSpecID.moduleClassIdOffset, classUUID.getMostSignificantBits());
    id.longIntoBytes(ModuleSpecID.moduleClassIdOffset + 8, classUUID.getLeastSignificantBits());

    id.longIntoBytes(ModuleSpecID.moduleSpecIdOffset, specUUID.getMostSignificantBits());
    id.longIntoBytes(ModuleSpecID.moduleSpecIdOffset + 8, specUUID.getLeastSignificantBits());
  }
Ejemplo n.º 2
0
 public static JpsRemoteProto.Message.UUID toProtoUUID(UUID requestId) {
   return JpsRemoteProto.Message.UUID
       .newBuilder()
       .setMostSigBits(requestId.getMostSignificantBits())
       .setLeastSigBits(requestId.getLeastSignificantBits())
       .build();
 }
Ejemplo n.º 3
0
 protected void putUUID(String name, UUID val) {
   _put(BINARY, name);
   _buf.writeInt(16);
   _buf.write(B_UUID);
   _buf.writeLong(val.getMostSignificantBits());
   _buf.writeLong(val.getLeastSignificantBits());
 }
Ejemplo n.º 4
0
  public String getCompUniqueID() {
    UUID tempID = null;
    long longID = 0L;
    StringBuffer result = new StringBuffer();

    tempID = getPackage_id();

    if (IdAssigner.NULL_UUID.equals(tempID)) tempID = getPackage_idCachedValue();
    result.append(Long.toHexString(tempID.getMostSignificantBits()));
    result.append(Long.toHexString(tempID.getLeastSignificantBits()));
    tempID = getDt_id();

    if (IdAssigner.NULL_UUID.equals(tempID)) tempID = getDt_idCachedValue();
    result.append(Long.toHexString(tempID.getMostSignificantBits()));
    result.append(Long.toHexString(tempID.getLeastSignificantBits()));
    return result.toString();
  }
 @Override
 public void writeCustomNBT(NBTTagCompound cmp) {
   super.writeCustomNBT(cmp);
   if (golemConnected != null) {
     cmp.setLong(TAG_UUID_MOST, golemConnected.getMostSignificantBits());
     cmp.setLong(TAG_UUID_LEAST, golemConnected.getLeastSignificantBits());
   }
 }
Ejemplo n.º 6
0
 /**
  * Returns a sorted map with annotations to be sent with each message. Default behavior is to
  * include the current correlation id (if it is set).
  */
 public SortedMap<String, byte[]> annotations() {
   SortedMap<String, byte[]> ann = new TreeMap<String, byte[]>();
   if (correlation_id != null) {
     long hi = correlation_id.getMostSignificantBits();
     long lo = correlation_id.getLeastSignificantBits();
     ann.put("CORR", ByteBuffer.allocate(16).putLong(hi).putLong(lo).array());
   }
   return ann;
 }
Ejemplo n.º 7
0
  /**
   * Converts message to bytes to send over network.
   *
   * @return Bytes representing this packet.
   */
  public byte[] toBytes() {
    byte[] buf = new byte[PACKET_SIZE];

    int off = 0;

    off = U.longToBytes(origNodeId.getLeastSignificantBits(), buf, off);
    off = U.longToBytes(origNodeId.getMostSignificantBits(), buf, off);

    off = U.longToBytes(targetNodeId.getLeastSignificantBits(), buf, off);
    off = U.longToBytes(targetNodeId.getMostSignificantBits(), buf, off);

    off = U.longToBytes(origTs, buf, off);

    off = U.longToBytes(replyTs, buf, off);

    assert off == PACKET_SIZE;

    return buf;
  }
Ejemplo n.º 8
0
  public String getCompUniqueID() {
    UUID tempID = null;
    long longID = 0L;
    StringBuffer result = new StringBuffer();

    tempID = getId();

    result.append(Long.toHexString(tempID.getMostSignificantBits()));
    result.append(Long.toHexString(tempID.getLeastSignificantBits()));
    return result.toString();
  }
  @Override
  public void writeExternal(DataOutput out) throws IOException {
    super.writeExternal(out);
    out.writeLong(uuid1.getMostSignificantBits());
    out.writeLong(uuid1.getLeastSignificantBits());
    out.writeInt(int1);

    if (revisions == null) {
      out.writeInt(0);
    } else {
      out.writeInt(revisions.size());

      for (TtkRefexUuidIntRevision rmv : revisions) {
        rmv.writeExternal(out);
      }
    }
  }
Ejemplo n.º 10
0
 public static byte[] toBytes(UUID uuid) {
   ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
   byteBuffer.putLong(uuid.getMostSignificantBits());
   byteBuffer.putLong(uuid.getLeastSignificantBits());
   return byteBuffer.array();
 }
Ejemplo n.º 11
0
  public boolean send(Socket socket) {
    assert (socket != null);

    ZMsg msg = new ZMsg();
    //  If we're sending to a ROUTER, send the routingId first
    if (socket.getType() == ZMQ.ROUTER) {
      msg.add(routingId);
    }

    int frameSize = 2 + 1; //  Signature and message ID
    switch (id) {
      case LOG:
        {
          //  sequence is a 2-byte integer
          frameSize += 2;
          //  version is a 2-byte integer
          frameSize += 2;
          //  level is a 1-byte integer
          frameSize += 1;
          //  event is a 1-byte integer
          frameSize += 1;
          //  node is a 2-byte integer
          frameSize += 2;
          //  peer is a 2-byte integer
          frameSize += 2;
          //  time is a 8-byte integer
          frameSize += 8;
          //  host is a string with 1-byte length
          frameSize++;
          frameSize += (host != null) ? host.length() : 0;
          //  data is a long string with 4-byte length
          frameSize += 4;
          frameSize += (data != null) ? data.length() : 0;
        }
        break;

      case STRUCTURES:
        {
          //  sequence is a 2-byte integer
          frameSize += 2;
          //  aliases is an array of strings
          frameSize += 4;
          if (aliases != null) {
            for (String value : aliases) {
              frameSize += 4;
              frameSize += value.length();
            }
          }
          //  headers is an array of key=value strings
          frameSize += 4;
          if (headers != null) {
            headersBytes = 0;
            for (Map.Entry<String, String> entry : headers.entrySet()) {
              headersBytes += 1 + entry.getKey().length();
              headersBytes += 4 + entry.getValue().length();
            }
            frameSize += headersBytes;
          }
        }
        break;

      case BINARY:
        {
          //  sequence is a 2-byte integer
          frameSize += 2;
          //  flags is a block of 4 bytes
          frameSize += 4;
          //  public_key is a chunk with 4-byte length
          frameSize += 4;
          frameSize += (public_key != null) ? public_key.length : 0;
          //  identifier is uuid with 16-byte length
          frameSize += 16;
        }
        break;

      case TYPES:
        {
          //  sequence is a 2-byte integer
          frameSize += 2;
          //  client_forename is a string with 1-byte length
          frameSize++;
          frameSize += (client_forename != null) ? client_forename.length() : 0;
          //  client_surname is a string with 1-byte length
          frameSize++;
          frameSize += (client_surname != null) ? client_surname.length() : 0;
          //  client_mobile is a string with 1-byte length
          frameSize++;
          frameSize += (client_mobile != null) ? client_mobile.length() : 0;
          //  client_email is a string with 1-byte length
          frameSize++;
          frameSize += (client_email != null) ? client_email.length() : 0;
          //  supplier_forename is a string with 1-byte length
          frameSize++;
          frameSize += (supplier_forename != null) ? supplier_forename.length() : 0;
          //  supplier_surname is a string with 1-byte length
          frameSize++;
          frameSize += (supplier_surname != null) ? supplier_surname.length() : 0;
          //  supplier_mobile is a string with 1-byte length
          frameSize++;
          frameSize += (supplier_mobile != null) ? supplier_mobile.length() : 0;
          //  supplier_email is a string with 1-byte length
          frameSize++;
          frameSize += (supplier_email != null) ? supplier_email.length() : 0;
        }
        break;

      default:
        System.out.printf("E: bad message type '%d', not sent\n", id);
        assert (false);
    }
    //  Now serialize message into the frame
    ZFrame frame = new ZFrame(new byte[frameSize]);
    needle = ByteBuffer.wrap(frame.getData());
    int frameFlags = 0;
    putNumber2(0xAAA0 | 0);
    putNumber1((byte) id);

    switch (id) {
      case LOG:
        {
          putNumber2(sequence);
          putNumber2(3);
          putNumber1(level);
          putNumber1(event);
          putNumber2(node);
          putNumber2(peer);
          putNumber8(time);
          if (host != null) putString(host);
          else putNumber1((byte) 0); //  Empty string
          if (data != null) putLongString(data);
          else putNumber4(0); //  Empty string
        }
        break;

      case STRUCTURES:
        {
          putNumber2(sequence);
          if (aliases != null) {
            putNumber4(aliases.size());
            for (String value : aliases) {
              putLongString(value);
            }
          } else putNumber4(0); //  Empty string array
          if (headers != null) {
            putNumber4(headers.size());
            for (Map.Entry<String, String> entry : headers.entrySet()) {
              putString(entry.getKey());
              putLongString(entry.getValue());
            }
          } else putNumber4(0); //  Empty hash
        }
        break;

      case BINARY:
        {
          putNumber2(sequence);
          putBlock(flags, 4);
          if (public_key != null) {
            putNumber4(public_key.length);
            needle.put(public_key, 0, public_key.length);
          } else {
            putNumber4(0);
          }
          if (identifier != null) {
            ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
            bb.putLong(identifier.getMostSignificantBits());
            bb.putLong(identifier.getLeastSignificantBits());
            needle.put(bb.array());
          } else {
            needle.put(new byte[16]); //  Empty Chunk
          }
        }
        break;

      case TYPES:
        {
          putNumber2(sequence);
          if (client_forename != null) putString(client_forename);
          else putNumber1((byte) 0); //  Empty string
          if (client_surname != null) putString(client_surname);
          else putNumber1((byte) 0); //  Empty string
          if (client_mobile != null) putString(client_mobile);
          else putNumber1((byte) 0); //  Empty string
          if (client_email != null) putString(client_email);
          else putNumber1((byte) 0); //  Empty string
          if (supplier_forename != null) putString(supplier_forename);
          else putNumber1((byte) 0); //  Empty string
          if (supplier_surname != null) putString(supplier_surname);
          else putNumber1((byte) 0); //  Empty string
          if (supplier_mobile != null) putString(supplier_mobile);
          else putNumber1((byte) 0); //  Empty string
          if (supplier_email != null) putString(supplier_email);
          else putNumber1((byte) 0); //  Empty string
        }
        break;
    }
    //  Now send the data frame
    msg.add(frame);

    //  Now send any frame fields, in order
    switch (id) {
      case BINARY:
        {
          //  If address isn't set, send an empty frame
          if (address == null) address = new ZFrame("".getBytes());
          msg.add(address);
        }
        break;
    }
    switch (id) {
      case BINARY:
        {
          if (content == null) content = new ZMsg();
          for (ZFrame contentPart : content) {
            msg.add(contentPart);
          }
        }
        break;
    }
    //  Destroy ZprotoExample object
    msg.send(socket);
    destroy();
    return true;
  }