@Test public void testRetrieveStateAndSendToATopic() { final JpaJvm mockJpaJvm = mock(JpaJvm.class); final List<JpaGroup> jpaGroupList = new ArrayList<>(); jpaGroupList.add(mock(JpaGroup.class)); jpaGroupList.add(mock(JpaGroup.class)); when(jpaGroupList.get(0).getId()).thenReturn(1L); when(jpaGroupList.get(1).getId()).thenReturn(2L); final Identifier<Jvm> id = new Identifier<>(1L); when(mockJvmCrudService.getJvm(eq(id))).thenReturn(mockJpaJvm); when(mockJpaJvm.getGroups()).thenReturn(jpaGroupList); when(mockJvmCrudService.getJvmCount(anyString())).thenReturn(6L); when(mockJvmCrudService.getJvmStartedCount(anyString())).thenReturn(3L); when(mockJvmCrudService.getJvmStoppedCount(anyString())).thenReturn(2L); when(mockJvmCrudService.getJvmForciblyStoppedCount(anyString())).thenReturn(1L); when(mockWebServerCrudService.getWebServerCount(anyString())).thenReturn(16L); when(mockWebServerCrudService.getWebServerStartedCount(anyString())).thenReturn(2L); when(mockWebServerCrudService.getWebServerStoppedCount(anyString())).thenReturn(8L); when(mockWebServerCrudService.getWebServerForciblyStoppedCount(anyString())).thenReturn(6L); groupStateNotificationServiceImpl.retrieveStateAndSend(id, Jvm.class); System.out.println(groupStateArray[0]); System.out.println(groupStateArray[1]); assertTrue(groupStateArray[0].indexOf("type=GROUP,message=,webServerCount=16,webServerStartedCount=2," + "webServerStoppedCount=8,webServerForciblyStoppedCount=6,jvmCount=6,jvmStartedCount=3,jvmStoppedCount=2," + "jvmForciblyStoppedCount=1]") > -1); assertTrue(groupStateArray[1].indexOf("type=GROUP,message=,webServerCount=16,webServerStartedCount=2," + "webServerStoppedCount=8,webServerForciblyStoppedCount=6,jvmCount=6,jvmStartedCount=3,jvmStoppedCount=2," + "jvmForciblyStoppedCount=1]") > -1); }
@Override @Async @SuppressWarnings("unchecked") public void retrieveStateAndSend(final Identifier id, final Class aClass) { LOGGER.debug("Synchronizing on {} and {}...", id, aClass); synchronized (lockObject) { LOGGER.debug("Thread locked on {} and {}...!", id, aClass); final List<JpaGroup> groups; if (Jvm.class.getName().equals(aClass.getName())) { final JpaJvm jvm = jvmCrudService.getJvm(id); groups = jvm.getGroups(); } else if (WebServer.class.getName().equals(aClass.getName())) { final JpaWebServer webServer = webServerCrudService.getWebServerAndItsGroups(id.getId()); groups = webServer.getGroups(); } else { final String errMsg = "Invalid class parameter: " + aClass.getName() + "!"; LOGGER.error(errMsg); throw new GroupStateNotificationServiceException(errMsg); } fetchStates(groups, true); } LOGGER.debug("Thread locked on {} and {} released!", id, aClass); }
GroupStateNotificationServiceImpl implements GroupStateNotificationService { @Override @Async @SuppressWarnings("unchecked") public void retrieveStateAndSend(final Identifier id, final Class aClass) { LOGGER.debug("Synchronizing on {} and {}...", id, aClass); synchronized (lockObject) { LOGGER.debug("Thread locked on {} and {}...!", id, aClass); final List<JpaGroup> groups; if (Jvm.class.getName().equals(aClass.getName())) { final JpaJvm jvm = jvmCrudService.getJvm(id); groups = jvm.getGroups(); } else if (WebServer.class.getName().equals(aClass.getName())) { final JpaWebServer webServer = webServerCrudService.getWebServerAndItsGroups(id.getId()); groups = webServer.getGroups(); } else { final String errMsg = "Invalid class parameter: " + aClass.getName() + "!"; LOGGER.error(errMsg); throw new GroupStateNotificationServiceException(errMsg); } fetchStates(groups, true); } LOGGER.debug("Thread locked on {} and {} released!", id, aClass); } }
GroupStateNotificationServiceImpl implements GroupStateNotificationService { @Override @Async @SuppressWarnings("unchecked") public void retrieveStateAndSend(final Identifier id, final Class aClass) { LOGGER.debug("Synchronizing on {} and {}...", id, aClass); synchronized (lockObject) { LOGGER.debug("Thread locked on {} and {}...!", id, aClass); final List<JpaGroup> groups; if (Jvm.class.getName().equals(aClass.getName())) { final JpaJvm jvm = jvmCrudService.getJvm(id); groups = jvm.getGroups(); } else if (WebServer.class.getName().equals(aClass.getName())) { final JpaWebServer webServer = webServerCrudService.getWebServerAndItsGroups(id.getId()); groups = webServer.getGroups(); } else { final String errMsg = "Invalid class parameter: " + aClass.getName() + "!"; LOGGER.error(errMsg); throw new GroupStateNotificationServiceException(errMsg); } fetchStates(groups, true); } LOGGER.debug("Thread locked on {} and {} released!", id, aClass); } GroupStateNotificationServiceImpl(final GroupCrudService groupCrudService, JvmCrudService jvmCrudService,
                                             final WebServerCrudService webServerCrudService, final MessagingService messagingService); }
