Пример #1
0
  @Test
  public void readVariables() {
    String xml =
        "<hazelcast>\n"
            + "    <semaphore name=\"${name}\">\n"
            + "        <initial-permits>${initial.permits}</initial-permits>\n"
            + "        <backup-count>${backupcount.part1}${backupcount.part2}</backup-count>\n"
            + "        <async-backup-count>${notreplaced}</async-backup-count>\n"
            + "    </semaphore>"
            + "</hazelcast>";
    ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
    XmlConfigBuilder configBuilder = new XmlConfigBuilder(bis);

    Properties properties = new Properties();
    properties.setProperty("name", "s");
    properties.setProperty("initial.permits", "25");
    properties.setProperty("backupcount.part1", "1");
    properties.setProperty("backupcount.part2", "0");
    configBuilder.setProperties(properties);

    Config config = configBuilder.build();
    SemaphoreConfig semaphoreConfig = config.getSemaphoreConfig("s");
    assertEquals(25, semaphoreConfig.getInitialPermits());
    assertEquals(10, semaphoreConfig.getBackupCount());
    assertEquals(0, semaphoreConfig.getAsyncBackupCount());
  }
Пример #2
0
 public SemaphoreConfig findSemaphoreConfig(String name) {
   String baseName = getBaseName(name);
   SemaphoreConfig config = lookupByPattern(semaphoreConfigs, baseName);
   if (config != null) {
     return config.getAsReadOnly();
   }
   return getSemaphoreConfig("default").getAsReadOnly();
 }
Пример #3
0
 @Test
 public void readSemaphoreConfig() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
           + "    <semaphore name=\"default\">\n"
           + "        <initial-permits>1</initial-permits>\n"
           + "    </semaphore>"
           + "    <semaphore name=\"custom\">\n"
           + "        <initial-permits>10</initial-permits>\n"
           + "    </semaphore>"
           + "</hazelcast>";
   Config config = buildConfig(xml);
   SemaphoreConfig defaultConfig = config.getSemaphoreConfig("default");
   SemaphoreConfig customConfig = config.getSemaphoreConfig("custom");
   assertEquals(1, defaultConfig.getInitialPermits());
   assertEquals(10, customConfig.getInitialPermits());
 }
Пример #4
0
 /**
  * Returns the SemaphoreConfig for the given name
  *
  * @param name name of the semaphore config
  * @return SemaphoreConfig
  */
 public SemaphoreConfig getSemaphoreConfig(String name) {
   String baseName = getBaseName(name);
   SemaphoreConfig config = lookupByPattern(semaphoreConfigs, baseName);
   if (config != null) {
     return config;
   }
   SemaphoreConfig defConfig = semaphoreConfigs.get("default");
   if (defConfig == null) {
     defConfig = new SemaphoreConfig();
     defConfig.setName("default");
     addSemaphoreConfig(defConfig);
   }
   config = new SemaphoreConfig(defConfig);
   config.setName(name);
   addSemaphoreConfig(config);
   return config;
 }
Пример #5
0
 @Test
 public void readSemaphoreConfig() {
   String xml =
       HAZELCAST_START_TAG
           + "    <semaphore name=\"default\">\n"
           + "        <initial-permits>1</initial-permits>\n"
           + "    </semaphore>"
           + "    <semaphore name=\"custom\">\n"
           + "        <initial-permits>10</initial-permits>\n"
           + "    </semaphore>"
           + "</hazelcast>";
   Config config = buildConfig(xml);
   SemaphoreConfig defaultConfig = config.getSemaphoreConfig("default");
   SemaphoreConfig customConfig = config.getSemaphoreConfig("custom");
   assertEquals(1, defaultConfig.getInitialPermits());
   assertEquals(10, customConfig.getInitialPermits());
 }
Пример #6
0
 @Test
 public void readSemaphoreConfig() {
   String xml =
       "<hazelcast>\n"
           + "    <semaphore name=\"default\">\n"
           + "        <initial-permits>1</initial-permits>\n"
           + "    </semaphore>"
           + "    <semaphore name=\"custom\">\n"
           + "        <initial-permits>10</initial-permits>\n"
           + "        <semaphore-factory enabled=\"true\">"
           + "             <class-name>com.acme.MySemaphore</class-name>\n"
           + "        </semaphore-factory>"
           + "    </semaphore>"
           + "</hazelcast>";
   Config config = buildConfig(xml);
   SemaphoreConfig defaultConfig = config.getSemaphoreConfig("default");
   SemaphoreConfig customConfig = config.getSemaphoreConfig("custom");
   assertEquals(1, defaultConfig.getInitialPermits());
   assertEquals(10, customConfig.getInitialPermits());
 }
Пример #7
0
 /**
  * Adds a new SemaphoreConfig by name
  *
  * @param semaphoreConfig semaphore config to add
  * @return this config instance
  */
 public Config addSemaphoreConfig(SemaphoreConfig semaphoreConfig) {
   this.semaphoreConfigs.put(semaphoreConfig.getName(), semaphoreConfig);
   return this;
 }