org.apache.ignite.Ignite.binary()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中org.apache.ignite.Ignite.binary()方法的一些代码示例,展示了Ignite.binary()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ignite.binary()方法的具体详情如下:
包路径:org.apache.ignite.Ignite
类名称:Ignite
方法名:binary

Ignite.binary介绍

[英]Gets an instance of IgniteBinary interface.
[中]获取二进制接口的实例。

代码示例

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public IgniteBinary binary() {
  checkIgnite();
  return g.binary();
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override protected Object typeIdForTypeName(TypeKind kind, String typeName) throws CacheException {
  if (kind == TypeKind.BINARY)
    return ignite.binary().typeId(typeName);
  try {
    return Class.forName(typeName);
  }
  catch (ClassNotFoundException e) {
    throw new CacheException("Failed to find class: " + typeName, e);
  }
}

代码示例来源:origin: apache/ignite

@Override public boolean apply() {
    return ignite0.binary().types().size() == 100;
  }
}, 5000);

代码示例来源:origin: apache/ignite

/**
 * @param val value to be used for creating the instance.
 */
public T instance(int val) {
  return BINARY_QUEUE_MODE
    ? (T)ignite.binary().toBinary(new SameHashItem(Integer.toString(val)))
    : (T)new SameHashItem(Integer.toString(val));
}

代码示例来源:origin: apache/ignite

/**
 * Create key object.
 *
 * @param ignite Ignite instance.
 * @param id ID.
 * @return Key object.
 */
protected static BinaryObject key(Ignite ignite, long id) {
  return ignite.binary().builder(KeyClass.class.getName()).setField(FIELD_KEY, id).build();
}

代码示例来源:origin: apache/ignite

/**
 * Check arrays with builder.
 *
 * @param registered Registered flag.
 * @throws Exception If failed.
 */
public void checkSimpleBuilderArray(boolean registered) throws Exception {
  startUp(registered);
  BinaryObject binaryOne = node1.binary().buildEnum(EnumType.class.getName(), EnumType.ONE.ordinal());
  BinaryObject binaryTwo = node1.binary().buildEnum(EnumType.class.getName(), EnumType.TWO.ordinal());
  cacheBinary1.put(1, new BinaryObject[] { binaryOne, binaryTwo });
  validateSimpleArray(registered);
}

代码示例来源:origin: apache/ignite

/**
 * Check if Binary facade is disabled test. Test uses JDK marshaller to provide warranty facade is not available
 * @throws Exception If failed.
 */
@Test
public void testBinaryDisabled() throws Exception {
  enableJdkMarshaller = true;
  assertNull(startGrid().binary());
}

代码示例来源:origin: apache/ignite

@Override public void run() {
    try {
      for (int j = 0; j < updatesNum; j++) {
        BinaryObjectBuilder bob = client.binary().builder(BINARY_TYPE_NAME);
        bob.setField("field" + j, threadId);
        cache.put(threadId, bob.build());
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}, "updater-" + i);

代码示例来源:origin: apache/ignite

/**
 * Create value object.
 *
 * @param ignite Ignite instance.
 * @param id ID.
 * @return Value object.
 */
protected static BinaryObject value(Ignite ignite, long id) {
  return ignite.binary().builder(ValueClass.class.getName())
    .setField(FIELD_NAME_1_ESCAPED, id)
    .setField(FIELD_NAME_2_ESCAPED, id)
    .build();
}

代码示例来源:origin: apache/ignite

@Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
    BinaryObject val = e.getValue();
    assertNotNull("Unexpected value: " + val, val);
    assertEquals(new Integer(1), val.field("val"));
    Ignite ignite = e.unwrap(Ignite.class);
    IgniteBinary binaries = ignite.binary();
    BinaryObjectBuilder builder = binaries.builder(val);
    builder.setField("val", 2);
    e.setValue(builder.build());
    return null;
  }
});

代码示例来源:origin: apache/ignite

@Override public Object call() throws Exception {
    try (Ignite grid = startGrid()) {
      IgniteCache<BinaryObject, String> cache = grid.cache(CACHE_NAME);
      HashMap<BinaryObject, String> batch = new HashMap<>();
      for (int i = 0; i < batchSize; i++) {
        BinaryObject key = grid.binary().builder("KEY_TYPE_NAME").setField("id", i).build();
        batch.put(key, "VALUE");
      }
      cache.putAllAsync(batch).get();
    }
    return null;
  }
}, CacheWriterException.class, null);

