コード例 #1
0
  /**
   * Start grid with IGFS.
   *
   * @param gridName Grid name.
   * @param igfsName IGFS name
   * @param mode IGFS mode.
   * @param secondaryFs Secondary file system (optional).
   * @param restCfg Rest configuration string (optional).
   * @return Started grid instance.
   * @throws Exception If failed.
   */
  protected Ignite startGridWithIgfs(
      String gridName,
      String igfsName,
      IgfsMode mode,
      @Nullable IgfsSecondaryFileSystem secondaryFs,
      @Nullable IgfsIpcEndpointConfiguration restCfg)
      throws Exception {
    FileSystemConfiguration igfsCfg = new FileSystemConfiguration();

    igfsCfg.setDataCacheName("dataCache");
    igfsCfg.setMetaCacheName("metaCache");
    igfsCfg.setName(igfsName);
    igfsCfg.setBlockSize(IGFS_BLOCK_SIZE);
    igfsCfg.setDefaultMode(mode);
    igfsCfg.setIpcEndpointConfiguration(restCfg);
    igfsCfg.setSecondaryFileSystem(secondaryFs);
    igfsCfg.setPrefetchBlocks(PREFETCH_BLOCKS);
    igfsCfg.setSequentialReadsBeforePrefetch(SEQ_READS_BEFORE_PREFETCH);

    CacheConfiguration dataCacheCfg = defaultCacheConfiguration();

    dataCacheCfg.setName("dataCache");
    dataCacheCfg.setCacheMode(PARTITIONED);
    dataCacheCfg.setNearConfiguration(null);
    dataCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(2));
    dataCacheCfg.setBackups(0);
    dataCacheCfg.setAtomicityMode(TRANSACTIONAL);
    dataCacheCfg.setOffHeapMaxMemory(0);

    CacheConfiguration metaCacheCfg = defaultCacheConfiguration();

    metaCacheCfg.setName("metaCache");
    metaCacheCfg.setCacheMode(REPLICATED);
    metaCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    metaCacheCfg.setAtomicityMode(TRANSACTIONAL);

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setGridName(gridName);

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));

    cfg.setDiscoverySpi(discoSpi);
    cfg.setCacheConfiguration(dataCacheCfg, metaCacheCfg);
    cfg.setFileSystemConfiguration(igfsCfg);

    cfg.setLocalHost("127.0.0.1");
    cfg.setConnectorConfiguration(null);

    return G.start(cfg);
  }
コード例 #2
0
  /**
   * Executes example.
   *
   * @param args Command line arguments, none required.
   */
  public static void main(String[] args) {
    try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) {
      System.out.println();
      System.out.println(">>> Portable objects cache put-get example started.");

      CacheConfiguration<Integer, Organization> cfg = new CacheConfiguration<>();

      cfg.setCacheMode(CacheMode.PARTITIONED);
      cfg.setName(CACHE_NAME);
      cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);

      try (IgniteCache<Integer, Organization> cache = ignite.createCache(cfg)) {
        if (ignite.cluster().forDataNodes(cache.getName()).nodes().isEmpty()) {
          System.out.println();
          System.out.println(">>> This example requires remote cache node nodes to be started.");
          System.out.println(">>> Please start at least 1 remote cache node.");
          System.out.println(">>> Refer to example's javadoc for details on configuration.");
          System.out.println();

          return;
        }

        putGet(cache);
        putGetPortable(cache);
        putGetAll(cache);
        putGetAllPortable(cache);

        System.out.println();
      } finally {
        // Delete cache with its content completely.
        ignite.destroyCache(CACHE_NAME);
      }
    }
  }
