Пример #1
0
 void init() {
   for (int i = 0; i < threads; i++) {
     esOrderConsumer.execute(new PositionQueueSlurper());
   }
   topicFeed.addMessageListener(new StockStreamListener());
   mapNewOrders.addLocalEntryListener(new NewOrderListener());
   startStreamer();
   Executors.newSingleThreadExecutor()
       .execute(
           new Runnable() {
             public void run() {
               while (true) {
                 try {
                   Thread.sleep(5000);
                   long feeds = countReceivedStockUpdates.getAndSet(0) / 5;
                   long orders = countOrdersProcessed.getAndSet(0) / 5;
                   long events = countNewOrderEvents.getAndSet(0) / 5;
                   long views = countPositionViews.getAndSet(0) / 5;
                   log(
                       "Feeds:"
                           + feeds
                           + ", OrdersProcessed:"
                           + orders
                           + ", newOrderEvents:"
                           + events
                           + ", Views:"
                           + views);
                 } catch (Exception e) {
                   e.printStackTrace();
                 }
               }
             }
           });
 }
 @Test
 public void testHazelcastInstances() {
   assertNotNull(map1);
   assertNotNull(map2);
   assertNotNull(multiMap);
   assertNotNull(queue);
   assertNotNull(topic);
   assertNotNull(set);
   assertNotNull(list);
   assertNotNull(executorService);
   assertNotNull(idGenerator);
   assertNotNull(atomicLong);
   assertNotNull(atomicReference);
   assertNotNull(countDownLatch);
   assertNotNull(semaphore);
   assertNotNull(lock);
   assertEquals("map1", map1.getName());
   assertEquals("map2", map2.getName());
   assertEquals("testMultimap", multiMap.getName());
   assertEquals("testQ", queue.getName());
   assertEquals("testTopic", topic.getName());
   assertEquals("set", set.getName());
   assertEquals("list", list.getName());
   assertEquals("idGenerator", idGenerator.getName());
   assertEquals("atomicLong", atomicLong.getName());
   assertEquals("atomicReference", atomicReference.getName());
   assertEquals("countDownLatch", countDownLatch.getName());
   assertEquals("semaphore", semaphore.getName());
 }
    /**
     * Constructs the topic listener which will listen on the given topic.
     *
     * @param topic the topic to listen to
     */
    public HzTopicListener(ITopic<byte[]> topic) {

      this.queue =
          QueueTopicProxyFactory.createQueueProxy(
              new ArrayBlockingQueue<byte[]>(config.getTopicMaxMessageCount()));
      this.msgTopic = topic;

      registrationId = topic.addMessageListener(this);
    }
    /*
     * (non-Javadoc)
     *
     * @see
     * com.hazelcast.core.MessageListener#onMessage(com.hazelcast.core.Message)
     */
    @Override
    public void onMessage(Message<byte[]> hzMsg) {
      // We always queue the message even if we have a message listener. We'll
      // immediately pull it out of the queue and dispatch in a separate thread.
      // This is important to prevent slow message handlers from blocking topic
      // distribution in Hazelcast.
      if (!queue.offer(hzMsg.getMessageObject())) {
        log.warn(
            format(
                "In-memory message buffer full for topic [%s]. "
                    + "Messages will be lost. Consider increaing the speed of "
                    + "the consumer or the message buffer.",
                msgTopic.getName()));
        return;
      }

      if (messageListener != null) {
        hazelcastMQContext.onConsumerDispatchReady(id);
      }
    }
Пример #5
0
 /** Process all events for keys queued to the watcher */
 private static void forwardToItopic(WatchEvent.Kind<Path> kind, Path dir) {
   boolean isDir = Files.isDirectory(dir);
   if (kind == ENTRY_CREATE) {
     if (!isDir) {
       Action act = new Action("add_file", Folder.getInternalPath(dir));
       // Folder.getFileFromDiskToWinSafe(act.getPath());
       Folder.loadFileFromFSToInternal(dir);
       topic.publish(act);
     } else {
       if (Folder.isEmptyFSFolder(dir)) {
         Folder.createEmptyFolderInInternal(dir);
         topic.publish(new Action("create_empty_folder", Folder.getInternalPath(dir)));
       } else {
         Folder.loadFolderFromFSToInternal(dir);
         topic.publish(new Action("create_folder", Folder.getInternalPath(dir)));
       }
     }
   } else if (kind == ENTRY_DELETE) {
     // todo
     Folder.deleteFromInternal(dir);
     topic.publish(new Action("delete_entry", Folder.getInternalPath(dir)));
   } else if (kind == ENTRY_MODIFY) {
     // todo
     if (!isDir) {
       Folder.loadFileFromFSToInternal(dir);
       topic.publish(new Action("edit_file", Folder.getInternalPath(dir)));
     } else {
       if (Folder.isEmptyFSFolder(dir)) {
         Folder.createEmptyFolderInInternal(dir);
         topic.publish(new Action("create_empty_folder", Folder.getInternalPath(dir)));
       } else {
         Folder.loadFolderFromFSToInternal(dir);
         topic.publish(new Action("edit_folder", Folder.getInternalPath(dir)));
       }
     }
   } else {
     // TODO
     System.out.println("[forwardToItopic] Unexpected Event - kind=" + kind + "dir=" + dir);
   }
 }
 public void shutdown() {
   msgTopic.removeMessageListener(registrationId);
   queue.clear();
 }
Пример #7
0
 void log(String msg) {
   if (msg != null) {
     logger.info(msg);
     topicLogs.publish(memberString + ": " + msg);
   }
 }
Пример #8
0
 private void firePositionViewChanged(PositionView positionView) {
   if (positionView == null) return;
   countPositionViews.incrementAndGet();
   ITopic topicPM = hazelcast.getTopic("pm_" + positionView.pmId);
   topicPM.publish(positionView);
 }