예제 #1
0
 /**
  * Create the global configuration.
  *
  * @return the global configuration.
  */
 protected GlobalConfigurationBuilder createGlobalConfigurationBuilder() {
   GlobalConfigurationBuilder global = new GlobalConfigurationBuilder();
   global.globalJmxStatistics().allowDuplicateDomains(true);
   // TODO author=Horia Chiorean date=7/26/12 description=MODE-1524 - Currently we don't use
   // advanced externalizers
   // global =
   // global.fluent().serialization().addAdvancedExternalizer(Schematic.externalizers()).build();
   return global;
 }
예제 #2
0
  protected static EmbeddedCacheManager createCacheManager() throws Exception {
    GlobalConfigurationBuilder gcfg = new GlobalConfigurationBuilder();
    gcfg.globalJmxStatistics().allowDuplicateDomains(true);

    ConfigurationBuilder cfg = new ConfigurationBuilder();
    cfg.transaction()
        .transactionMode(TransactionMode.TRANSACTIONAL)
        .indexing()
        .index(Index.ALL)
        .addProperty("default.directory_provider", "ram")
        .addProperty(
            "error_handler",
            "org.infinispan.all.embeddedquery.testdomain.StaticTestingErrorHandler")
        .addProperty("lucene_version", "LUCENE_CURRENT");

    EmbeddedCacheManager cm = new DefaultCacheManager(gcfg.build(), cfg.build());

    return cm;
  }
  @BeforeClass
  public static void beforeclass() {
    GlobalConfigurationBuilder globalConfigurationBuilder =
        new GlobalConfigurationBuilder().nonClusteredDefault();
    globalConfigurationBuilder.globalJmxStatistics().jmxDomain("infinispan-" + UUID.randomUUID());

    ConfigurationBuilder cacheConfiguration = new ConfigurationBuilder();
    cacheConfiguration.dataContainer().keyEquivalence(new AnyServerEquivalence());

    serverCache = new DefaultCacheManager(globalConfigurationBuilder.build());
    serverCache.defineConfiguration("sessions", cacheConfiguration.build());

    HotRodServerConfigurationBuilder hotRodServerConfigurationBuilder =
        new HotRodServerConfigurationBuilder();
    hotRodServerConfigurationBuilder.port(RemoteConfiguration.SERVER_PORT);

    server = new HotRodServer();
    server.start(hotRodServerConfigurationBuilder.build(), serverCache);
  }
  protected void initEmbedded() {
    GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder();

    boolean clustered = config.getBoolean("clustered", false);
    boolean async = config.getBoolean("async", true);
    boolean allowDuplicateJMXDomains = config.getBoolean("allowDuplicateJMXDomains", true);

    if (clustered) {
      gcb.transport().defaultTransport();
    }
    gcb.globalJmxStatistics().allowDuplicateDomains(allowDuplicateJMXDomains);

    cacheManager = new DefaultCacheManager(gcb.build());
    containerManaged = false;

    logger.debug("Started embedded Infinispan cache container");

    ConfigurationBuilder invalidationConfigBuilder = new ConfigurationBuilder();
    if (clustered) {
      invalidationConfigBuilder
          .clustering()
          .cacheMode(async ? CacheMode.INVALIDATION_ASYNC : CacheMode.INVALIDATION_SYNC);
    }
    Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build();

    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.REALM_CACHE_NAME, invalidationCacheConfiguration);
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.USER_CACHE_NAME, invalidationCacheConfiguration);

    ConfigurationBuilder sessionConfigBuilder = new ConfigurationBuilder();
    if (clustered) {
      String sessionsMode = config.get("sessionsMode", "distributed");
      if (sessionsMode.equalsIgnoreCase("replicated")) {
        sessionConfigBuilder
            .clustering()
            .cacheMode(async ? CacheMode.REPL_ASYNC : CacheMode.REPL_SYNC);
      } else if (sessionsMode.equalsIgnoreCase("distributed")) {
        sessionConfigBuilder
            .clustering()
            .cacheMode(async ? CacheMode.DIST_ASYNC : CacheMode.DIST_SYNC);
      } else {
        throw new RuntimeException("Invalid value for sessionsMode");
      }

      sessionConfigBuilder
          .clustering()
          .hash()
          .numOwners(config.getInt("sessionsOwners", 2))
          .numSegments(config.getInt("sessionsSegments", 60))
          .build();
    }

    Configuration sessionCacheConfiguration = sessionConfigBuilder.build();
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.SESSION_CACHE_NAME, sessionCacheConfiguration);
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.OFFLINE_SESSION_CACHE_NAME, sessionCacheConfiguration);
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.LOGIN_FAILURE_CACHE_NAME, sessionCacheConfiguration);

    ConfigurationBuilder replicationConfigBuilder = new ConfigurationBuilder();
    if (clustered) {
      replicationConfigBuilder
          .clustering()
          .cacheMode(async ? CacheMode.REPL_ASYNC : CacheMode.REPL_SYNC);
    }
    Configuration replicationCacheConfiguration = replicationConfigBuilder.build();
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.WORK_CACHE_NAME, replicationCacheConfiguration);

    ConfigurationBuilder counterConfigBuilder = new ConfigurationBuilder();
    counterConfigBuilder
        .invocationBatching()
        .enable()
        .transaction()
        .transactionMode(TransactionMode.TRANSACTIONAL);
    counterConfigBuilder
        .transaction()
        .transactionManagerLookup(new DummyTransactionManagerLookup());
    counterConfigBuilder.transaction().lockingMode(LockingMode.PESSIMISTIC);
    Configuration counterCacheConfiguration = counterConfigBuilder.build();

    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.VERSION_CACHE_NAME, counterCacheConfiguration);
  }