コード例 #3
0
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(IP_FINDER);

    cfg.getTransactionConfiguration().setTxSerializableEnabled(true);

    cfg.setDiscoverySpi(disco);

    BasicWarmupClosure warmupClosure = new BasicWarmupClosure();

    warmupClosure.setGridCount(2);
    warmupClosure.setIterationCount(10);
    warmupClosure.setKeyRange(10);

    cfg.setWarmupClosure(warmupClosure);

    CacheConfiguration<Integer, Integer> cacheCfg = new CacheConfiguration<>();

    cacheCfg.setCacheMode(CacheMode.PARTITIONED);
    cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    cacheCfg.setBackups(1);
    cacheCfg.setName("test");

    cfg.setCacheConfiguration(cacheCfg);

    return cfg;
  }
コード例 #4
0
ファイル: DumbWorker.java プロジェクト: caricah/iotracah
  /**
   * <code>initiate</code> starts the operations of this system handler. All excecution code for the
   * plugins is expected to begin at this point.
   *
   * @throws UnRetriableException
   */
  @Override
  public void initiate() throws UnRetriableException {

    // Initiate the session reset manager.
    SessionResetManager sessionResetManager = new SessionResetManager();
    sessionResetManager.setWorker(this);
    sessionResetManager.setDatastore(this.getDatastore());
    setSessionResetManager(sessionResetManager);

    String igniteCacheName = "dumbTester";

    CacheConfiguration clCfg = new CacheConfiguration();

    clCfg.setName(igniteCacheName);
    clCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    clCfg.setCacheMode(CacheMode.PARTITIONED);
    clCfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);

    LruEvictionPolicy lruEvictionPolicy = new LruEvictionPolicy(5170000);
    clCfg.setEvictionPolicy(lruEvictionPolicy);

    clCfg.setSwapEnabled(true);

    // if(subscriptions instanceof  IgniteCache) {
    // subscriptions = getIgnite().createCache(clCfg);
    // }

    // Initiate unirest properties.
    Unirest.setTimeouts(5000, 5000);
  }
コード例 #5
0
  /**
   * @param gridName Grid name.
   * @return Cache configuration.
   * @throws Exception In case of error.
   */
  @SuppressWarnings("unchecked")
  protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
    CacheConfiguration cfg = defaultCacheConfiguration();

    CacheStore<?, ?> store = cacheStore();

    if (store != null) {
      cfg.setCacheStoreFactory(new TestStoreFactory());
      cfg.setReadThrough(true);
      cfg.setWriteThrough(true);
      cfg.setLoadPreviousValue(true);
    }

    cfg.setSwapEnabled(swapEnabled());
    cfg.setCacheMode(cacheMode());
    cfg.setAtomicityMode(atomicityMode());
    cfg.setWriteSynchronizationMode(writeSynchronization());
    cfg.setNearConfiguration(nearConfiguration());

    Class<?>[] idxTypes = indexedTypes();

    if (!F.isEmpty(idxTypes)) cfg.setIndexedTypes(idxTypes);

    if (cacheMode() == PARTITIONED) cfg.setBackups(1);

    return cfg;
  }
コード例 #6
0
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(gridName);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(ipFinder);

    c.setDiscoverySpi(disco);

    // Cache.
    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(CacheMode.PARTITIONED);
    cc.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    cc.setNearConfiguration(null);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setRebalanceMode(SYNC);
    cc.setSwapEnabled(false);
    cc.setSqlFunctionClasses(GridQueryParsingTest.class);
    cc.setIndexedTypes(
        String.class, Address.class,
        String.class, Person.class);

    c.setCacheConfiguration(cc);

    return c;
  }
コード例 #7
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);
  }
