コード例 #1
0
 private V createValueIfNull(V value) {
   if (value == null) {
     if (generatedValueType) value = DataValueClasses.newDirectReference(vClass);
     else
       try {
         value = vClass.newInstance();
       } catch (Exception e) {
         throw new AssertionError(e);
       }
   }
   return value;
 }
コード例 #2
0
 /**
  * Reads from {@link this.tmpBytes} an object at {@param offset}, will reuse {@param value} if
  * possible, to reduce object creation.
  *
  * @param offset the offset to read the data from
  * @param value the object to reuse ( if possible ), if null a new object will be created an
  *     object and no reuse will occur.
  */
 @SuppressWarnings("unchecked")
 V readObjectUsing(V value, final long offset) {
   if (value instanceof Byteable) {
     ((Byteable) value).bytes(bytes, offset);
     return value;
   }
   if (generatedValueType) {
     if (value == null) value = DataValueClasses.newInstance(vClass);
     ((BytesMarshallable) value).readMarshallable(tmpBytes);
     return value;
   }
   return tmpBytes.readInstance(vClass, value);
 }
コード例 #3
0
  @Before
  public void setup() throws IOException {
    value = DataValueClasses.newDirectReference(IntValue.class);
    ((Byteable) value).bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);

    final InetSocketAddress endpoint = new InetSocketAddress("localhost", s_port + 1);
    timeProvider =
        new TimeProvider() {

          Random rnd = new Random(4);

          @Override
          public long currentTime() {

            if (rnd.nextBoolean()) return t++;
            else return t;
          }
        };

    {
      final TcpTransportAndNetworkConfig tcpConfig1 =
          TcpTransportAndNetworkConfig.of(s_port, endpoint);

      map1 =
          ChronicleMapBuilder.of(Integer.class, CharSequence.class)
              .entries(Builder.SIZE)
              .timeProvider(timeProvider)
              .replication((byte) 1, tcpConfig1)
              .create();
    }
    {
      final TcpTransportAndNetworkConfig tcpConfig2 = TcpTransportAndNetworkConfig.of(s_port + 1);

      map2 =
          ChronicleMapBuilder.of(Integer.class, CharSequence.class)
              .entries(Builder.SIZE)
              .timeProvider(timeProvider)
              .replication((byte) 2, tcpConfig2)
              .create();
    }
    s_port += 2;
  }