Esempio n. 1
0
 /**
  * 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);
 }
  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;
  }
Esempio n. 3
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);
  }