/** {@inheritDoc} */ @Override public void start(BenchmarkConfiguration cfg) throws Exception { IgniteBenchmarkArguments args = new IgniteBenchmarkArguments(); BenchmarkUtils.jcommander(cfg.commandLineArguments(), args, "<ignite-node>"); IgniteConfiguration c = loadConfiguration(args.configuration()); assert c != null; // Server node doesn't contains cache configuration. Driver will create dynamic cache. c.setCacheConfiguration(); TransactionConfiguration tc = c.getTransactionConfiguration(); tc.setDefaultTxConcurrency(args.txConcurrency()); tc.setDefaultTxIsolation(args.txIsolation()); TcpCommunicationSpi commSpi = (TcpCommunicationSpi) c.getCommunicationSpi(); if (commSpi == null) commSpi = new TcpCommunicationSpi(); c.setCommunicationSpi(commSpi); ignite = Ignition.start(c); }
/** * Executes example. * * @param args Command line arguments, none required. */ public static void main(String[] args) { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Cache star schema example started."); CacheConfiguration<Integer, FactPurchase> factCacheCfg = new CacheConfiguration<>(PARTITIONED_CACHE_NAME); factCacheCfg.setCacheMode(CacheMode.PARTITIONED); factCacheCfg.setIndexedTypes(Integer.class, FactPurchase.class); CacheConfiguration<Integer, Object> dimCacheCfg = new CacheConfiguration<>(REPLICATED_CACHE_NAME); dimCacheCfg.setCacheMode(CacheMode.REPLICATED); dimCacheCfg.setIndexedTypes( Integer.class, DimStore.class, Integer.class, DimProduct.class); try (IgniteCache<Integer, FactPurchase> factCache = ignite.getOrCreateCache(factCacheCfg); IgniteCache<Integer, Object> dimCache = ignite.getOrCreateCache(dimCacheCfg)) { populateDimensions(dimCache); populateFacts(factCache); queryStorePurchases(); queryProductPurchases(); } } }
/** * Query all purchases made at a specific store for 3 specific products. This query uses * cross-cache joins between {@link DimStore}, {@link DimProduct} objects stored in {@code * 'replicated'} cache and {@link FactPurchase} objects stored in {@code 'partitioned'} cache. * * @throws IgniteException If failed. */ private static void queryProductPurchases() { IgniteCache<Integer, FactPurchase> factCache = Ignition.ignite().cache(PARTITIONED_CACHE_NAME); // All purchases for certain product made at store2. // ================================================= DimProduct p1 = rand(dataProduct.values()); DimProduct p2 = rand(dataProduct.values()); DimProduct p3 = rand(dataProduct.values()); System.out.println( "IDs of products [p1=" + p1.getId() + ", p2=" + p2.getId() + ", p3=" + p3.getId() + ']'); // Create cross cache query to get all purchases made at store2 // for specified products. QueryCursor<Cache.Entry<Integer, FactPurchase>> prodPurchases = factCache.query( new SqlQuery( FactPurchase.class, "from \"" + REPLICATED_CACHE_NAME + "\".DimStore, \"" + REPLICATED_CACHE_NAME + "\".DimProduct, " + "\"" + PARTITIONED_CACHE_NAME + "\".FactPurchase " + "where DimStore.id=FactPurchase.storeId and DimProduct.id=FactPurchase.productId " + "and DimStore.name=? and DimProduct.id in(?, ?, ?)") .setArgs("Store2", p1.getId(), p2.getId(), p3.getId())); printQueryResults( "All purchases made at store2 for 3 specific products:", prodPurchases.getAll()); }
/** * Listen to events that happen only on local node. * * @throws IgniteException If failed. */ private static void localListen() throws IgniteException { System.out.println(); System.out.println(">>> Local event listener example."); Ignite ignite = Ignition.ignite(); IgnitePredicate<TaskEvent> lsnr = evt -> { System.out.println( "Received task event [evt=" + evt.name() + ", taskName=" + evt.taskName() + ']'); return true; // Return true to continue listening. }; // Register event listener for all local task execution events. ignite.events().localListen(lsnr, EVTS_TASK_EXECUTION); // Generate task events. ignite .compute() .withName("example-event-task") .run(() -> System.out.println("Executing sample job.")); // Unsubscribe local task event listener. ignite.events().stopLocalListen(lsnr); }
/** * Executes example. * * @param args Command line arguments, none required. * @throws Exception If example execution failed. */ public static void main(String[] args) throws Exception { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Events API example started."); // Listen to events happening on local node. localListen(); // Listen to events happening on all cluster nodes. remoteListen(); // Wait for a while while callback is notified about remaining puts. Thread.sleep(1000); } }
/** * Listen to events coming from all cluster nodes. * * @throws IgniteException If failed. */ private static void remoteListen() throws IgniteException { System.out.println(); System.out.println(">>> Remote event listener example."); // This optional local callback is called for each event notification // that passed remote predicate listener. IgniteBiPredicate<UUID, TaskEvent> locLsnr = (nodeId, evt) -> { // Remote filter only accepts tasks whose name being with "good-task" prefix. assert evt.taskName().startsWith("good-task"); System.out.println( "Received task event [evt=" + evt.name() + ", taskName=" + evt.taskName()); return true; // Return true to continue listening. }; // Remote filter which only accepts tasks whose name begins with "good-task" prefix. IgnitePredicate<TaskEvent> rmtLsnr = evt -> evt.taskName().startsWith("good-task"); Ignite ignite = Ignition.ignite(); // Register event listeners on all nodes to listen for task events. ignite.events().remoteListen(locLsnr, rmtLsnr, EVTS_TASK_EXECUTION); // Generate task events. for (int i = 0; i < 10; i++) { ignite .compute() .withName(i < 5 ? "good-task-" + i : "bad-task-" + i) .run( new IgniteRunnable() { // Auto-inject task session. @TaskSessionResource private ComputeTaskSession ses; @Override public void run() { System.out.println("Executing sample job for task: " + ses.getTaskName()); } }); } }
/** * Query all purchases made at a specific store. This query uses cross-cache joins between {@link * DimStore} objects stored in {@code 'replicated'} cache and {@link FactPurchase} objects stored * in {@code 'partitioned'} cache. * * @throws IgniteException If failed. */ private static void queryStorePurchases() { IgniteCache<Integer, FactPurchase> factCache = Ignition.ignite().cache(PARTITIONED_CACHE_NAME); // All purchases for store1. // ======================== // Create cross cache query to get all purchases made at store1. QueryCursor<Cache.Entry<Integer, FactPurchase>> storePurchases = factCache.query( new SqlQuery( FactPurchase.class, "from \"" + REPLICATED_CACHE_NAME + "\".DimStore, \"" + PARTITIONED_CACHE_NAME + "\".FactPurchase " + "where DimStore.id=FactPurchase.storeId and DimStore.name=?") .setArgs("Store1")); printQueryResults("All purchases made at store1:", storePurchases.getAll()); }
/** {@inheritDoc} */ @Override public void stop() throws Exception { Ignition.stopAll(true); }