@ Override public final void contextInitialized ( final ServletContextEvent sce ) { if ( persistenceEnabled ) { // Load ec2 instances AbstractMockEc2Instance [ ] instanceArray = ( AbstractMockEc2Instance [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . EC2 ) ; if ( null != instanceArray ) { MockEc2Controller . getInstance ( ) . restoreAllMockEc2Instances ( Arrays . asList ( instanceArray ) ) ; } // Load Vpc MockVpc [ ] vpcArray = ( MockVpc [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . VPC ) ; if ( null != vpcArray ) { MockVpcController . getInstance ( ) . restoreAllMockVpc ( Arrays . asList ( vpcArray ) ) ; } // Load Volume MockVolume [ ] volumeArray = ( MockVolume [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . VOLUME ) ; if ( null != volumeArray ) { MockVolumeController . getInstance ( ) . restoreAllMockVolume ( Arrays . asList ( volumeArray ) ) ; } // Load Tags MockTags [ ] tagsArray = ( MockTags [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . TAGS ) ; if ( null != tagsArray ) { MockTagsController . getInstance ( ) . restoreAllMockTags ( Arrays . asList ( tagsArray ) ) ; } // Load Subnet MockSubnet [ ] subnetArray = ( MockSubnet [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . SUBNET ) ; if ( null != subnetArray ) { MockSubnetController . getInstance ( ) . restoreAllMockSubnet ( Arrays . asList ( subnetArray ) ) ; } // Load RouteTable MockRouteTable [ ] routetableArray = ( MockRouteTable [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . ROUTETABLE ) ; if ( null != routetableArray ) { MockRouteTableController . getInstance ( ) . restoreAllMockRouteTable ( Arrays . asList ( routetableArray ) ) ; } // Load Internet Gateway MockInternetGateway [ ] internetgatewayArray = ( MockInternetGateway [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . INTERNETGATEWAY ) ; if ( null != internetgatewayArray ) { MockInternetGatewayController . getInstance ( ) . restoreAllInternetGateway ( Arrays . asList ( internetgatewayArray ) ) ; } } // start a timer for cleaning up terminated instances MockEc2Controller . getInstance ( ) . cleanupTerminatedInstances ( cleanupTerminatedInstancesPeriod ) ; log . info ( "aws-mock started." ) ; }
We load the saved instances if persistence of enabled on web application starting .