예제 #1
0
  /** Init. */
  @PostConstruct
  public void init() {
    logger.info("Setting up Ignite Ticket Registry...");

    configureSecureTransport();

    if (logger.isDebugEnabled()) {
      logger.debug(
          "igniteConfiguration.cacheConfiguration={}",
          this.igniteConfiguration.getCacheConfiguration());
      logger.debug(
          "igniteConfiguration.getDiscoverySpi={}", this.igniteConfiguration.getDiscoverySpi());
      logger.debug(
          "igniteConfiguration.getSslContextFactory={}",
          this.igniteConfiguration.getSslContextFactory());
    }

    if (Ignition.state() == IgniteState.STOPPED) {
      this.ignite = Ignition.start(this.igniteConfiguration);
    } else if (Ignition.state() == IgniteState.STARTED) {
      this.ignite = Ignition.ignite();
    }

    this.ticketIgniteCache =
        this.ignite.getOrCreateCache(
            casProperties.getTicket().getRegistry().getIgnite().getTicketsCache().getCacheName());
  }
  /**
   * 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());
  }
예제 #3
0
  /**
   * 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);
  }
예제 #4
0
  /**
   * Creates cache.
   *
   * @param name Cache name.
   * @param atomicityMode Atomicity mode.
   * @return Cache configuration.
   */
  private static IgniteCache createCache(String name, CacheAtomicityMode atomicityMode) {
    CacheConfiguration ccfg = new CacheConfiguration(name);

    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    return Ignition.ignite().getOrCreateCache(ccfg);
  }
  /**
   * Executes transaction with read/write-through to persistent store.
   *
   * @param cache Cache to execute transaction on.
   */
  private static void executeTransaction(IgniteCache<Long, Person> cache) {
    try (Transaction tx = Ignition.ignite().transactions().txStart()) {
      Person val = cache.get(id);

      System.out.println("Read value: " + val);

      val = cache.getAndPut(id, new Person(id, "Isaac", "Newton"));

      System.out.println("Overwrote old value: " + val);

      val = cache.get(id);

      System.out.println("Read value: " + val);

      tx.commit();
    }

    System.out.println("Read value after commit: " + cache.get(id));
  }
예제 #6
0
  /**
   * 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 run() {
   IgniteSet<ScheduledRunnable> set = Ignition.ignite(gridName).set(setName, null);
   set.add(scheduledRunnable);
 }