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

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

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

Ignition.setClientMode介绍

[英]Sets client mode thread-local flag.

This flag used when node is started if IgniteConfiguration#isClientMode()is null. When IgniteConfiguration#isClientMode() is set this flag is ignored.
[中]设置客户端模式线程本地标志。
如果IgniteConfiguration#isClientMode()为null,则在启动节点时使用此标志。设置IgniteConfiguration#isClientMode()时,将忽略此标志。

代码示例

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

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  startGridsMultiThreaded(3, false);
  Ignition.setClientMode(true);
  try {
    startGrid(CLIENT);
  }
  finally {
    Ignition.setClientMode(false);
  }
}

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

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  startGridsMultiThreaded(3);
  try {
    Ignition.setClientMode(true);
    startGrid();
  }
  finally {
    Ignition.setClientMode(false);
  }
}

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

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  startGridsMultiThreaded(3);
  Ignition.setClientMode(true);
  try {
    startGrid("client1");
    startGrid("client2");
  }
  finally {
    Ignition.setClientMode(false);
  }
}

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

/** {@inheritDoc} */
@Override public void init(long dataPtr) {
  final PlatformInputStream input = new PlatformExternalMemory(null, dataPtr).input();
  Ignition.setClientMode(input.readBoolean());
  processInput(input);
}

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

/**
 * Ignite grid of 3 server nodes with passed parameters.
 *
 * @param atomicityMode atomicity mode
 * @param mode cache mode
 * @param writeSyncMode cache write synchronization mode
 * @param backupsCnt backups count
 * @throws Exception If failed.
 */
private void initGrid(CacheAtomicityMode atomicityMode, CacheMode mode,
  CacheWriteSynchronizationMode writeSyncMode, int backupsCnt) throws Exception {
  this.atomicityMode = atomicityMode;
  this.mode = mode;
  this.backupsCnt = backupsCnt;
  this.writeSyncMode = writeSyncMode;
  Ignition.setClientMode(false);
  for (int i = 0; i < NODES; i++)
    startGrid(i);
  Ignition.setClientMode(true);
  client = startGrid(NODES + 1);
  // it is required to start first node in test jvm, but we can not start client node,
  // because client will fail to connect and test will fail too.
  // as workaround start first server node in test jvm and then stop it.
  stopGrid(0);
}

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

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  assert NODES_CNT > 2;
  ids = new LinkedList<>();
  try {
    for (int i = 0; i < NODES_CNT; i++) {
      Ignition.setClientMode(i > 1);
      Ignite g = startGrid(i);
      ids.add(g.cluster().localNode().id());
      if (i == 0)
        ignite = g;
    }
    waitForTopology(NODES_CNT);
  }
  finally {
    Ignition.setClientMode(false);
  }
}

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

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_EVENTS);
  startGridsMultiThreaded(3);
  Ignition.setClientMode(true);
  try {
    Ignite ignite = startGrid("client");
    ignite.events().remoteListen(
      new IgniteBiPredicate<UUID, Event>() {
        @Override public boolean apply(UUID uuid, Event evt) {
          return true;
        }
      },
      new IgnitePredicate<Event>() {
        @Override public boolean apply(Event evt) {
          throw new NoClassDefFoundError("XXX");
        }
      },
      EventType.EVT_CACHE_OBJECT_PUT
    );
  }
  finally {
    Ignition.setClientMode(false);
  }
}

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

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  startGridsMultiThreaded(3, false);
  Ignition.setClientMode(true);
  try {
    startGrid(CLIENT);
  }
  finally {
    Ignition.setClientMode(false);
  }
  IgniteCache c = grid(CLIENT).cache(CACHE_NAME);
  int k = 0;
  for (int grp = 1; grp < 7; ++grp) {
    for (int i = 0; i < grp; ++i) {
      c.put(new Key(k, grp), new Value(k, Character.toString((char)('A' + k))));
      k++;
    }
  }
}

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

return;
Ignition.setClientMode(true);

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

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  igfsSecondaryFileSystem = createSecondaryFileSystemStack();
  nodes = new Ignite[nodeCount()];
  for (int i = 0; i < nodes.length; i++) {
    String nodeName = i == 0 ? "ignite" : "ignite" + i;
    nodes[i] = startGridWithIgfs(nodeName, "igfs", mode, igfsSecondaryFileSystem, PRIMARY_REST_CFG,
      primaryIpFinder);
  }
  igfs = (IgfsImpl) nodes[0].fileSystem("igfs");
  if (client()) {
    // Start client.
    Ignition.setClientMode(true);
    try {
      Ignite ignite = startGridWithIgfs("ignite-client", "igfs", mode, igfsSecondaryFileSystem,
        PRIMARY_REST_CFG, primaryIpFinder);
      igfs = (IgfsImpl) ignite.fileSystem("igfs");
    }
    finally {
      Ignition.setClientMode(false);
    }
  }
}

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

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  startGridsMultiThreaded(3, false);
  Ignition.setClientMode(true);
  try {
    startGrid(CLIENT);
  }
  finally {
    Ignition.setClientMode(false);
  }
  IgniteCache c = grid(CLIENT).cache(CACHE_NAME);
  int k = 0;
  for (int grp = 1; grp < 7; ++grp) {
    for (int i = 0; i < grp; ++i) {
      c.put(new Key(k, grp), new Value(k, Character.toString((char)('A' + k))));
      k++;
    }
  }
  // Add duplicates
  k = 0;
  for (int grp = 1; grp < 7; ++grp) {
    for (int i = 0; i < grp; ++i) {
      c.put(new Key(k + KEY_BASE_FOR_DUPLICATES, grp),
        new Value(k + KEY_BASE_FOR_DUPLICATES, Character.toString((char)('A' + k))));
      k++;
    }
  }
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testJobCancel() throws Exception {
  Ignite server = startGrid("server");
  server.services().deployNodeSingleton("my-service", new MyService());
  Ignition.setClientMode(true);
  Ignite client = startGrid("client");
  ComputeTaskFuture<Integer> fut = client.compute().executeAsync(new MyTask(), null);
  Thread.sleep(3000);
  server.close();
  assertEquals(42, fut.get().intValue());
}

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

