ManagedApplication { public void storeAwaitingMessage( Instance instance, Message msg ) { Instance scopedInstance = InstanceHelpers.findScopedInstance( instance ); this.logger.finer( "Storing message " + msg.getClass().getSimpleName() + " for instance " + scopedInstance ); synchronized( this.scopedInstanceToAwaitingMessages ) { List<Message> messages = this.scopedInstanceToAwaitingMessages.get( scopedInstance ); if( messages == null ) { messages = new ArrayList<>( 1 ); this.scopedInstanceToAwaitingMessages.put( scopedInstance, messages ); } messages.add( msg ); } } ManagedApplication( Application application ); Map<Instance,List<Message>> getScopedInstanceToAwaitingMessages(); Application getApplication(); File getDirectory(); String getName(); Graphs getGraphs(); File getTemplateDirectory(); @Override String toString(); void storeAwaitingMessage( Instance instance, Message msg ); List<Message> removeAwaitingMessages( Instance instance ); void acknowledgeHeartBeat( Instance scopedInstance ); void checkStates( INotificationMngr notificationMngr );  }
@Test public void testStoreAwaitingMessage() { Instance rootInstance = new Instance( "root" ); Assert.assertEquals( 0, this.ma.getScopedInstanceToAwaitingMessages().size()); this.ma.storeAwaitingMessage( rootInstance, new MsgCmdSendInstances()); Assert.assertEquals( 1, this.ma.getScopedInstanceToAwaitingMessages().size()); List<Message> messages = this.ma.getScopedInstanceToAwaitingMessages().get( rootInstance ); Assert.assertEquals( 1, messages.size()); Assert.assertEquals( MsgCmdSendInstances.class, messages.get( 0 ).getClass()); Instance childInstance = new Instance( "child" ); InstanceHelpers.insertChild( rootInstance, childInstance ); this.ma.storeAwaitingMessage( childInstance, new MsgCmdAddInstance( childInstance )); Assert.assertEquals( 1, this.ma.getScopedInstanceToAwaitingMessages().size()); Assert.assertEquals( 2, messages.size()); Assert.assertEquals( MsgCmdSendInstances.class, messages.get( 0 ).getClass()); Assert.assertEquals( MsgCmdAddInstance.class, messages.get( 1 ).getClass()); childInstance.setParent( null ); this.ma.storeAwaitingMessage( childInstance, new MsgCmdRemoveInstance( childInstance )); Assert.assertEquals( 2, this.ma.getScopedInstanceToAwaitingMessages().size()); messages = this.ma.getScopedInstanceToAwaitingMessages().get( childInstance ); Assert.assertEquals( 1, messages.size()); Assert.assertEquals( MsgCmdRemoveInstance.class, messages.get( 0 ).getClass()); }