One of the Apache-ignite entry combat

Source: Internet
Author: User
Tags apache ignite

Introduction to one of Apache-ignite's entry combat

The Apache Ignite Memory Data organization Framework is a high-performance, integrated, and distributed memory computing and transaction platform for large-scale dataset processing with higher performance than traditional disk-based or flash technologies, while providing high performance for applications and different data sources The function of data organization management in distributed memory. installation

Download the latest installation package from Https://ignite.apache.org/download.cgi#binaries, and here I am downloading the apache-ignite-fabric-2.3.0-bin.zip package. After downloading, the decompression can be used directly. Run

Go into the ${ignite_home}/bin directory, and then run

./ignite.sh ...
[00:24:04] to start Console Management & monitoring Run Ignitevisorcmd. {Sh|bat}
[00:24:04]
[00:24:04] Ignite node started OK (ID=01AF1A02)
[00:24:04] Topology snapshot [Ver=1, Servers=1, Clients=0, cpus=2, Hea P=1.0GB] ...

which
-Servers=1 indicates that there is only one node in the current Ignite cluster.
-Clients=0 indicates that no clients are currently connected to this cluster.

At this point, we can run the same command on another machine to start a Ignite, and then we can see

...
[00:41:21] Topology snapshot [ver=2, servers=2, clients=0, cpus=2, ...
] ...

You can see servers=2 that a new node has joined the cluster. Test

The Ignite cluster is already available, so let's look at how to use Ignite as a distributed caching system.

First, to establish a Maven project, the Pom.xml document reads as follows:

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:s chemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelversion >4.0.0</modelVersion> <groupId>my.ignitestudy</groupId> <artifactid>ignitestudy</ artifactid> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name> ignitestudy</name> <url>http://maven.apache.org</url> <properties> <ignite.vers Ion>2.3.0</ignite.version> <project.build.sourceencoding>utf-8</project.build.sourceencoding&
    Gt </properties> <dependencies> <dependency> <groupId>org.apache.commons< 
        /groupid> <artifactId>commons-lang3</artifactId> <version>3.1</version>
</dependency>
        <dependency> <groupId>net.sf.json-lib</groupId> <artifactid>json- Lib</artifactid> <version>2.4</version> &LT;CLASSIFIER&GT;JDK15&LT;/CLASSIFIER&G
        T </dependency> <dependency> <groupId>org.apache.ignite</groupId> & Lt;artifactid>ignite-core</artifactid> <version>${ignite.version}</version> </ dependency> <dependency> <groupId>org.apache.ignite</groupId> <ar Tifactid>ignite-spring</artifactid> <version>${ignite.version}</version> &LT;/DEP endency> <dependency> <groupId>org.apache.ignite</groupId> <artif Actid>ignite-indexing</artifactid> <version>${ignite.version}</version> </depe

 Ndency>       <dependency> <groupId>junit</groupId> &LT;ARTIFACTID&GT;JUNIT&LT;/ARTIFAC tid> <version>3.8.1</version> <scope>test</scope> </dependen cy> </dependencies> <build> <plugins> <plugin> ;groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifacti d> <version>2.3.2</version> <configuration> <s Ource>1.8</source> <target>1.8</target> <encoding>utf-8 </encoding> <compilerArguments> <extdirs>${project.basedir}/ Lib</extdirs> </compilerArguments> </configuration> <

           /plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configurati On> <descriptorRefs> <descriptorref>jar-with-dependencies</d escriptorref> </descriptorRefs> </configuration> <ex
                        Ecutions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal& gt;single</goal> </goals> </execution> </ executions> </plugin> </plugins> </build> </project>

The following is an example of how to use Cache in Java

Package My.ignitestudy.datagrid;
Import Org.apache.ignite.Ignite;
Import Org.apache.ignite.IgniteCache;
Import org.apache.ignite.Ignition;
Import org.apache.ignite.configuration.IgniteConfiguration;
Import Org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
Import Org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;

Import org.apache.ignite.transactions.Transaction;

Import Java.util.Arrays;
        public class Test {public static void main (string[] args) throws Exception {Ignite Ignite = Getignite ();
        Testgetput (ignite);
    Testatomoperation (ignite);
        private static Ignite Getignite () {Tcpdiscoveryspi SPI = new Tcpdiscoveryspi ();
        Tcpdiscoveryvmipfinder Ipfinder = new Tcpdiscoveryvmipfinder ();
        Ipfinder.setaddresses (Arrays.aslist ("192.168.0.192:47500..47509"));
        Spi.setipfinder (Ipfinder);
        Igniteconfiguration cfg = new igniteconfiguration ();
        CFG.SETDISCOVERYSPI (SPI); Cfg.setclientMode (TRUE);
        Ignite Ignite = Ignition.start (CFG);
    return ignite; } private static void Testgetput (Ignite Ignite) {ignitecache<string, string> cache = Ignite.getorcreat

        Ecache ("Mycache");
        for (int i = 0; i < i++) {cache.put ("Mykey_" + I, "myvalue_" + i);
            for (int i = 0; i < i++) {String key = "Mykey_" + i;
        System.out.println ("Got [key=" + key + ", val=" + cache.get (Key) + ']); }} private static void Testatomoperation (Ignite Ignite) {ignitecache<string, integer> cache = IGN

        Ite.getorcreatecache ("Mycache");
        Integer OldValue = cache.getandputifabsent ("MyKey", 11);

        System.out.println ("MyKey:" + oldValue);
        Boolean success = Cache.putifabsent ("MyKey", 22);

        System.out.println ("MyKey:" + success);
        OldValue = Cache.getandreplace ("MyKey", 11);

 SYSTEM.OUT.PRINTLN ("MyKey Replace:" + oldValue);       Success = Cache.replace ("MyKey", 22);

        SYSTEM.OUT.PRINTLN ("MyKey Replace:" + success);
        Success = Cache.replace ("MyKey", 2, 22);

        SYSTEM.OUT.PRINTLN ("MyKey Replace:" + success);
        Success = Cache.remove ("MyKey", 1);
    System.out.println ("MyKey Remove:" + success); }
}

In the Java code above, we use a programmatic way to connect to the cluster, as follows:

Tcpdiscoveryspi SPI = new Tcpdiscoveryspi ();
Tcpdiscoveryvmipfinder Ipfinder = new Tcpdiscoveryvmipfinder ();
Ipfinder.setaddresses (Arrays.aslist ("192.168.0.192:47500..47509"));
Spi.setipfinder (Ipfinder);
Igniteconfiguration cfg = new igniteconfiguration ();
CFG.SETDISCOVERYSPI (SPI);
Cfg.setclientmode (true);

Ignite Ignite = Ignition.start (CFG);

You can also use the specified configuration file to obtain a connection to the cluster, such as:

Ignite Ignite = Ignition.start ("... config file path ...");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.