/**
 * @param serverCnt Servers count.
 * @throws Exception If failed.
 */
private void doTestClientSuspension(int serverCnt) throws Exception {
  startGrids(serverCnt);
  Ignition.setClientMode(true);
  Ignite client = startGrid("client");
  for (int i = 0; i < serverCnt; i++)
    assertEquals(1, grid(i).cluster().forClients().nodes().size());
  Thread.sleep(2000);
  for (int i = 0; i < serverCnt; i++)
    assertEquals(1, grid(i).cluster().forClients().nodes().size());
  suspendClientMetricsUpdate(client);
  Thread.sleep(2000);
  for (int i = 0; i < serverCnt; i++)
    assertEquals(0, grid(i).cluster().forClients().nodes().size());
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testExecution() throws Exception {
  startGrid(0); // Server.
  Ignition.setClientMode(true);
  Ignite ignite = startGrid(); // Client.
  ignite.services().deployClusterSingleton("my-service", new MyServiceImpl());
  MyService svc = ignite.services().serviceProxy("my-service", MyService.class, false);
  svc.hello();
}

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

Ignition.setClientMode(true);

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

Ignition.setClientMode(true);
Ignition.setClientMode(false);

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

/**
   * @throws Exception If failed.
   */
  @Test
  public void testPackagePrivateService() throws Exception {
    try {
      Ignite server = startGrid("server");

      server.services().deployClusterSingleton("my-service", MyServiceFactory.create());

      Ignition.setClientMode(true);

      Ignite client = startGrid("client");

      MyService svc = client.services().serviceProxy("my-service", MyService.class, true);

      assertEquals(42, svc.hello());
    }
    finally {
      stopAllGrids();
    }
  }
}

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

/**
   * @throws Exception If failed.
   */
  @Test
  public void testQueryFromNewClientCustomSchemaName() throws Exception {
    Ignite srv = startGrid("server");

    IgniteCache<Integer, Integer> cache1 = srv.createCache(new CacheConfiguration<Integer, Integer>().
      setName("cache1").setSqlSchema("cache1_sql").setIndexedTypes(Integer.class, Integer.class));
    IgniteCache<Integer, Integer> cache2 = srv.createCache(new CacheConfiguration<Integer, Integer>().
      setName("cache2").setSqlSchema("cache2_sql").setIndexedTypes(Integer.class, Integer.class));

    for (int i = 0; i < 10; i++) {
      cache1.put(i, i);
      cache2.put(i, i);
    }

    Ignition.setClientMode(true);

    Ignite client = startGrid("client");

    IgniteCache<Integer, Integer> cache = client.cache("cache1");

    List<List<?>> res = cache.query(new SqlFieldsQuery(
      "select i1._val, i2._val from Integer i1 cross join cache2_sql.Integer i2")).getAll();

    assertEquals(100, res.size());
  }
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testQueryFromNewClient() throws Exception {
  Ignite srv = startGrid("server");
  for (int iter = 0; iter < 2; iter++) {
    log.info("Iteration: " + iter);
    IgniteCache<Integer, Integer> cache1 = srv.createCache(new CacheConfiguration<Integer, Integer>().
      setName("cache1").setIndexedTypes(Integer.class, Integer.class));
    IgniteCache<Integer, Integer> cache2 = srv.createCache(new CacheConfiguration<Integer, Integer>().
      setName("cache2").setIndexedTypes(Integer.class, Integer.class));
    for (int i = 0; i < 10; i++) {
      cache1.put(i, i);
      cache2.put(i, i);
    }
    Ignition.setClientMode(true);
    Ignite client = (iter == 0) ? startGrid("client") : grid("client");
    IgniteCache<Integer, Integer> cache = client.cache("cache1");
    List<List<?>> res = cache.query(new SqlFieldsQuery(
      "select i1._val, i2._val from Integer i1 cross join \"cache2\".Integer i2")).getAll();
    assertEquals(100, res.size());
    srv.destroyCache(cache1.getName());
    srv.destroyCache(cache2.getName());
  }
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testDataPageScan() throws Exception {
  final String cacheName = "test";
  GridQueryProcessor.idxCls = DirectPageScanIndexing.class;
  IgniteEx server = startGrid(0);
  server.cluster().active(true);
  Ignition.setClientMode(true);
  IgniteEx client = startGrid(1);
  CacheConfiguration<Long,TestData> ccfg = new CacheConfiguration<>(cacheName);
  ccfg.setIndexedTypes(Long.class, TestData.class);
  ccfg.setSqlFunctionClasses(QueryDataPageScanTest.class);
  IgniteCache<Long,TestData> clientCache = client.createCache(ccfg);
  final int keysCnt = 1000;
  for (long i = 0; i < keysCnt; i++)
    clientCache.put(i, new TestData(i));
  IgniteCache<Long,TestData> serverCache = server.cache(cacheName);
  doTestScanQuery(clientCache, keysCnt);
  doTestScanQuery(serverCache, keysCnt);
  doTestSqlQuery(clientCache);
  doTestSqlQuery(serverCache);
  doTestDml(clientCache);
  doTestDml(serverCache);
  doTestLazySql(clientCache, keysCnt);
  doTestLazySql(serverCache, keysCnt);
}

相关文章