コード例 #8
0
ファイル: AgentClusterDemo.java プロジェクト: pires/ignite
  /** Configure cacheEmployee. */
  private static <K, V> CacheConfiguration<K, V> cacheEmployee() {
    CacheConfiguration<K, V> ccfg = cacheConfiguration(EMPLOYEE_CACHE_NAME);

    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setBackups(1);

    // Configure cacheEmployee types.
    Collection<QueryEntity> qryEntities = new ArrayList<>();

    // EMPLOYEE.
    QueryEntity type = new QueryEntity();

    qryEntities.add(type);

    type.setKeyType(Integer.class.getName());
    type.setValueType(Employee.class.getName());

    // Query fields for EMPLOYEE.
    LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>();

    qryFlds.put("id", "java.lang.Integer");
    qryFlds.put("departmentId", "java.lang.Integer");
    qryFlds.put("managerId", "java.lang.Integer");
    qryFlds.put("firstName", "java.lang.String");
    qryFlds.put("lastName", "java.lang.String");
    qryFlds.put("email", "java.lang.String");
    qryFlds.put("phoneNumber", "java.lang.String");
    qryFlds.put("hireDate", "java.sql.Date");
    qryFlds.put("job", "java.lang.String");
    qryFlds.put("salary", "java.lang.Double");

    type.setFields(qryFlds);

    // Indexes for EMPLOYEE.
    Collection<QueryIndex> indexes = new ArrayList<>();

    QueryIndex idx = new QueryIndex();

    idx.setName("EMP_NAMES");
    idx.setIndexType(QueryIndexType.SORTED);
    LinkedHashMap<String, Boolean> indFlds = new LinkedHashMap<>();

    indFlds.put("firstName", Boolean.FALSE);
    indFlds.put("lastName", Boolean.FALSE);

    idx.setFields(indFlds);

    indexes.add(idx);
    indexes.add(new QueryIndex("salary", QueryIndexType.SORTED, false, "EMP_SALARY"));

    type.setIndexes(indexes);

    ccfg.setQueryEntities(qryEntities);

    return ccfg;
  }
コード例 #9
0
  /** @return Cache configuration. */
  protected CacheConfiguration cacheConfiguration() {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setCacheMode(PARTITIONED);
    cfg.setBackups(1);
    cfg.setNearConfiguration(nearConfiguration());
    cfg.setWriteSynchronizationMode(FULL_SYNC);
    cfg.setAtomicityMode(atomicityMode);

    return cfg;
  }
コード例 #10
0
  /**
   * @param name Cache name.
   * @param cacheMode Cache mode.
   * @param parts Number of partitions.
   * @return Cache configuration.
   */
  private CacheConfiguration cacheConfiguration(String name, CacheMode cacheMode, int parts) {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName(name);
    ccfg.setCacheMode(cacheMode);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    if (cacheMode == PARTITIONED) ccfg.setBackups(1);

    ccfg.setAffinity(new RendezvousAffinityFunction(false, parts));

    return ccfg;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(gridName);

    CacheConfiguration atomicCacheCfg = cacheConfiguration0();

    atomicCacheCfg.setName(CACHE_ATOMIC);
    atomicCacheCfg.setAtomicityMode(ATOMIC);
    atomicCacheCfg.setAtomicWriteOrderMode(PRIMARY);

    CacheConfiguration atomicOffheapCacheCfg = offheapCacheConfiguration0();

    atomicOffheapCacheCfg.setName(CACHE_ATOMIC_OFFHEAP);
    atomicOffheapCacheCfg.setAtomicityMode(ATOMIC);
    atomicOffheapCacheCfg.setAtomicWriteOrderMode(PRIMARY);

    CacheConfiguration atomicOffheapTieredCacheCfg = offheapTieredCacheConfiguration();

    atomicOffheapTieredCacheCfg.setName(CACHE_ATOMIC_OFFHEAP_TIERED);
    atomicOffheapTieredCacheCfg.setAtomicityMode(ATOMIC);
    atomicOffheapTieredCacheCfg.setAtomicWriteOrderMode(PRIMARY);

    c.setCacheConfiguration(
        cacheConfiguration(),
        offheapCacheConfiguration(),
        offheapTieredCacheConfiguration(),
        atomicCacheCfg,
        atomicOffheapCacheCfg,
        atomicOffheapTieredCacheCfg);

    c.setSwapSpaceSpi(new FileSwapSpaceSpi());

    c.setPeerClassLoadingEnabled(peerClassLoading());

    return c;
  }