GroupStateNotificationServiceImpl implements GroupStateNotificationService { @Override @Async @SuppressWarnings("unchecked") public void retrieveStateAndSend(final Identifier id, final Class aClass) { LOGGER.debug("Synchronizing on {} and {}...", id, aClass); synchronized (lockObject) { LOGGER.debug("Thread locked on {} and {}...!", id, aClass); final List<JpaGroup> groups; if (Jvm.class.getName().equals(aClass.getName())) { final JpaJvm jvm = jvmCrudService.getJvm(id); groups = jvm.getGroups(); } else if (WebServer.class.getName().equals(aClass.getName())) { final JpaWebServer webServer = webServerCrudService.getWebServerAndItsGroups(id.getId()); groups = webServer.getGroups(); } else { final String errMsg = "Invalid class parameter: " + aClass.getName() + "!"; LOGGER.error(errMsg); throw new GroupStateNotificationServiceException(errMsg); } fetchStates(groups, true); } LOGGER.debug("Thread locked on {} and {} released!", id, aClass); } GroupStateNotificationServiceImpl(final GroupCrudService groupCrudService, JvmCrudService jvmCrudService,
                                             final WebServerCrudService webServerCrudService, final MessagingService messagingService); @Override @Async @SuppressWarnings("unchecked") void retrieveStateAndSend(final Identifier id, final Class aClass); @Override CurrentState<Group, OperationalState> getGroupState(final String groupName); @Override Map<String, CurrentState<Group, OperationalState>> getGroupStates(); }
GroupStateNotificationServiceImpl implements GroupStateNotificationService { @Override @Async @SuppressWarnings("unchecked") public void retrieveStateAndSend(final Identifier id, final Class aClass) { LOGGER.debug("Synchronizing on {} and {}...", id, aClass); synchronized (lockObject) { LOGGER.debug("Thread locked on {} and {}...!", id, aClass); final List<JpaGroup> groups; if (Jvm.class.getName().equals(aClass.getName())) { final JpaJvm jvm = jvmCrudService.getJvm(id); groups = jvm.getGroups(); } else if (WebServer.class.getName().equals(aClass.getName())) { final JpaWebServer webServer = webServerCrudService.getWebServerAndItsGroups(id.getId()); groups = webServer.getGroups(); } else { final String errMsg = "Invalid class parameter: " + aClass.getName() + "!"; LOGGER.error(errMsg); throw new GroupStateNotificationServiceException(errMsg); } fetchStates(groups, true); } LOGGER.debug("Thread locked on {} and {} released!", id, aClass); } GroupStateNotificationServiceImpl(final GroupCrudService groupCrudService, JvmCrudService jvmCrudService,
                                             final WebServerCrudService webServerCrudService, final MessagingService messagingService); @Override @Async @SuppressWarnings("unchecked") void retrieveStateAndSend(final Identifier id, final Class aClass); @Override CurrentState<Group, OperationalState> getGroupState(final String groupName); @Override Map<String, CurrentState<Group, OperationalState>> getGroupStates();  }