代码示例来源:origin: apache/ignite

@Override public Object call() throws Exception {
    node2.binary().registerEnum(enumName,
        F.asMap(EnumType.ONE.name(), EnumType.TWO.ordinal()));
    return null;
  }
}, BinaryObjectException.class, "Conflicting enum values. Value ");

代码示例来源:origin: apache/ignite

@Override public Object call() throws Exception {
    node2.binary().registerEnum(enumName,
        F.asMap(EnumType.TWO.name(), EnumType.ONE.ordinal()));
    return null;
  }
}, BinaryObjectException.class, "Conflicting enum values. Name ");

代码示例来源:origin: apache/ignite

/**
 * @param node Node.
 * @param val Number to form string field value from.
 * @return PERSON cache value.
 */
private BinaryObject val(Ignite node, int val) {
  String valTypeName = ((IgniteEx)node).context().query().types(CACHE_NAME).iterator().next().valueTypeName();
  return node.binary().builder(valTypeName).setField("name", "person" + val).build();
}

代码示例来源:origin: apache/ignite

/** Register enum */
private void defineEnum() {
  node1.binary().registerEnum(EnumType.class.getName(),
      F.asMap(EnumType.ONE.name(), EnumType.ONE.ordinal(),
          EnumType.TWO.name(), EnumType.TWO.ordinal()));
}

代码示例来源:origin: apache/ignite

/**
 * fill data by default
 */
private void fillTestData(Ignite ig) {
  try (IgniteDataStreamer<Object, Object> s = ig.dataStreamer(TEST_CACHE_NAME)) {
    for (int i = 0; i < 500; i++) {
      BinaryObject bo = ig.binary().builder("TestIndexObject")
        .setField("a", i, Object.class)
        .setField("b", String.valueOf(i), Object.class)
        .build();
      s.addData(i, bo);
    }
  }
}

代码示例来源:origin: apache/ignite

/**
 * Validate single value.
 *
 * @param obj Binary value.
 * @param val Expected value.
 */
private void validate(BinaryObject obj, DeclaredBodyEnum val) {
  assertTrue(obj.type().isEnum());
  assertEquals(node1.binary().typeId(DeclaredBodyEnum.class.getName()), obj.type().typeId());
  assertEquals(node2.binary().typeId(DeclaredBodyEnum.class.getName()), obj.type().typeId());
  assertEquals(val.ordinal(), obj.enumOrdinal());
}

代码示例来源:origin: apache/ignite

@Override public Object call() throws Exception {
    node1.binary().registerEnum("invalidEnumType1",
      F.asMap(EnumType.ONE.name(), EnumType.ONE.ordinal(),
      EnumType.TWO.name(), EnumType.ONE.ordinal()));
    return null;
  }
}, BinaryObjectException.class, "Conflicting enum values");

代码示例来源:origin: apache/ignite

/**
 * @param ignite Node.
 * @param id Identifier.
 * @return Trader entity as binary object.
 */
private BinaryObject createTrader(Ignite ignite, String id) {
  return ignite.binary()
    .builder(TRADER)
    .setField(ID, id)
    .setField(FIRSTNAME, "First name " + id)
    .setField(SECONDNAME, "Second name " + id)
    .setField(EMAIL, "trader" + id + "@mail.org")
    .build();
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Nullable @Override public Object execute() {
  BinaryObjectEx arg0 = ((BinaryObjectEx)arg);
  BinaryType meta = ignite.binary().type(arg0.typeId());
  if (meta == null)
    throw new IgniteException("Metadata doesn't exist.");
  if (meta.fieldNames() == null || !meta.fieldNames().contains("Field"))
    throw new IgniteException("Field metadata doesn't exist.");
  if (!F.eq("int", meta.fieldTypeName("Field")))
    throw new IgniteException("Invalid field type: " + meta.fieldTypeName("Field"));
  if (meta.affinityKeyFieldName() != null)
    throw new IgniteException("Unexpected affinity key: " + meta.affinityKeyFieldName());
  return arg0.field("field");
}

相关文章