/**
  * 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;
 }
  public static GlobalConfigurationBuilder defaultClusteredBuilder() {
    GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder();
    builder
        .transport()
        .transport(new JGroupsTransport())
        .asyncTransportExecutor()
        .addProperty("threadNamePrefix", "asyncTransportThread");

    return builder;
  }
  private EmbeddedCacheManager createCacheManagerProgrammatically() {
    System.out.println("####### Starting a cache manager with a programmatic configuration");

    GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder();
    builder.nonClusteredDefault();
    ConfigurationBuilder cacheBuider = new ConfigurationBuilder();
    EmbeddedCacheManager cacheManager =
        new DefaultCacheManager(builder.build(), cacheBuider.build());

    return cacheManager;
  }
  @Override
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    GlobalConfigurationBuilder lonGc = GlobalConfigurationBuilder.defaultClusteredBuilder();
    lonGc.site().localSite("LON");
    ConfigurationBuilder lon = getDefaultClusteredCacheConfig(CacheMode.LOCAL, false);
    lon.sites().addBackup().site("NYC").strategy(BackupConfiguration.BackupStrategy.SYNC);
    nycBackup = getDefaultClusteredCacheConfig(CacheMode.LOCAL, false);
    nycBackup.sites().backupFor().remoteSite("NYC").defaultRemoteCache();

    // Remember to not do nothing else other than
    // creating the cache manager in order to avoid leaks
    return TestCacheManagerFactory.createClusteredCacheManager(lonGc, lon);
  }
 public void testConfigureMarshaller() {
   GlobalConfigurationBuilder gc = new GlobalConfigurationBuilder();
   TestObjectStreamMarshaller marshaller = new TestObjectStreamMarshaller();
   gc.serialization().marshaller(marshaller);
   withCacheManager(
       new CacheManagerCallable(createCacheManager(gc, new ConfigurationBuilder())) {
         @Override
         public void call() {
           cm.getCache();
         }
       });
   marshaller.stop();
 }
  public static List createTopologyAwareCacheNodes(
      int numberOfNodes,
      CacheMode cacheMode,
      boolean transactional,
      boolean indexLocalOnly,
      boolean isRamDirectoryProvider) {
    List caches = new ArrayList();

    ConfigurationBuilder builder =
        AbstractCacheTest.getDefaultClusteredCacheConfig(cacheMode, transactional);

    builder.indexing().enable().indexLocalOnly(indexLocalOnly);

    if (isRamDirectoryProvider) {
      builder
          .indexing()
          .addProperty("default.directory_provider", "ram")
          .addProperty("lucene_version", "LUCENE_CURRENT");
    } else {
      builder
          .indexing()
          .addProperty(
              "hibernate.search.default.indexmanager",
              "org.infinispan.query.indexmanager.InfinispanIndexManager")
          .addProperty("default.directory_provider", "infinispan")
          .addProperty("hibernate.search.default.exclusive_index_use", "false")
          .addProperty("lucene_version", "LUCENE_36");
      if (cacheMode.isClustered()) {
        builder.clustering().stateTransfer().fetchInMemoryState(true);
      }
    }

    for (int i = 0; i < numberOfNodes; i++) {
      GlobalConfigurationBuilder globalConfigurationBuilder =
          GlobalConfigurationBuilder.defaultClusteredBuilder();
      globalConfigurationBuilder.transport().machineId("a" + i).rackId("b" + i).siteId("test" + i);

      EmbeddedCacheManager cm1 =
          TestCacheManagerFactory.createClusteredCacheManager(globalConfigurationBuilder, builder);

      caches.add(cm1.getCache());
    }

    return caches;
  }
 private GlobalConfigurationBuilder getSecureGlobalConfiguration() {
   GlobalConfigurationBuilder global = new GlobalConfigurationBuilder();
   global
       .security()
       .authorization()
       .enable()
       .principalRoleMapper(new IdentityRoleMapper())
       .role("admin")
       .permission(AuthorizationPermission.ALL)
       .role("query")
       .permission(AuthorizationPermission.READ)
       .permission(AuthorizationPermission.WRITE)
       .permission(AuthorizationPermission.BULK_READ)
       .role("noquery")
       .permission(AuthorizationPermission.READ)
       .permission(AuthorizationPermission.WRITE);
   return global;
 }
 /**
  * Create a cache container using the supplied configurations.
  *
  * @param globalConfigurationBuilder the global configuration builder
  * @param configurationBuilder the default cache configuration builder
  * @return the cache container
  */
 protected CacheContainer createContainer(
     GlobalConfigurationBuilder globalConfigurationBuilder,
     ConfigurationBuilder configurationBuilder) {
   GlobalConfiguration globalConfiguration = globalConfigurationBuilder.build();
   Configuration configuration = configurationBuilder.build();
   logger.debug(
       "Starting cache manager with global configuration \n{0}\nand default configuration:\n{1}",
       globalConfiguration, configuration);
   return new DefaultCacheManager(globalConfiguration, configuration);
 }
  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);
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    GlobalConfigurationBuilder that = (GlobalConfigurationBuilder) o;

    if (asyncListenerExecutor != null
        ? !asyncListenerExecutor.equals(that.asyncListenerExecutor)
        : that.asyncListenerExecutor != null) return false;
    if (asyncTransportExecutor != null
        ? !asyncTransportExecutor.equals(that.asyncTransportExecutor)
        : that.asyncTransportExecutor != null) return false;
    if (remoteCommandsExecutor != null
        ? !remoteCommandsExecutor.equals(that.remoteCommandsExecutor)
        : that.remoteCommandsExecutor != null) return false;
    if (cl != null ? !cl.equals(that.cl) : that.cl != null) return false;
    if (evictionScheduledExecutor != null
        ? !evictionScheduledExecutor.equals(that.evictionScheduledExecutor)
        : that.evictionScheduledExecutor != null) return false;
    if (globalJmxStatistics != null
        ? !globalJmxStatistics.equals(that.globalJmxStatistics)
        : that.globalJmxStatistics != null) return false;
    if (replicationQueueScheduledExecutor != null
        ? !replicationQueueScheduledExecutor.equals(that.replicationQueueScheduledExecutor)
        : that.replicationQueueScheduledExecutor != null) return false;
    if (serialization != null
        ? !serialization.equals(that.serialization)
        : that.serialization != null) return false;
    if (shutdown != null ? !shutdown.equals(that.shutdown) : that.shutdown != null) return false;
    if (site != null ? !site.equals(that.site) : that.site != null) return false;
    if (transport != null ? !transport.equals(that.transport) : that.transport != null)
      return false;

    return !(totalOrderExecutor != null
        ? !totalOrderExecutor.equals(that.totalOrderExecutor())
        : that.totalOrderExecutor != null);
  }
 @Override
 protected void createCacheManagers() throws Throwable {
   final GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
   final ConfigurationBuilder builder = getDefaultClusteredCacheConfig(getCacheMode());
   global
       .security()
       .authorization()
       .enable()
       .principalRoleMapper(new IdentityRoleMapper())
       .role("admin")
       .permission(AuthorizationPermission.ALL);
   builder.security().authorization().enable().role("admin");
   Security.doAs(
       ADMIN,
       new PrivilegedExceptionAction<Void>() {
         @Override
         public Void run() throws Exception {
           createCluster(global, builder, 2);
           waitForClusterToForm();
           return null;
         }
       });
 }
 @Test(expected = CacheException.class)
 public void testTimestampValidation() {
   Properties p = createProperties();
   final DefaultCacheManager manager =
       new DefaultCacheManager(GlobalConfigurationBuilder.defaultClusteredBuilder().build());
   try {
     InfinispanRegionFactory factory = createRegionFactory(manager, p);
     ConfigurationBuilder builder = new ConfigurationBuilder();
     builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC);
     manager.defineConfiguration("timestamps", builder.build());
     factory.start(null, p);
     fail("Should have failed saying that invalidation is not allowed for timestamp caches.");
   } finally {
     TestingUtil.killCacheManagers(manager);
   }
 }
  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);
  }
 @Test(expectedExceptions = CacheConfigurationException.class)
 public void testClusterNameNull() {
   GlobalConfigurationBuilder gc = new GlobalConfigurationBuilder();
   gc.transport().clusterName(null).build();
 }
Beispiel #16
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;
  }