Example #1
0
 public QueueConfig findQueueConfig(String name) {
   String baseName = getBaseName(name);
   QueueConfig config = lookupByPattern(queueConfigs, baseName);
   if (config != null) {
     return config.getAsReadOnly();
   }
   return getQueueConfig("default").getAsReadOnly();
 }
Example #2
0
  @BeforeClass
  public static void init() {
    Config config = new Config();

    QueueConfig queueConfig = config.getQueueConfig(queueForTestQueueWithSizeLimit);
    queueConfig.setMaxSize(maxSizeForQueue);

    queueConfig = config.getQueueConfig(queueForTestOfferPoll);
    queueConfig.setMaxSize(maxSizeForQueue);

    server = Hazelcast.newHazelcastInstance(config);
    client = HazelcastClient.newHazelcastClient();
  }
Example #3
0
 public QueueConfig getQueueConfig(String name) {
   String baseName = getBaseName(name);
   QueueConfig config = lookupByPattern(queueConfigs, baseName);
   if (config != null) {
     return config;
   }
   QueueConfig defConfig = queueConfigs.get("default");
   if (defConfig == null) {
     defConfig = new QueueConfig();
     defConfig.setName("default");
     addQueueConfig(defConfig);
   }
   config = new QueueConfig(defConfig);
   config.setName(name);
   addQueueConfig(config);
   return config;
 }
Example #4
0
 @Test
 public void shouldCreateQueue() throws InterruptedException {
   // Given
   int numberOfEvents = 5;
   Config config = new Config();
   QueueStoreConfig jdbcBackedQueueConfig =
       QueueStoreConfigFactory.getJdbcBackedQueueConfig(dataSource(), queueName);
   QueueConfig messageQueue = config.getQueueConfig(queueName);
   messageQueue.setQueueStoreConfig(jdbcBackedQueueConfig);
   HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
   // When
   QueueStore storeImplementation = jdbcBackedQueueConfig.getStoreImplementation();
   for (long i = 0; i < numberOfEvents; i++) {
     storeImplementation.store(i, String.valueOf(i));
   }
   IQueue<String> iQueue = hazelcastInstance.getQueue(queueName);
   MatcherAssert.assertThat(iQueue.size(), CoreMatchers.equalTo(numberOfEvents));
   String actual = iQueue.take();
   MatcherAssert.assertThat(actual, CoreMatchers.equalTo("0"));
   hazelcastInstance.shutdown();
 }
Example #5
0
 public QueueConfig(QueueConfig config) {
   this();
   this.name = config.name;
   this.backupCount = config.backupCount;
   this.asyncBackupCount = config.asyncBackupCount;
   this.maxSize = config.maxSize;
   this.emptyQueueTtl = config.emptyQueueTtl;
   this.statisticsEnabled = config.statisticsEnabled;
   this.queueStoreConfig =
       config.queueStoreConfig != null ? new QueueStoreConfig(config.queueStoreConfig) : null;
   this.listenerConfigs = new ArrayList<ItemListenerConfig>(config.getItemListenerConfigs());
 }
 @Test
 public void testQueueConfig() {
   QueueConfig testQConfig = config.getQueueConfig("testQ");
   assertNotNull(testQConfig);
   assertEquals("testQ", testQConfig.getName());
   assertEquals(1000, testQConfig.getMaxSize());
   QueueConfig qConfig = config.getQueueConfig("q");
   assertNotNull(qConfig);
   assertEquals("q", qConfig.getName());
   assertEquals(2500, qConfig.getMaxSize());
   assertEquals(1, testQConfig.getItemListenerConfigs().size());
   ItemListenerConfig listenerConfig = testQConfig.getItemListenerConfigs().get(0);
   assertEquals("com.hazelcast.spring.DummyItemListener", listenerConfig.getClassName());
   assertTrue(listenerConfig.isIncludeValue());
 }
 @Override
 public void initialize() {
   final NodeEngine nodeEngine = getNodeEngine();
   final List<ItemListenerConfig> itemListenerConfigs = config.getItemListenerConfigs();
   for (ItemListenerConfig itemListenerConfig : itemListenerConfigs) {
     ItemListener listener = itemListenerConfig.getImplementation();
     if (listener == null && itemListenerConfig.getClassName() != null) {
       try {
         listener =
             ClassLoaderUtil.newInstance(
                 nodeEngine.getConfigClassLoader(), itemListenerConfig.getClassName());
       } catch (Exception e) {
         throw ExceptionUtil.rethrow(e);
       }
     }
     if (listener != null) {
       if (listener instanceof HazelcastInstanceAware) {
         ((HazelcastInstanceAware) listener)
             .setHazelcastInstance(nodeEngine.getHazelcastInstance());
       }
       addItemListener(listener, itemListenerConfig.isIncludeValue());
     }
   }
 }
Example #8
0
 public Config addQueueConfig(QueueConfig queueConfig) {
   queueConfigs.put(queueConfig.getName(), queueConfig);
   return this;
 }
 /** Test method for {@link com.hazelcast.config.QueueConfig#setName(java.lang.String)}. */
 @Test
 public void testSetName() {
   String name = "a test name";
   QueueConfig queueConfig = new QueueConfig().setName(name);
   assertEquals(name, queueConfig.getName());
 }
 /** Test method for {@link com.hazelcast.config.QueueConfig#getName()}. */
 @Test
 public void testGetName() {
   QueueConfig queueConfig = new QueueConfig();
   assertNull(null, queueConfig.getName());
 }
 protected Config createConfig() {
   Config config = new Config();
   QueueConfig queueConfig = config.getQueueConfig(queueName);
   queueConfig.setMaxSize(6);
   return config;
 }