private int readNestedPosition(String fieldName, FieldType type) throws IOException {
    String[] fieldNames = NESTED_FIELD_PATTERN.split(fieldName);
    if (fieldNames.length > 1) {
      FieldDefinition fd = null;
      DefaultPortableReader reader = this;

      for (int i = 0; i < fieldNames.length; i++) {
        fd = reader.cd.getField(fieldNames[i]);
        if (fd == null) {
          break;
        }
        if (i == fieldNames.length - 1) {
          break;
        }

        int pos = reader.readPosition(fd);
        in.position(pos);
        boolean isNull = in.readBoolean();
        if (isNull) {
          throw new NullPointerException("Parent field is null: " + fieldNames[i]);
        }
        reader = serializer.createReader(in, fd.getFactoryId(), fd.getClassId(), fd.getVersion());
      }
      if (fd == null) {
        throw throwUnknownFieldException(fieldName);
      }
      if (fd.getType() != type) {
        throw new HazelcastSerializationException("Not a '" + type + "' field: " + fieldName);
      }
      return reader.readPosition(fd);
    }
    throw throwUnknownFieldException(fieldName);
  }
 public ObjectDataInput getRawDataInput() throws IOException {
   if (!raw) {
     int pos = in.readInt(offset + cd.getFieldCount() * 4);
     in.position(pos);
   }
   raw = true;
   return in;
 }
예제 #3
0
 @Override
 public BufferObjectDataInput takeInputBuffer(Data data) {
   BufferObjectDataInput in = inputQueue.poll();
   if (in == null) {
     in = serializationService.createObjectDataInput((byte[]) null);
   }
   in.init(data.toByteArray(), HeapData.DATA_OFFSET);
   return in;
 }
 public short[] readShortArray(String fieldName) throws IOException {
   final int currentPos = in.position();
   try {
     int pos = readPosition(fieldName, FieldType.SHORT_ARRAY);
     in.position(pos);
     return in.readShortArray();
   } finally {
     in.position(currentPos);
   }
 }
 public double[] readDoubleArray(String fieldName) throws IOException {
   final int currentPos = in.position();
   try {
     int pos = readPosition(fieldName, FieldType.DOUBLE_ARRAY);
     in.position(pos);
     return in.readDoubleArray();
   } finally {
     in.position(currentPos);
   }
 }
 public long[] readLongArray(String fieldName) throws IOException {
   final int currentPos = in.position();
   try {
     int pos = readPosition(fieldName, FieldType.LONG_ARRAY);
     in.position(pos);
     return in.readLongArray();
   } finally {
     in.position(currentPos);
   }
 }
 public char[] readCharArray(String fieldName) throws IOException {
   final int currentPos = in.position();
   try {
     int pos = readPosition(fieldName, FieldType.CHAR_ARRAY);
     in.position(pos);
     return in.readCharArray();
   } finally {
     in.position(currentPos);
   }
 }
 public byte[] readByteArray(String fieldName) throws IOException {
   final int currentPos = in.position();
   try {
     int pos = readPosition(fieldName, FieldType.BYTE_ARRAY);
     in.position(pos);
     return IOUtil.readByteArray(in);
   } finally {
     in.position(currentPos);
   }
 }
 public String readUTF(String fieldName) throws IOException {
   final int currentPos = in.position();
   try {
     int pos = readPosition(fieldName, FieldType.UTF);
     in.position(pos);
     return in.readUTF();
   } finally {
     in.position(currentPos);
   }
 }
예제 #10
0
 public DefaultPortableReader(
     PortableSerializer serializer, BufferObjectDataInput in, ClassDefinition cd) {
   this.in = in;
   this.serializer = serializer;
   this.cd = cd;
   try {
     // final position after portable is read
     finalPosition = in.readInt();
   } catch (IOException e) {
     throw new HazelcastSerializationException(e);
   }
   this.offset = in.position();
 }
