Beispiel #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());
 }
 /** 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);
   }
 }
Beispiel #4
0
 void log(String msg) {
   if (msg != null) {
     logger.info(msg);
     topicLogs.publish(memberString + ": " + msg);
   }
 }
Beispiel #5
0
 private void firePositionViewChanged(PositionView positionView) {
   if (positionView == null) return;
   countPositionViews.incrementAndGet();
   ITopic topicPM = hazelcast.getTopic("pm_" + positionView.pmId);
   topicPM.publish(positionView);
 }