org.apache.ignite.Ignition类的使用及代码示例

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

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

Ignition介绍

[英]This class defines a factory for the main Ignite API. It controls Grid life cycle and allows listening for grid events. Grid Loaders Although user can apply grid factory directly to start and stop grid, grid is often started and stopped by grid loaders. Grid loaders can be found in org.apache.ignite.startup package, for example:

  • org.apache.ignite.startup.cmdline.CommandLineStartup
  • org.apache.ignite.startup.servlet.ServletStartup
    Examples Use #start() method to start grid with default configuration. You can also use org.apache.ignite.configuration.IgniteConfiguration to override some default configuration. Below is an example on how to start grid with custom configuration for URI deployment.
IgniteConfiguration cfg = new IgniteConfiguration(); 
GridUriDeployment deploySpi = new GridUriDeployment(); 
deploySpi.setUriList(Collections.singletonList("classes://tmp/output/classes")); 
cfg.setDeploymentSpi(deploySpi); 
Ignition.start(cfg);

Here is how a grid instance can be configured from Spring XML configuration file. The example below configures a grid instance with additional user attributes (see org.apache.ignite.cluster.ClusterNode#attributes()) and specifies a Ignite instance name:

<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> 
... 
<property name="igniteInstanceName" value="grid"/> 
<property name="userAttributes"> 
<map> 
<entry key="group" value="worker"/> 
</map> 
</property> 
... 
</bean>

A grid instance with Spring configuration above can be started as following. Note that you do not need to pass path to Spring XML file if you are using IGNITE_HOME/config/default-config.xml. Also note, that the path can be absolute or relative to IGNITE_HOME.

... 
Ignition.start("/path/to/spring/xml/file.xml"); 
...

You can also instantiate grid directly from Spring without using Ignition. For more information refer to org.apache.ignite.IgniteSpringBean documentation.
[中]此类定义了主Ignite API的工厂。它控制网格生命周期并允许侦听网格事件。网格加载器尽管用户可以直接应用网格工厂来启动和停止网格,但网格通常由网格加载器启动和停止。网格加载器可以在org中找到。阿帕奇。燃烧启动包,例如:
*组织。阿帕奇。燃烧启动。cmdline。命令行启动
*组织。阿帕奇。燃烧启动。servlet。服务启动
示例使用#start()方法以默认配置启动网格。你也可以使用org。阿帕奇。燃烧配置IgniteConfiguration以覆盖某些默认配置。下面是一个关于如何使用URI部署的自定义配置启动网格的示例

IgniteConfiguration cfg = new IgniteConfiguration(); 
GridUriDeployment deploySpi = new GridUriDeployment(); 
deploySpi.setUriList(Collections.singletonList("classes://tmp/output/classes")); 
cfg.setDeploymentSpi(deploySpi); 
Ignition.start(cfg);

以下是如何从SpringXML配置文件配置网格实例。下面的示例使用其他用户属性配置一个网格实例(请参见org.apache.ignite.cluster.ClusterNode#attributes()),并指定一个ignite实例名称:

<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> 
... 
<property name="igniteInstanceName" value="grid"/> 
<property name="userAttributes"> 
<map> 
<entry key="group" value="worker"/> 
</map> 
</property> 
... 
</bean>

具有上面Spring配置的网格实例可以如下启动。请注意,如果您使用的是IGNITE_HOME/config/default config,则不需要向Spring XML文件传递路径。xml。还请注意,路径可以是绝对路径,也可以是相对于IGNITE_HOME的路径

... 
Ignition.start("/path/to/spring/xml/file.xml"); 
...

您还可以直接从Spring实例化网格,而不必使用点火开关。有关更多信息,请参阅组织。阿帕奇。燃烧Springbean文档。

代码示例

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

/**
 * Initializes the factory with provided a configuration under {@code springCfgPath} that is used to start up
 * an underlying {@link Ignite} instance.
 *
 * @param springCfgPath A path to Ignite configuration.
 */
public IgniteRepositoryFactory(String springCfgPath) {
  this.ignite = Ignition.start(springCfgPath);
}

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

/**
 * Formats "TF_CLUSTER" variable to be passed into user script.
 *
 * @return Formatted "TF_CLUSTER" variable to be passed into user script.
 */
private String formatTfClusterVar() {
  return clusterSpec.format(Ignition.ignite());
}

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

List<Ignite> grids = Ignition.allGrids();
  return;
Ignition.setClientMode(true);
  ignite = Ignition.start();
} else {
  ignite = Ignition.start(configuration);

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

Ignition.start(config("server1", false, false));
Ignition.start(config("server2", false, false));
Ignition.start(config("client1", true, false));
Ignition.start(config("client2", true, false));
Ignition.start(config("client3", true, false));
Ignition.start(config("client4", true, true));
Ignition.stop("client1", true);
Ignition.stop("client2", true);
Ignition.stop("client3", true);
Ignition.stop("client4", true);
Ignition.stop("server1", true);
Ignition.stop("server2", true);

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

/**
 * @param args Args.
 * @throws Exception If failed.
 */
public static void main(String[] args) throws Exception {
  Ignition.start("modules/core/src/test/config/load/dsi-49-server-production.xml");
  IgniteCache<Long, Long> cache = Ignition.ignite("dsi").cache("PARTITIONED_CACHE");
  stats();
  for (int i = 0; i < 5000000; i++) {
    long t0 = System.currentTimeMillis();
    cnt.incrementAndGet();
    cache.get(id.incrementAndGet());
    latency.addAndGet(System.currentTimeMillis() - t0);
  }
  System.out.println("Finished test.");
  if (t != null) {
    t.interrupt();
    t.join();
  }
}

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

Ignition.setClientMode(Boolean.getBoolean("clientMode"));
Ignite ignite = Ignition.start(System.getProperty("cfg", "default-config.xml"));
  System.err.println("Wormup error");
  ex.printStackTrace(System.err);
  Ignition.stop(false);
  return;
  Ignition.stop(false);

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

Ignition.start(args.length < 4 ? "modules/core/src/test/config/load/dsi-load-client.xml" : args[3]);
  g = Ignition.ignite("dsi");
    timer.interrupt();
  Ignition.stopAll(true);

代码示例来源: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 public void close() throws IgniteException {
  Ignition.stop(igniteInstanceName, true);
}

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

/**
 * Creates instance of the HadoopIgfsInProcWithIgniteRefsCount by IGFS name.
 *
 * @param igfsName Target IGFS name.
 * @param log Log.
 * @param userName User name.
 * @return HadoopIgfsInProcWithIgniteRefsCount instance. {@code null} if the IGFS not fount in the current VM.
 */
public static HadoopIgfsInProc create(String igfsName, Log log, String userName) {
  synchronized (REF_CTR_MUX) {
    for (Ignite ignite : Ignition.allGrids()) {
      HadoopIgfsInProc delegate = create0(ignite, igfsName, log, userName);
      if (delegate != null)
        return delegate;
    }
  }
  return null;
}

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

ignites.add(Ignition.start(cfg0));
Ignition.stop(ignite.name(), false);

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

/**
 * Starts streamer.
 *
 * @throws IgniteException If failed.
 */
@Override
public void open(Configuration parameter) {
  A.notNull(igniteCfgFile, "Ignite config file");
  A.notNull(cacheName, "Cache name");
  try {
    // if an ignite instance is already started in same JVM then use it.
    this.ignite = Ignition.ignite();
  } catch (IgniteIllegalStateException e) {
    this.ignite = Ignition.start(igniteCfgFile);
  }
  this.ignite.getOrCreateCache(cacheName);
  this.log = this.ignite.log();
  this.streamer = this.ignite.dataStreamer(cacheName);
  this.streamer.autoFlushFrequency(autoFlushFrequency);
  this.streamer.allowOverwrite(allowOverwrite);
  stopped = 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

/**
 * Stop single instance.
 *
 * @param igniteInstanceName Ignite instance name,
 * @param cancel Cancel flag.
 * @return {@code True} if instance was found and stopped.
 */
public static synchronized boolean stop(@Nullable String igniteInstanceName, boolean cancel) {
  if (Ignition.stop(igniteInstanceName, cancel)) {
    PlatformProcessor old = instances.remove(igniteInstanceName);
    assert old != null;
    return true;
  }
  else
    return false;
}

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

/**
 * Ensure index is used in plan.
 *
 * @param idxName Index name.
 * @param sql SQL.
 * @param args Arguments.
 */
protected static void assertIndexUsed(String idxName, String sql, Object... args) {
  for (Ignite node : Ignition.allGrids())
    assertIndexUsed((IgniteEx)node, idxName, sql, args);
}

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

/**
 * Initializes the factory with provided a configuration under {@code springCfgPath} that is used to start up
 * an underlying {@link Ignite} instance.
 *
 * @param springCfgPath A path to Ignite configuration.
 */
public IgniteRepositoryFactory(String springCfgPath) {
  this.ignite = Ignition.start(springCfgPath);
}

代码示例来源:origin: gauravrmazra/gauravbytes

public static void main(String[] args) {
    try (Ignite ignite =  Ignition.start(defaultIgniteCfg("hello-world"))) {
      IgniteRunnable task = new IgniteRunnable() {
        private static final long serialVersionUID = 787726700536869271L;

        @IgniteInstanceResource
        private transient Ignite ignite;
        @Override
        public void run() {
          System.out.println("Hello Gaurav Bytes from: " + ignite.name());
          
        }
      };
      ignite.compute().run(task);
    }
    Ignition.stop(true);
  }
}

代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-ignite

private void startIgnite(IgniteConfiguration conf) {
  try {
    cacheManager = (IgniteEx) Ignition.ignite( gridName );
  }
  catch (IgniteIllegalStateException iise) {
    // not found, then start
    conf.setIgniteInstanceName( gridName );
    cacheManager = (IgniteEx) Ignition.start( conf );
    if ( conf.getPersistentStoreConfiguration() != null && !conf.isClientMode() ) {
      cacheManager.active( true );
    }
    stopOnExit = true;
  }
}

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

/**
 * Formats "TF_CHIEF_SERVER" variable to be passed into user script.
 *
 * @return Formatted "TF_CHIEF_SERVER" variable to be passed into user script.
 */
private String formatTfChiefServerVar() {
  List<TensorFlowServerAddressSpec> tasks = clusterSpec.getJobs().get(TensorFlowClusterResolver.CHIEF_JOB_NAME);
  if (tasks == null || tasks.size() != 1)
    throw new IllegalStateException("TensorFlow cluster specification should contain exactly one chief task");
  TensorFlowServerAddressSpec addrSpec = tasks.iterator().next();
  return "grpc://" + addrSpec.format(Ignition.ignite());
}

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

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

相关文章