예제 #11
0
 public Portable[] readPortableArray(String fieldName) throws IOException {
   FieldDefinition fd = cd.getField(fieldName);
   if (fd == null) {
     throw throwUnknownFieldException(fieldName);
   }
   if (fd.getType() != FieldType.PORTABLE_ARRAY) {
     throw new HazelcastSerializationException("Not a Portable array field: " + fieldName);
   }
   final int currentPos = in.position();
   try {
     int pos = readPosition(fd);
     in.position(pos);
     final int len = in.readInt();
     final Portable[] portables = new Portable[len];
     if (len > 0) {
       final int offset = in.position();
       for (int i = 0; i < len; i++) {
         final int start = in.readInt(offset + i * 4);
         in.position(start);
         portables[i] =
             serializer.readAndInitialize(in, fd.getFactoryId(), fd.getClassId(), fd.getVersion());
       }
     }
     return portables;
   } finally {
     in.position(currentPos);
   }
 }
예제 #12
0
  private JoinMessage receive() {
    try {
      try {
        multicastSocket.receive(datagramPacketReceive);
      } catch (IOException ignore) {
        return null;
      }
      try {
        final byte[] data = datagramPacketReceive.getData();
        final int offset = datagramPacketReceive.getOffset();
        final BufferObjectDataInput input =
            node.getSerializationService().createObjectDataInput(data);
        input.position(offset);

        final byte packetVersion = input.readByte();
        if (packetVersion != Packet.VERSION) {
          logger.warning(
              "Received a JoinRequest with a different packet version! This -> "
                  + Packet.VERSION
                  + ", Incoming -> "
                  + packetVersion
                  + ", Sender -> "
                  + datagramPacketReceive.getAddress());
          return null;
        }
        try {
          return input.readObject();
        } finally {
          input.close();
        }
      } catch (Exception e) {
        if (e instanceof EOFException || e instanceof HazelcastSerializationException) {
          logger.warning(
              "Received data format is invalid."
                  + " (An old version of Hazelcast may be running here.)",
              e);
        } else {
          throw e;
        }
      }
    } catch (Exception e) {
      logger.warning(e);
    }
    return null;
  }
예제 #13
0
  @Override
  public void returnInputBuffer(BufferObjectDataInput in) {
    if (in == null) {
      return;
    }

    in.clear();

    offerOrClose(inputQueue, in);
  }
예제 #14
0
 public Portable readPortable(String fieldName) throws IOException {
   FieldDefinition fd = cd.getField(fieldName);
   if (fd == null) {
     throw throwUnknownFieldException(fieldName);
   }
   if (fd.getType() != FieldType.PORTABLE) {
     throw new HazelcastSerializationException("Not a Portable field: " + fieldName);
   }
   final int currentPos = in.position();
   try {
     int pos = readPosition(fd);
     in.position(pos);
     final boolean isNull = in.readBoolean();
     if (!isNull) {
       return serializer.readAndInitialize(
           in, fd.getFactoryId(), fd.getClassId(), fd.getVersion());
     }
     return null;
   } finally {
     in.position(currentPos);
   }
 }
예제 #15
0
 public double readDouble(String fieldName) throws IOException {
   int pos = readPosition(fieldName, FieldType.DOUBLE);
   return in.readDouble(pos);
 }
예제 #16
0
 public byte readByte(String fieldName) throws IOException {
   int pos = readPosition(fieldName, FieldType.BYTE);
   return in.readByte(pos);
 }
예제 #17
0
 public boolean readBoolean(String fieldName) throws IOException {
   int pos = readPosition(fieldName, FieldType.BOOLEAN);
   return in.readBoolean(pos);
 }
예제 #18
0
 public float readFloat(String fieldName) throws IOException {
   int pos = readPosition(fieldName, FieldType.FLOAT);
   return in.readFloat(pos);
 }
예제 #19
0
 public long readLong(String fieldName) throws IOException {
   int pos = readPosition(fieldName, FieldType.LONG);
   return in.readLong(pos);
 }
예제 #20
0
 public int readInt(String fieldName) throws IOException {
   int pos = readPosition(fieldName, FieldType.INT);
   return in.readInt(pos);
 }
예제 #21
0
 public short readShort(String fieldName) throws IOException {
   int pos = readPosition(fieldName, FieldType.SHORT);
   return in.readShort(pos);
 }
예제 #22
0
 void end() throws IOException {
   in.position(finalPosition);
 }
예제 #23
0
 private int readPosition(FieldDefinition fd) throws IOException {
   return in.readInt(offset + fd.getIndex() * 4);
 }
예제 #24
0
 public char readChar(String fieldName) throws IOException {
   int pos = readPosition(fieldName, FieldType.CHAR);
   return in.readChar(pos);
 }