コード例 #12
0
  /**
   * Executes example.
   *
   * @param args Command line arguments, none required.
   * @throws IgniteException If example execution failed.
   */
  public static void main(String[] args) throws IgniteException {
    ExamplesUtils.checkMinMemory(MIN_MEMORY);

    // To start ignite with desired configuration uncomment the appropriate line.
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
      System.out.println();
      System.out.println(">>> Cache store example started.");

      CacheConfiguration<Long, Person> cacheCfg = new CacheConfiguration<>(CACHE_NAME);

      // Set atomicity as transaction, since we are showing transactions in example.
      cacheCfg.setAtomicityMode(TRANSACTIONAL);

      // Configure JDBC store.
      cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(CacheJdbcPersonStore.class));

      // Configure JDBC session listener.
      cacheCfg.setCacheStoreSessionListenerFactories(
          new Factory<CacheStoreSessionListener>() {
            @Override
            public CacheStoreSessionListener create() {
              CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();

              lsnr.setDataSource(CacheJdbcPersonStore.DATA_SRC);

              return lsnr;
            }
          });

      cacheCfg.setReadThrough(true);
      cacheCfg.setWriteThrough(true);

      try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheCfg)) {
        // Make initial cache loading from persistent store. This is a
        // distributed operation and will call CacheStore.loadCache(...)
        // method on all nodes in topology.
        loadCache(cache);

        // Start transaction and execute several cache operations with
        // read/write-through to persistent store.
        executeTransaction(cache);
      }
    }
  }
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(gridName);

    TransactionConfiguration txCfg = c.getTransactionConfiguration();

    txCfg.setDefaultTxConcurrency(txConcurrency);
    txCfg.setDefaultTxIsolation(txIsolation);
    txCfg.setTxSerializableEnabled(true);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(cacheMode());
    cc.setAtomicityMode(TRANSACTIONAL);

    cc.setSwapEnabled(false);

    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

    cc.setEvictionPolicy(plc);
    cc.setEvictSynchronizedKeyBufferSize(1);

    cc.setEvictSynchronized(true);

    if (testStore != null) {
      cc.setCacheStoreFactory(singletonFactory(testStore));
      cc.setReadThrough(true);
      cc.setWriteThrough(true);
      cc.setLoadPreviousValue(true);
    } else cc.setCacheStoreFactory(null);

    c.setCacheConfiguration(cc);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(ipFinder);

    c.setDiscoverySpi(disco);

    return c;
  }
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(gridName);

    TcpDiscoverySpi spi = new TcpDiscoverySpi();

    spi.setIpFinder(ipFinder);

    c.setDiscoverySpi(spi);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setName("test");
    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setNearConfiguration(null);

    c.setCacheConfiguration(cc);

    return c;
  }
コード例 #15
0
  /** {@inheritDoc} */
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(gridName);

    TcpDiscoverySpi disco = new TcpDiscoverySpi();

    disco.setIpFinder(ipFinder);

    c.setDiscoverySpi(disco);

    CacheConfiguration<?, ?> cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setBackups(1);
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setAtomicityMode(TRANSACTIONAL);
    cc.setIndexedTypes(Integer.class, Integer.class);

    c.setCacheConfiguration(cc);

    return c;
  }
コード例 #16
0
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  @Override
  protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    ((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);

    OptimizedMarshaller marsh = new OptimizedMarshaller();
    marsh.setRequireSerializable(false);

    cfg.setMarshaller(marsh);

    CacheConfiguration ccfg = defaultCacheConfiguration();
    ccfg.setCacheMode(CacheMode.PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setWriteSynchronizationMode(PRIMARY_SYNC);
    ccfg.setNearConfiguration(null);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
  }