예제 #5
0
  @Bean
  public SpringEmbeddedCacheManagerFactoryBean cacheManagerFactoryBean() throws Exception {
    // JGroups settings
    String jgroupsConfigurationFile = environment.getRequiredProperty("jgroups.configurationFile");
    if ("jgroups-ec2.xml".equals(jgroupsConfigurationFile)) {
      ClassConfigurator.addProtocol((short) 1000, S3_CLIENT_PING.class);

      EC2MetadataClient metadataClient = new EC2MetadataClient();
      String ipAddress = metadataClient.readResource("/latest/meta-data/local-ipv4");
      logger.info("jgroups.tcp.address -> {}", ipAddress);
      System.setProperty("jgroups.tcp.address", ipAddress);
      System.setProperty("jgroups.s3.bucket", environment.getRequiredProperty("jgroups.s3.bucket"));
    }

    ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder();

    GlobalConfigurationBuilder globalBuilder = holder.getGlobalConfigurationBuilder();
    // @formatter:off
    globalBuilder
        .globalJmxStatistics()
        .enable()
        //				.cacheManagerName("HibernateSearch")
        .allowDuplicateDomains(true)
        .transport()
        .defaultTransport()
        //				.clusterName("wallride-cluster")
        .addProperty("configurationFile", jgroupsConfigurationFile);
    // @formatter:on

    Properties props = new Properties();
    props.put("hibernate.search.default.directory_provider", "infinispan");
    //		props.put("hibernate.search.default.indexmanager",
    // InfinispanIndexManager.class.getCanonicalName());
    props.put("hibernate.search.default.indexmanager", "near-real-time");
    props.put("hibernate.search.default.exclusive_index_use", "false");

    ConfigurationBuilder defaultBuilder = holder.getDefaultConfigurationBuilder();

    JdbcStringBasedStoreConfigurationBuilder jdbcBuilder =
        new JdbcStringBasedStoreConfigurationBuilder(defaultBuilder.persistence());
    //		JdbcStringBasedCacheStoreConfigurationBuilder jdbcBuilder = new
    // JdbcStringBasedCacheStoreConfigurationBuilder(defaultBuilder.loaders());
    // @formatter:off
    jdbcBuilder
        .key2StringMapper(LuceneKey2StringMapper.class)
        .table()
        .tableNamePrefix("ispn_string_table")
        .idColumnName("id_column")
        .idColumnType("varchar(255)")
        .dataColumnName("data_column")
        .dataColumnType("longblob")
        .timestampColumnName("timestamp_column")
        .timestampColumnType("bigint")
        .dropOnExit(false)
        .createOnStart(true)
        .async()
        .enable()
        .flushLockTimeout(15000)
        .threadPoolSize(10)
        .fetchPersistentState(true)
        .ignoreModifications(false)
        .purgeOnStartup(false)
        //			.dataSource().jndiUrl("dataSource");
        .connectionFactory(InfinispanDataSourceConnectionFactoryConfigurationBuilder.class)
        .dataSource(dataSource);
    // @formatter:on

    // @formatter:off
    defaultBuilder
        .clustering()
        .cacheMode(CacheMode.DIST_SYNC)
        //			.locking()
        //				.lockAcquisitionTimeout(300000)
        //				.writeSkewCheck(false)
        //				.concurrencyLevel(500)
        //				.useLockStriping(false)
        //			.stateTransfer()
        //				.timeout(960000)
        //				.fetchInMemoryState(true)
        //			.sync()
        //			.replTimeout(480000)
        //				.jmxStatistics()
        //				.enable()
        //			.eviction()
        //				.maxEntries(-1)
        //				.strategy(EvictionStrategy.NONE)
        //				.expiration()
        //					.maxIdle(-1)
        //					.reaperEnabled(false)
        //			.indexing()
        //				.index(Index.LOCAL)
        //				.enable()
        //				.indexLocalOnly(false)
        //				.withProperties(props)
        .persistence()
        .addStore(jdbcBuilder)
        .preload(true)
        .shared(true);
    // @formatter:on

    //		ConfigurationBuilder luceneBuilder = new ConfigurationBuilder();
    //		luceneBuilder
    //			.clustering()
    //				.cacheMode(CacheMode.REPL_SYNC)
    //				.stateTransfer()
    //					.fetchInMemoryState(true)
    //				.sync()
    //					.replTimeout(480000)
    //			.indexing()
    //					.enabled(false);
    //
    //		holder.getNamedConfigurationBuilders().put("LuceneIndexesMetadata", luceneBuilder);
    //		holder.getNamedConfigurationBuilders().put("LuceneIndexesData", luceneBuilder);
    //		holder.getNamedConfigurationBuilders().put("LuceneIndexesLocking", luceneBuilder);

    ConfigurationBuilder cacheBuilder = new ConfigurationBuilder();
    // @formatter:off
    cacheBuilder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC).indexing().index(Index.NONE);
    //			.persistence()
    //				.clearStores();
    // @formatter:on

    holder.getNamedConfigurationBuilders().put("blogs", cacheBuilder);
    //		holder.getNamedConfigurationBuilders().put("settings", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("popularPosts", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("articles", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("categories", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("pages", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("medias", cacheBuilder);
    holder.getNamedConfigurationBuilders().put("banners", cacheBuilder);

    //		holder.getNamedConfigurationBuilders().put("resources", cacheBuilder);

    //		final EmbeddedCacheManager embeddedCacheManager = new
    // DefaultCacheManager(globalBuilder.build(), cacheBuilder.build());
    final EmbeddedCacheManager embeddedCacheManager = new DefaultCacheManager(holder, true);

    InfinispanSingletonCacheManagerDirectoryProvider.cacheManager = embeddedCacheManager;

    SpringEmbeddedCacheManagerFactoryBean factory =
        new SpringEmbeddedCacheManagerFactoryBean() {
          @Override
          protected EmbeddedCacheManager createBackingEmbeddedCacheManager() throws IOException {
            return embeddedCacheManager;
          }
        };
    return factory;
  }