idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
6,300 | private RunInstancesResponseType runInstances ( final String imageId , final String instanceType , final int minCount , final int maxCount ) { RunInstancesResponseType ret = new RunInstancesResponseType ( ) ; RunningInstancesSetType instSet = new RunningInstancesSetType ( ) ; Class < ? extends AbstractMockEc2Instance > clazzOfMockEc2Instance = null ; try { clazzOfMockEc2Instance = ( Class . forName ( MOCK_EC2_INSTANCE_CLASS_NAME ) . asSubclass ( AbstractMockEc2Instance . class ) ) ; } catch ( ClassNotFoundException e ) { throw new AwsMockException ( "badly configured class '" + MOCK_EC2_INSTANCE_CLASS_NAME + "' not found" , e ) ; } List < AbstractMockEc2Instance > newInstances = null ; newInstances = mockEc2Controller . runInstances ( clazzOfMockEc2Instance , imageId , instanceType , minCount , maxCount ) ; for ( AbstractMockEc2Instance i : newInstances ) { RunningInstancesItemType instItem = new RunningInstancesItemType ( ) ; instItem . setInstanceId ( i . getInstanceID ( ) ) ; instItem . setImageId ( i . getImageId ( ) ) ; instItem . setInstanceType ( i . getInstanceType ( ) . getName ( ) ) ; InstanceStateType state = new InstanceStateType ( ) ; state . setCode ( i . getInstanceState ( ) . getCode ( ) ) ; state . setName ( i . getInstanceState ( ) . getName ( ) ) ; instItem . setInstanceState ( state ) ; instItem . setDnsName ( i . getPubDns ( ) ) ; instItem . setPlacement ( DEFAULT_MOCK_PLACEMENT ) ; instItem . setVpcId ( MOCK_VPC_ID ) ; instItem . setPrivateIpAddress ( MOCK_PRIVATE_IP_ADDRESS ) ; instItem . setSubnetId ( MOCK_SUBNET_ID ) ; instSet . getItem ( ) . add ( instItem ) ; } ret . setInstancesSet ( instSet ) ; return ret ; } | Handles runInstances request with only simplified filters of imageId instanceType minCount and maxCount . |
6,301 | private StartInstancesResponseType startInstances ( final Set < String > instanceIDs ) { StartInstancesResponseType ret = new StartInstancesResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType ( ) ; changeSet . getItem ( ) . addAll ( mockEc2Controller . startInstances ( instanceIDs ) ) ; ret . setInstancesSet ( changeSet ) ; return ret ; } | Handles startInstances request with only a simplified filter of instanceIDs . |
6,302 | private StopInstancesResponseType stopInstances ( final Set < String > instanceIDs ) { StopInstancesResponseType ret = new StopInstancesResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType ( ) ; changeSet . getItem ( ) . addAll ( mockEc2Controller . stopInstances ( instanceIDs ) ) ; ret . setInstancesSet ( changeSet ) ; return ret ; } | Handles stopInstances request with only a simplified filter of instanceIDs . |
6,303 | private TerminateInstancesResponseType terminateInstances ( final Set < String > instanceIDs ) { TerminateInstancesResponseType ret = new TerminateInstancesResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType ( ) ; changeSet . getItem ( ) . addAll ( mockEc2Controller . terminateInstances ( instanceIDs ) ) ; ret . setInstancesSet ( changeSet ) ; return ret ; } | Handles terminateInstances request with only a simplified filter of instanceIDs . |
6,304 | private DescribeImagesResponseType describeImages ( final Set < String > imageId ) { DescribeImagesResponseType ret = new DescribeImagesResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; DescribeImagesResponseInfoType info = new DescribeImagesResponseInfoType ( ) ; for ( String ami : MOCK_AMIS ) { if ( imageId == null || imageId . isEmpty ( ) ) { DescribeImagesResponseItemType item = new DescribeImagesResponseItemType ( ) ; item . setImageId ( ami ) ; item . setArchitecture ( "x86_64" ) ; item . setVirtualizationType ( "paravirtual" ) ; item . setName ( "My server" ) ; item . setHypervisor ( "xen" ) ; item . setRootDeviceType ( "ebs" ) ; item . setImageLocation ( "123456789012/My server" ) ; item . setKernelId ( "aki-88aa75e1" ) ; item . setImageOwnerId ( "123456789012" ) ; item . setRootDeviceName ( "/dev/sda1" ) ; item . setIsPublic ( false ) ; item . setImageType ( "machine" ) ; BlockDeviceMappingType blockDeviceMappingType = new BlockDeviceMappingType ( ) ; BlockDeviceMappingItemType blockDeviceMapping = new BlockDeviceMappingItemType ( ) ; blockDeviceMapping . setDeviceName ( "/dev/sda1" ) ; EbsBlockDeviceType ebs = new EbsBlockDeviceType ( ) ; ebs . setDeleteOnTermination ( true ) ; ebs . setSnapshotId ( "snap-1234567890abcdef0" ) ; ebs . setVolumeSize ( 1 ) ; ebs . setVolumeType ( "standard" ) ; blockDeviceMapping . setEbs ( ebs ) ; blockDeviceMappingType . getItem ( ) . add ( blockDeviceMapping ) ; item . setBlockDeviceMapping ( blockDeviceMappingType ) ; info . getItem ( ) . add ( item ) ; } else if ( imageId . contains ( ami ) ) { DescribeImagesResponseItemType item = new DescribeImagesResponseItemType ( ) ; item . setImageId ( ami ) ; item . setArchitecture ( "x86_64" ) ; item . setVirtualizationType ( "paravirtual" ) ; item . setName ( "My server" ) ; item . setHypervisor ( "xen" ) ; item . setRootDeviceType ( "ebs" ) ; item . setImageLocation ( "123456789012/My server" ) ; item . setKernelId ( "aki-88aa75e1" ) ; item . setImageOwnerId ( "123456789012" ) ; item . setRootDeviceName ( "/dev/sda1" ) ; item . setIsPublic ( false ) ; item . setImageType ( "machine" ) ; BlockDeviceMappingType blockDeviceMappingType = new BlockDeviceMappingType ( ) ; BlockDeviceMappingItemType blockDeviceMapping = new BlockDeviceMappingItemType ( ) ; blockDeviceMapping . setDeviceName ( "/dev/sda1" ) ; EbsBlockDeviceType ebs = new EbsBlockDeviceType ( ) ; ebs . setDeleteOnTermination ( true ) ; ebs . setSnapshotId ( "snap-1234567890abcdef0" ) ; ebs . setVolumeSize ( 1 ) ; ebs . setVolumeType ( "standard" ) ; blockDeviceMapping . setEbs ( ebs ) ; blockDeviceMappingType . getItem ( ) . add ( blockDeviceMapping ) ; item . setBlockDeviceMapping ( blockDeviceMappingType ) ; info . getItem ( ) . add ( item ) ; } } ret . setImagesSet ( info ) ; return ret ; } | Handles describeImages request as simple as without any filters to use . |
6,305 | private DescribeRouteTablesResponseType describeRouteTables ( ) { DescribeRouteTablesResponseType ret = new DescribeRouteTablesResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; RouteTableSetType routeTableSet = new RouteTableSetType ( ) ; for ( Iterator < MockRouteTable > mockRouteTable = mockRouteTableController . describeRouteTables ( ) . iterator ( ) ; mockRouteTable . hasNext ( ) ; ) { MockRouteTable item = mockRouteTable . next ( ) ; RouteTableType routeTable = new RouteTableType ( ) ; if ( ! DEFAULT_MOCK_PLACEMENT . getAvailabilityZone ( ) . equals ( currentRegion ) ) { routeTable . setVpcId ( currentRegion + "_" + item . getVpcId ( ) ) ; routeTable . setRouteTableId ( currentRegion + "_" + item . getRouteTableId ( ) ) ; } else { routeTable . setVpcId ( item . getVpcId ( ) ) ; routeTable . setRouteTableId ( item . getRouteTableId ( ) ) ; } RouteTableAssociationSetType associationSet = new RouteTableAssociationSetType ( ) ; routeTable . setAssociationSet ( associationSet ) ; RouteSetType routeSet = new RouteSetType ( ) ; routeTable . setRouteSet ( routeSet ) ; routeTableSet . getItem ( ) . add ( routeTable ) ; } ret . setRouteTableSet ( routeTableSet ) ; return ret ; } | Handles describeRouteTables request and returns response with a route table . |
6,306 | private CreateRouteTableResponseType createRouteTable ( final String vpcId , final String cidrBlock ) { CreateRouteTableResponseType ret = new CreateRouteTableResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; MockRouteTable mockRouteTable = mockRouteTableController . createRouteTable ( cidrBlock , vpcId ) ; RouteTableType routeTableType = new RouteTableType ( ) ; routeTableType . setVpcId ( mockRouteTable . getVpcId ( ) ) ; routeTableType . setRouteTableId ( mockRouteTable . getRouteTableId ( ) ) ; ret . setRouteTable ( routeTableType ) ; return ret ; } | Handles createRouteTable request to create routetable and returns response with a route table . |
6,307 | private CreateRouteResponseType createRoute ( final String destinationCidrBlock , final String internetGatewayId , final String routeTableId ) { CreateRouteResponseType ret = new CreateRouteResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockRouteTableController . createRoute ( destinationCidrBlock , internetGatewayId , routeTableId ) ; return ret ; } | Handles createRoute request to create route and returns response with a route table . |
6,308 | private CreateVolumeResponseType createVolume ( final String volumeType , final String size , final String availabilityZone , final int iops , final String snapshotId ) { CreateVolumeResponseType ret = new CreateVolumeResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; MockVolume mockVolume = mockVolumeController . createVolume ( volumeType , size , availabilityZone , iops , snapshotId ) ; ret . setVolumeId ( mockVolume . getVolumeId ( ) ) ; ret . setVolumeType ( mockVolume . getVolumeType ( ) ) ; ret . setSize ( mockVolume . getSize ( ) ) ; ret . setAvailabilityZone ( mockVolume . getAvailabilityZone ( ) ) ; ret . setIops ( mockVolume . getIops ( ) ) ; ret . setSnapshotId ( mockVolume . getSnapshotId ( ) ) ; return ret ; } | Handles createVolume request to create volume and returns response with a volume . |
6,309 | private CreateSubnetResponseType createSubnet ( final String vpcId , final String cidrBlock ) { CreateSubnetResponseType ret = new CreateSubnetResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; MockSubnet mockSubnet = mockSubnetController . createSubnet ( cidrBlock , vpcId ) ; SubnetType subnetType = new SubnetType ( ) ; subnetType . setVpcId ( mockSubnet . getVpcId ( ) ) ; subnetType . setSubnetId ( mockSubnet . getSubnetId ( ) ) ; ret . setSubnet ( subnetType ) ; return ret ; } | Handles createSubnet request to create Subnet and returns response with a subnet . |
6,310 | private CreateSecurityGroupResponseType createSecurityGroup ( final String groupName , final String groupDescription , final String vpcId ) { CreateSecurityGroupResponseType ret = new CreateSecurityGroupResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; MockSecurityGroup mockSecurityGroup = mockSecurityGroupController . createSecurityGroup ( groupName , groupDescription , vpcId ) ; ret . setGroupId ( mockSecurityGroup . getGroupId ( ) ) ; return ret ; } | Handles createSecurityGroup request to create SecurityGroup and returns response with a SecurityGroup . |
6,311 | private AuthorizeSecurityGroupIngressResponseType authorizeSecurityGroupIngress ( final String groupId , final String ipProtocol , final Integer fromPort , final Integer toPort , final String cidrIp ) { AuthorizeSecurityGroupIngressResponseType ret = new AuthorizeSecurityGroupIngressResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockSecurityGroupController . authorizeSecurityGroupIngress ( groupId , ipProtocol , fromPort , toPort , cidrIp ) ; return ret ; } | Handles authorizeSecurityGroupIngress request to SecurityGroup and returns response with a SecurityGroup . |
6,312 | private AuthorizeSecurityGroupEgressResponseType authorizeSecurityGroupEgress ( final String groupId , final String ipProtocol , final Integer fromPort , final Integer toPort , final String cidrIp ) { AuthorizeSecurityGroupEgressResponseType ret = new AuthorizeSecurityGroupEgressResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockSecurityGroupController . authorizeSecurityGroupEgress ( groupId , ipProtocol , fromPort , toPort , cidrIp ) ; return ret ; } | Handles authorizeSecurityGroupEgress request to SecurityGroup and returns response with a SecurityGroup . |
6,313 | private CreateInternetGatewayResponseType createInternetGateway ( ) { CreateInternetGatewayResponseType ret = new CreateInternetGatewayResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; MockInternetGateway mockInternetGateway = mockInternetGatewayController . createInternetGateway ( ) ; InternetGatewayType internetGateway = new InternetGatewayType ( ) ; internetGateway . setInternetGatewayId ( mockInternetGateway . getInternetGatewayId ( ) ) ; ret . setInternetGateway ( internetGateway ) ; return ret ; } | Handles createInternetGateway request to create InternetGateway and returns response with a InternetGateway . |
6,314 | private DeleteRouteTableResponseType deleteRouteTable ( final String routeTableId ) { DeleteRouteTableResponseType ret = new DeleteRouteTableResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockRouteTableController . deleteRouteTable ( routeTableId ) ; return ret ; } | Handles deleteRouteTable request to delete routetable and returns response with a route table . |
6,315 | private DeleteSubnetResponseType deleteSubnet ( final String subnetId ) { DeleteSubnetResponseType ret = new DeleteSubnetResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockSubnetController . deleteSubnet ( subnetId ) ; return ret ; } | Handles deleteSubnet request to delete subnet and returns response with a subnet . |
6,316 | private DeleteSecurityGroupResponseType deleteSecurityGroup ( final String securityGroupId ) { DeleteSecurityGroupResponseType ret = new DeleteSecurityGroupResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockSecurityGroupController . deleteSecurityGroup ( securityGroupId ) ; return ret ; } | Handles deleteSecurityGroup request to delete SecurityGroup and returns response with a SecurityGroup . |
6,317 | private DeleteVolumeResponseType deleteVolume ( final String volumeId ) { DeleteVolumeResponseType ret = new DeleteVolumeResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockVolumeController . deleteVolume ( volumeId ) ; return ret ; } | Handles deleteVolume request to delete volume and returns response with a volume . |
6,318 | private boolean isVolumeIdExists ( final List < String > volumeIds , final String volumeId ) { if ( volumeIds != null && volumeIds . size ( ) > 0 ) { for ( String volId : volumeIds ) { if ( volId . equals ( volumeId ) ) { return true ; } } } return false ; } | Check whether volumeId exists in list . |
6,319 | private DescribeSubnetsResponseType describeSubnets ( ) { DescribeSubnetsResponseType ret = new DescribeSubnetsResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; SubnetSetType subnetSetType = new SubnetSetType ( ) ; for ( Iterator < MockSubnet > mockSubnet = mockSubnetController . describeSubnets ( ) . iterator ( ) ; mockSubnet . hasNext ( ) ; ) { MockSubnet item = mockSubnet . next ( ) ; SubnetType subnetType = new SubnetType ( ) ; if ( ! DEFAULT_MOCK_PLACEMENT . getAvailabilityZone ( ) . equals ( currentRegion ) ) { subnetType . setVpcId ( currentRegion + "_" + item . getVpcId ( ) ) ; subnetType . setSubnetId ( currentRegion + "_" + item . getSubnetId ( ) ) ; } else { subnetType . setVpcId ( item . getVpcId ( ) ) ; subnetType . setSubnetId ( item . getSubnetId ( ) ) ; } subnetType . setSubnetId ( item . getSubnetId ( ) ) ; subnetType . setState ( "available" ) ; subnetType . setCidrBlock ( item . getCidrBlock ( ) ) ; subnetType . setAvailableIpAddressCount ( item . getAvailableIpAddressCount ( ) ) ; subnetType . setAvailabilityZone ( currentRegion ) ; subnetType . setDefaultForAz ( false ) ; subnetType . setMapPublicIpOnLaunch ( false ) ; subnetSetType . getItem ( ) . add ( subnetType ) ; } ret . setSubnetSet ( subnetSetType ) ; return ret ; } | Handles describeSubnets request and returns response with a subnet Set . |
6,320 | private DescribeInternetGatewaysResponseType describeInternetGateways ( ) { DescribeInternetGatewaysResponseType ret = new DescribeInternetGatewaysResponseType ( ) ; InternetGatewaySetType internetGatewaySet = new InternetGatewaySetType ( ) ; for ( Iterator < MockInternetGateway > mockInternetGateway = mockInternetGatewayController . describeInternetGateways ( ) . iterator ( ) ; mockInternetGateway . hasNext ( ) ; ) { MockInternetGateway item = mockInternetGateway . next ( ) ; InternetGatewayType internetGateway = new InternetGatewayType ( ) ; if ( ! DEFAULT_MOCK_PLACEMENT . getAvailabilityZone ( ) . equals ( currentRegion ) ) { internetGateway . setInternetGatewayId ( currentRegion + "_" + item . getInternetGatewayId ( ) ) ; } else { internetGateway . setInternetGatewayId ( item . getInternetGatewayId ( ) ) ; } InternetGatewayAttachmentSetType internetGatewayAttachmentSetType = new InternetGatewayAttachmentSetType ( ) ; if ( item . getAttachmentSet ( ) != null && item . getAttachmentSet ( ) . size ( ) > 0 ) { for ( MockInternetGatewayAttachmentType mockInternetGatewayAttachementType : item . getAttachmentSet ( ) ) { InternetGatewayAttachmentType internetGatewayAttachmentType = new InternetGatewayAttachmentType ( ) ; if ( ! DEFAULT_MOCK_PLACEMENT . getAvailabilityZone ( ) . equals ( currentRegion ) ) { internetGatewayAttachmentType . setVpcId ( currentRegion + "_" + mockInternetGatewayAttachementType . getVpcId ( ) ) ; } else { internetGatewayAttachmentType . setVpcId ( mockInternetGatewayAttachementType . getVpcId ( ) ) ; } internetGatewayAttachmentType . setState ( mockInternetGatewayAttachementType . getState ( ) ) ; internetGatewayAttachmentSetType . getItem ( ) . add ( internetGatewayAttachmentType ) ; } } internetGateway . setAttachmentSet ( internetGatewayAttachmentSetType ) ; internetGatewaySet . getItem ( ) . add ( internetGateway ) ; } ret . setInternetGatewaySet ( internetGatewaySet ) ; return ret ; } | Handles describeInternetGateways request and returns response with a Internet gateway . |
6,321 | private DescribeSecurityGroupsResponseType describeSecurityGroups ( ) { DescribeSecurityGroupsResponseType ret = new DescribeSecurityGroupsResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; SecurityGroupSetType securityGroupSet = new SecurityGroupSetType ( ) ; for ( Iterator < MockSecurityGroup > mockSecurityGroup = mockSecurityGroupController . describeSecurityGroups ( ) . iterator ( ) ; mockSecurityGroup . hasNext ( ) ; ) { MockSecurityGroup item = mockSecurityGroup . next ( ) ; SecurityGroupItemType securityGroupItem = new SecurityGroupItemType ( ) ; securityGroupItem . setOwnerId ( MOCK_SECURITY_OWNER_ID ) ; securityGroupItem . setGroupName ( item . getGroupName ( ) ) ; if ( ! DEFAULT_MOCK_PLACEMENT . getAvailabilityZone ( ) . equals ( currentRegion ) ) { securityGroupItem . setGroupId ( currentRegion + "_" + item . getGroupId ( ) ) ; securityGroupItem . setVpcId ( currentRegion + "_" + item . getVpcId ( ) ) ; } else { securityGroupItem . setGroupId ( item . getGroupId ( ) ) ; securityGroupItem . setVpcId ( item . getVpcId ( ) ) ; } securityGroupItem . setGroupDescription ( item . getGroupDescription ( ) ) ; IpPermissionSetType ipPermissionSet = new IpPermissionSetType ( ) ; for ( MockIpPermissionType mockIpPermissionType : item . getIpPermissions ( ) ) { IpPermissionType ipPermission = new IpPermissionType ( ) ; ipPermission . setFromPort ( mockIpPermissionType . getFromPort ( ) ) ; ipPermission . setToPort ( mockIpPermissionType . getToPort ( ) ) ; ipPermission . setIpProtocol ( mockIpPermissionType . getIpProtocol ( ) ) ; ipPermissionSet . getItem ( ) . add ( ipPermission ) ; } IpPermissionSetType ipPermissionEgressSet = new IpPermissionSetType ( ) ; for ( MockIpPermissionType mockIpPermissionType : item . getIpPermissionsEgress ( ) ) { IpPermissionType ipPermission = new IpPermissionType ( ) ; ipPermission . setFromPort ( mockIpPermissionType . getFromPort ( ) ) ; ipPermission . setToPort ( mockIpPermissionType . getToPort ( ) ) ; ipPermission . setIpProtocol ( mockIpPermissionType . getIpProtocol ( ) ) ; ipPermissionEgressSet . getItem ( ) . add ( ipPermission ) ; } securityGroupItem . setIpPermissionsEgress ( ipPermissionEgressSet ) ; securityGroupSet . getItem ( ) . add ( securityGroupItem ) ; } ret . setSecurityGroupInfo ( securityGroupSet ) ; return ret ; } | Handles describeSecurityGroups request and returns response with a security group . |
6,322 | private DescribeVpcsResponseType describeVpcs ( ) { DescribeVpcsResponseType ret = new DescribeVpcsResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; VpcSetType vpcSet = new VpcSetType ( ) ; for ( Iterator < MockVpc > mockVpc = mockVpcController . describeVpcs ( ) . iterator ( ) ; mockVpc . hasNext ( ) ; ) { MockVpc item = mockVpc . next ( ) ; VpcType vpcType = new VpcType ( ) ; if ( ! DEFAULT_MOCK_PLACEMENT . getAvailabilityZone ( ) . equals ( currentRegion ) ) { vpcType . setVpcId ( currentRegion + "_" + item . getVpcId ( ) ) ; } else { vpcType . setVpcId ( item . getVpcId ( ) ) ; } vpcType . setState ( item . getState ( ) ) ; vpcType . setCidrBlock ( item . getCidrBlock ( ) ) ; vpcType . setIsDefault ( item . getIsDefault ( ) ) ; vpcSet . getItem ( ) . add ( vpcType ) ; } ret . setVpcSet ( vpcSet ) ; return ret ; } | Handles describeVpcs request and returns response with a vpc . |
6,323 | private DescribeTagsResponseType describeTags ( ) { DescribeTagsResponseType ret = new DescribeTagsResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; TagSetType tagsSet = new TagSetType ( ) ; for ( MockTags mockVpc : mockTagsController . describeTags ( ) ) { for ( String resourceId : mockVpc . getResourcesSet ( ) ) { TagSetItemType tagItem = new TagSetItemType ( ) ; tagItem . setResourceId ( resourceId ) ; tagItem . setKey ( mockVpc . getTagSet ( ) . keySet ( ) . toArray ( new String [ mockVpc . getTagSet ( ) . size ( ) ] ) [ 0 ] ) ; tagItem . setValue ( mockVpc . getTagSet ( ) . values ( ) . toArray ( new String [ mockVpc . getTagSet ( ) . size ( ) ] ) [ 0 ] ) ; tagsSet . getItem ( ) . add ( tagItem ) ; } } ret . setTagSet ( tagsSet ) ; return ret ; } | Handles describeTags request and returns response with a Tags . |
6,324 | private CreateTagsResponseType createTags ( final List < String > resourcesSet , final Map < String , String > tagSet ) { CreateTagsResponseType ret = new CreateTagsResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockTagsController . createTags ( resourcesSet , tagSet ) ; ret . setReturn ( true ) ; return ret ; } | Handles createTags request and create new Tags . |
6,325 | private DeleteTagsResponseType deleteTags ( final List < String > resources ) { DeleteTagsResponseType ret = new DeleteTagsResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockTagsController . deleteTags ( resources ) ; return ret ; } | Handles deleteTags request and delete Tags and returns response . |
6,326 | private CreateVpcResponseType createVpc ( final String cidrBlock , final String instanceTenancy ) { CreateVpcResponseType ret = new CreateVpcResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; MockVpc mockVpc = mockVpcController . createVpc ( cidrBlock , instanceTenancy ) ; VpcType vpcType = new VpcType ( ) ; vpcType . setVpcId ( mockVpc . getVpcId ( ) ) ; vpcType . setState ( mockVpc . getState ( ) ) ; vpcType . setCidrBlock ( mockVpc . getCidrBlock ( ) ) ; vpcType . setIsDefault ( mockVpc . getIsDefault ( ) ) ; ret . setVpc ( vpcType ) ; return ret ; } | Handles createVpc request and create new Vpc . |
6,327 | private DeleteVpcResponseType deleteVpc ( final String vpcId ) { DeleteVpcResponseType ret = new DeleteVpcResponseType ( ) ; ret . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; mockVpcController . deleteVpc ( vpcId ) ; return ret ; } | Handles deleteVpc request and delete Vpc and returns response . |
6,328 | private String getXmlError ( final String errorCode , final String errorMessage ) { Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "errorCode" , StringEscapeUtils . escapeXml ( errorCode ) ) ; data . put ( "errorMessage" , StringEscapeUtils . escapeXml ( errorMessage ) ) ; data . put ( "requestID" , UUID . randomUUID ( ) . toString ( ) ) ; String ret = null ; try { ret = TemplateUtils . get ( ERROR_RESPONSE_TEMPLATE , data ) ; } catch ( AwsMockException e ) { log . error ( "fatal exception caught: {}" , e . getMessage ( ) ) ; e . printStackTrace ( ) ; } return ret ; } | Generate error response body in xml and write it with writer . |
6,329 | private String getBlankResponseXml ( ) { Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "requestID" , UUID . randomUUID ( ) . toString ( ) ) ; String ret = null ; try { ret = TemplateUtils . get ( BLANK_RESPONSE_TEMPLATE , data ) ; } catch ( AwsMockException e ) { log . error ( "fatal exception caught: {}" , e . getMessage ( ) ) ; e . printStackTrace ( ) ; } return ret ; } | Generate blank response body in xml and write it with writer . |
6,330 | public Collection < AbstractMockEc2Instance > describeInstances ( final Set < String > instanceIDs ) { if ( null == instanceIDs || instanceIDs . size ( ) == 0 ) { return allMockEc2Instances . values ( ) ; } else { return getInstances ( instanceIDs ) ; } } | List mock ec2 instances in current aws - mock . |
6,331 | public List < String > listInstanceIDs ( final Set < String > instanceIDs ) { Set < String > allInstanceIDs = allMockEc2Instances . keySet ( ) ; if ( null == instanceIDs || instanceIDs . size ( ) == 0 ) { return new ArrayList < String > ( allInstanceIDs ) ; } else { List < String > filteredInstanceIDs = new ArrayList < String > ( ) ; for ( String id : allInstanceIDs ) { if ( null != id && instanceIDs . contains ( id ) ) { filteredInstanceIDs . add ( id ) ; } } return filteredInstanceIDs ; } } | List mock ec2 instance IDs in current aws - mock . |
6,332 | public List < InstanceStateChangeType > stopInstances ( final Set < String > instanceIDs ) { List < InstanceStateChangeType > ret = new ArrayList < InstanceStateChangeType > ( ) ; Collection < AbstractMockEc2Instance > instances = getInstances ( instanceIDs ) ; for ( AbstractMockEc2Instance instance : instances ) { if ( null != instance ) { InstanceStateChangeType stateChange = new InstanceStateChangeType ( ) ; stateChange . setInstanceId ( instance . getInstanceID ( ) ) ; InstanceStateType previousState = new InstanceStateType ( ) ; previousState . setCode ( instance . getInstanceState ( ) . getCode ( ) ) ; previousState . setName ( instance . getInstanceState ( ) . getName ( ) ) ; stateChange . setPreviousState ( previousState ) ; instance . stop ( ) ; InstanceStateType newState = new InstanceStateType ( ) ; newState . setCode ( instance . getInstanceState ( ) . getCode ( ) ) ; newState . setName ( instance . getInstanceState ( ) . getName ( ) ) ; stateChange . setCurrentState ( newState ) ; ret . add ( stateChange ) ; } } return ret ; } | Stop one or more existing mock ec2 instances . |
6,333 | private Collection < AbstractMockEc2Instance > getInstances ( final Set < String > instanceIDs ) { Collection < AbstractMockEc2Instance > ret = new ArrayList < AbstractMockEc2Instance > ( ) ; for ( String instanceID : instanceIDs ) { ret . add ( getMockEc2Instance ( instanceID ) ) ; } return ret ; } | Get mock ec2 instances by instance IDs . |
6,334 | public void destroyCleanupTerminatedInstanceTimer ( ) { cleanupTerminatedInstancesScheduledFuture . cancel ( true ) ; cleanupTerminatedInstancesScheduledFuture = null ; cleanupTerminatedInstancesTimer . shutdown ( ) ; cleanupTerminatedInstancesTimer = null ; } | Cancel the internal timer of cleaning up terminated mock ec2 instances . |
6,335 | public static List < Image > describeAllImages ( ) { AWSCredentials credentials = new BasicAWSCredentials ( "foo" , "bar" ) ; AmazonEC2Client amazonEC2Client = new AmazonEC2Client ( credentials ) ; String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/" ; amazonEC2Client . setEndpoint ( ec2Endpoint ) ; DescribeImagesResult result = amazonEC2Client . describeImages ( ) ; return result . getImages ( ) ; } | Describe all available AMIs within aws - mock . |
6,336 | public MockVpc createVpc ( final String cidrBlock , final String instanceTenancy ) { MockVpc ret = new MockVpc ( ) ; ret . setCidrBlock ( cidrBlock ) ; ret . setVpcId ( "vpc-" + UUID . randomUUID ( ) . toString ( ) . substring ( 0 , VPC_ID_POSTFIX_LENGTH ) ) ; ret . setInstanceTenancy ( instanceTenancy ) ; synchronized ( this ) { if ( allMockVpcInstances . size ( ) == 0 ) { ret . setIsDefault ( true ) ; } else { ret . setIsDefault ( false ) ; } allMockVpcInstances . put ( ret . getVpcId ( ) , ret ) ; } return ret ; } | Create the mock VPC . |
6,337 | public MockVpc deleteVpc ( final String vpcId ) { if ( vpcId != null && allMockVpcInstances . containsKey ( vpcId ) ) { return allMockVpcInstances . remove ( vpcId ) ; } return null ; } | Delete vpc . |
6,338 | private GetMetricStatisticsResponse getMetricStatistics ( final String [ ] statistics , final DateTime startTime , final DateTime endTime , final int period , final String metricName ) { GetMetricStatisticsResponse ret = new GetMetricStatisticsResponse ( ) ; GetMetricStatisticsResult result = new GetMetricStatisticsResult ( ) ; Datapoints dataPoints = new Datapoints ( ) ; int dataPointsCount = Seconds . secondsBetween ( startTime , endTime ) . getSeconds ( ) / period ; DateTime newDate = startTime ; for ( int counterDp = 0 ; counterDp < dataPointsCount ; counterDp ++ ) { Datapoint dp = new Datapoint ( ) ; DateTime timeStamp = newDate . plusSeconds ( period ) ; XMLGregorianCalendar timeStampXml = toXMLGregorianCalendar ( timeStamp ) ; dp . setTimestamp ( timeStampXml ) ; dp . setAverage ( getMetricAverageValue ( metricName ) ) ; dp . setSampleCount ( getMetricSampleCountValue ( metricName ) ) ; dp . setUnit ( getMetricUnit ( metricName ) ) ; dataPoints . getMember ( ) . add ( dp ) ; newDate = timeStamp ; } result . setDatapoints ( dataPoints ) ; result . setLabel ( metricName ) ; ret . setGetMetricStatisticsResult ( result ) ; ResponseMetadata responseMetadata = new ResponseMetadata ( ) ; responseMetadata . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; ret . setResponseMetadata ( responseMetadata ) ; return ret ; } | Handles GetMetricStatistics request as simple as without any filters to use . |
6,339 | private DescribeAlarmsResponse describeAlarms ( ) { DescribeAlarmsResponse ret = new DescribeAlarmsResponse ( ) ; DescribeAlarmsResult result = new DescribeAlarmsResult ( ) ; MetricAlarms metricAlarms = new MetricAlarms ( ) ; MetricAlarm metricAlarm = new MetricAlarm ( ) ; metricAlarm . setAlarmDescription ( "CPU usage exceeds 70 percent" ) ; metricAlarm . setAlarmName ( "AwsMockAlarmCPU" ) ; metricAlarms . getMember ( ) . add ( metricAlarm ) ; metricAlarm = new MetricAlarm ( ) ; metricAlarm . setAlarmDescription ( "Memory usage exceeds 80 percent" ) ; metricAlarm . setAlarmName ( "AwsMockAlarmMemory" ) ; metricAlarms . getMember ( ) . add ( metricAlarm ) ; result . setMetricAlarms ( metricAlarms ) ; ret . setDescribeAlarmsResult ( result ) ; ResponseMetadata responseMetadata = new ResponseMetadata ( ) ; responseMetadata . setRequestId ( UUID . randomUUID ( ) . toString ( ) ) ; ret . setResponseMetadata ( responseMetadata ) ; return ret ; } | Handles describeAlarms request . |
6,340 | private XMLGregorianCalendar toXMLGregorianCalendar ( final DateTime date ) { GregorianCalendar gCalendar = new GregorianCalendar ( date . getZone ( ) . toTimeZone ( ) ) ; gCalendar . setTime ( date . toDate ( ) ) ; XMLGregorianCalendar xmlGrogerianCalendar = null ; try { xmlGrogerianCalendar = DatatypeFactory . newInstance ( ) . newXMLGregorianCalendar ( gCalendar ) ; } catch ( DatatypeConfigurationException ex ) { log . error ( ex . getMessage ( ) ) ; System . out . println ( ex . getStackTrace ( ) ) ; } return xmlGrogerianCalendar ; } | Converts java . util . Date to javax . xml . datatype . XMLGregorianCalendar . |
6,341 | private StandardUnit getMetricUnit ( final String metricName ) { String result = null ; if ( metricName . equals ( Constants . CPU_UTILIZATION ) ) { result = Constants . UNIT_PERCENT ; } else if ( metricName . equals ( Constants . DISK_READ_BYTES ) ) { result = Constants . UNIT_BYTES ; } else if ( metricName . equals ( Constants . DISK_READ_OPS ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . DISK_WRITE_BYTES ) ) { result = Constants . UNIT_BYTES ; } else if ( metricName . equals ( Constants . DISK_WRITE_OPS ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . NETWORK_IN ) ) { result = Constants . UNIT_BYTES ; } else if ( metricName . equals ( Constants . NETWORK_OUT ) ) { result = Constants . UNIT_BYTES ; } else if ( metricName . equals ( Constants . NETWORK_PACKETS_IN ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . NETWORK_PACKETS_OUT ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . STATUS_CHECK_FAILED ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . STATUS_CHECK_FAILED_INSTANCE ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . STATUS_CHECK_FAILED_SYSTEM ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . CPU_CREDIT_USAGE ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . ESTIMATED_CHARGES ) ) { result = Constants . UNIT_COUNT ; } else if ( metricName . equals ( Constants . CPU_CREDIT_BALANCE ) ) { result = Constants . UNIT_COUNT ; } return StandardUnit . fromValue ( result ) ; } | Get the Metric Unit . |
6,342 | public static void write ( final String templateFilename , final Map < String , Object > data , final Writer writer ) { Template tmpl = null ; try { tmpl = conf . getTemplate ( templateFilename ) ; } catch ( FileNotFoundException e1 ) { String errMsg = "FileNotFoundException: template file '" + templateFilename + "' not found" ; log . error ( "{}: {}" , errMsg , e1 . getMessage ( ) ) ; throw new AwsMockException ( errMsg , e1 ) ; } catch ( IOException e ) { String errMsg = "IOException: failed to getTemplate (filename is " + templateFilename + ")" ; log . error ( "{}: {}" , errMsg , e . getMessage ( ) ) ; throw new AwsMockException ( errMsg , e ) ; } try { tmpl . process ( data , writer ) ; } catch ( TemplateException e ) { StringBuilder dataDescription = new StringBuilder ( ) ; if ( null != data ) { for ( Map . Entry < String , Object > entry : data . entrySet ( ) ) { dataDescription . append ( entry . getKey ( ) + " - " + entry . getValue ( ) ) . append ( '\n' ) ; } } String errMsg = "TemplateException: failed to process template '" + templateFilename + "', with data: " + dataDescription . toString ( ) + " The probable cause could be un-matching of key-values for that template. " ; log . error ( "{}: {}" , errMsg , e . getMessage ( ) ) ; throw new AwsMockException ( errMsg , e ) ; } catch ( IOException e ) { String errMsg = "IOException: failed to process template and write to writer. " ; log . error ( "{}: {}" , errMsg , e . getMessage ( ) ) ; throw new AwsMockException ( errMsg , e ) ; } } | Process with given template + data and then put result to writer . |
6,343 | public static String get ( final String templateName , final Map < String , Object > data ) { StringWriter writer = new StringWriter ( ) ; write ( templateName , data , writer ) ; return writer . toString ( ) ; } | Process with given template + data and get result as a string . |
6,344 | public static void saveAll ( final Object obj , final PersistenceStoreType storeType ) { try { File file = new File ( persistenceStorePath + File . separator + storeType ) ; File directory = file . getParentFile ( ) ; if ( null != directory && ! directory . exists ( ) ) { directory . mkdirs ( ) ; } log . info ( "aws-mock: saving to {}" , file . getAbsolutePath ( ) ) ; ObjectOutputStream out = new ObjectOutputStream ( new FileOutputStream ( file , false ) ) ; out . writeObject ( obj ) ; out . close ( ) ; } catch ( FileNotFoundException e ) { log . error ( "FileNotFoundException caught during saving object to file: {}" , e . getMessage ( ) ) ; } catch ( IOException e ) { log . error ( "IOException caught during saving object to file: {}" , e . getMessage ( ) ) ; } } | Save object to the binary file defined as filename in property persistence . store . file . |
6,345 | public static Object loadAll ( final PersistenceStoreType storeType ) { Object ret = null ; try { File file = new File ( persistenceStorePath + File . separator + storeType ) ; log . info ( "aws-mock: try to load objects from {}" , file . getAbsolutePath ( ) ) ; ObjectInputStream in = new ObjectInputStream ( new FileInputStream ( file ) ) ; ret = in . readObject ( ) ; in . close ( ) ; } catch ( FileNotFoundException e ) { log . warn ( "no saved file to load from: {}" , e . getMessage ( ) ) ; return null ; } catch ( IOException e ) { log . warn ( "failed to load from the saved file: {}" , e . getMessage ( ) ) ; return null ; } catch ( ClassNotFoundException e ) { log . error ( "ClassNotFoundException caught during loading object from file: " + e . getMessage ( ) ) ; } return ret ; } | Load object from the binary file defined as filename in property . |
6,346 | public MockVolume createVolume ( final String volumeType , final String size , final String availabilityZone , final int iops , final String snapshotId ) { MockVolume ret = new MockVolume ( ) ; ret . setVolumeType ( volumeType ) ; ret . setVolumeId ( "vol-" + UUID . randomUUID ( ) . toString ( ) . substring ( 0 , VOLUME_ID_POSTFIX_LENGTH ) ) ; ret . setSize ( size ) ; ret . setAvailabilityZone ( availabilityZone ) ; ret . setIops ( iops ) ; ret . setSnapshotId ( snapshotId ) ; allMockVolumes . put ( ret . getVolumeId ( ) , ret ) ; return ret ; } | Create the mock Volume . |
6,347 | public MockVolume deleteVolume ( final String volumeId ) { if ( volumeId != null && allMockVolumes . containsKey ( volumeId ) ) { return allMockVolumes . remove ( volumeId ) ; } return null ; } | Delete Mock Volume . |
6,348 | public final void contextInitialized ( final ServletContextEvent sce ) { if ( persistenceEnabled ) { AbstractMockEc2Instance [ ] instanceArray = ( AbstractMockEc2Instance [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . EC2 ) ; if ( null != instanceArray ) { MockEc2Controller . getInstance ( ) . restoreAllMockEc2Instances ( Arrays . asList ( instanceArray ) ) ; } MockVpc [ ] vpcArray = ( MockVpc [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . VPC ) ; if ( null != vpcArray ) { MockVpcController . getInstance ( ) . restoreAllMockVpc ( Arrays . asList ( vpcArray ) ) ; } MockVolume [ ] volumeArray = ( MockVolume [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . VOLUME ) ; if ( null != volumeArray ) { MockVolumeController . getInstance ( ) . restoreAllMockVolume ( Arrays . asList ( volumeArray ) ) ; } MockTags [ ] tagsArray = ( MockTags [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . TAGS ) ; if ( null != tagsArray ) { MockTagsController . getInstance ( ) . restoreAllMockTags ( Arrays . asList ( tagsArray ) ) ; } MockSubnet [ ] subnetArray = ( MockSubnet [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . SUBNET ) ; if ( null != subnetArray ) { MockSubnetController . getInstance ( ) . restoreAllMockSubnet ( Arrays . asList ( subnetArray ) ) ; } MockRouteTable [ ] routetableArray = ( MockRouteTable [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . ROUTETABLE ) ; if ( null != routetableArray ) { MockRouteTableController . getInstance ( ) . restoreAllMockRouteTable ( Arrays . asList ( routetableArray ) ) ; } MockInternetGateway [ ] internetgatewayArray = ( MockInternetGateway [ ] ) PersistenceUtils . loadAll ( PersistenceStoreType . INTERNETGATEWAY ) ; if ( null != internetgatewayArray ) { MockInternetGatewayController . getInstance ( ) . restoreAllInternetGateway ( Arrays . asList ( internetgatewayArray ) ) ; } } MockEc2Controller . getInstance ( ) . cleanupTerminatedInstances ( cleanupTerminatedInstancesPeriod ) ; log . info ( "aws-mock started." ) ; } | We load the saved instances if persistence of enabled on web application starting . |
6,349 | public final void contextDestroyed ( final ServletContextEvent sce ) { Collection < AbstractMockEc2Instance > instances = MockEc2Controller . getInstance ( ) . getAllMockEc2Instances ( ) ; for ( AbstractMockEc2Instance instance : instances ) { instance . destroyInternalTimer ( ) ; } if ( persistenceEnabled ) { AbstractMockEc2Instance [ ] array = new AbstractMockEc2Instance [ instances . size ( ) ] ; instances . toArray ( array ) ; PersistenceUtils . saveAll ( array , PersistenceStoreType . EC2 ) ; Collection < MockVpc > vpcs = MockVpcController . getInstance ( ) . describeVpcs ( ) ; MockVpc [ ] vpcArray = new MockVpc [ vpcs . size ( ) ] ; vpcs . toArray ( vpcArray ) ; PersistenceUtils . saveAll ( vpcArray , PersistenceStoreType . VPC ) ; Collection < MockVolume > volumes = MockVolumeController . getInstance ( ) . describeVolumes ( ) ; MockVolume [ ] volumeArray = new MockVolume [ volumes . size ( ) ] ; volumes . toArray ( volumeArray ) ; PersistenceUtils . saveAll ( volumeArray , PersistenceStoreType . VOLUME ) ; Collection < MockTags > tags = MockTagsController . getInstance ( ) . describeTags ( ) ; MockTags [ ] tagArray = new MockTags [ tags . size ( ) ] ; tags . toArray ( tagArray ) ; PersistenceUtils . saveAll ( tagArray , PersistenceStoreType . TAGS ) ; Collection < MockSubnet > subnets = MockSubnetController . getInstance ( ) . describeSubnets ( ) ; MockSubnet [ ] subnetArray = new MockSubnet [ subnets . size ( ) ] ; subnets . toArray ( subnetArray ) ; PersistenceUtils . saveAll ( subnetArray , PersistenceStoreType . SUBNET ) ; Collection < MockRouteTable > routetables = MockRouteTableController . getInstance ( ) . describeRouteTables ( ) ; MockRouteTable [ ] routetableArray = new MockRouteTable [ routetables . size ( ) ] ; routetables . toArray ( routetableArray ) ; PersistenceUtils . saveAll ( routetableArray , PersistenceStoreType . ROUTETABLE ) ; Collection < MockInternetGateway > internetgateways = MockInternetGatewayController . getInstance ( ) . describeInternetGateways ( ) ; MockInternetGateway [ ] internetgatewayArray = new MockInternetGateway [ internetgateways . size ( ) ] ; internetgateways . toArray ( internetgatewayArray ) ; PersistenceUtils . saveAll ( internetgatewayArray , PersistenceStoreType . INTERNETGATEWAY ) ; } MockEc2Controller . getInstance ( ) . destroyCleanupTerminatedInstanceTimer ( ) ; log . info ( "aws-mock stopped." ) ; } | We save the instances if persistence of enabled on web application shutting - down . |
6,350 | public static String marshall ( final GetMetricStatisticsResponse obj , final String localPartQName , final String requestVersion ) { StringWriter writer = new StringWriter ( ) ; try { synchronized ( jaxbMarshaller ) { JAXBElement < GetMetricStatisticsResponse > jAXBElement = new JAXBElement < GetMetricStatisticsResponse > ( new QName ( PropertiesUtils . getProperty ( Constants . PROP_NAME_CLOUDWATCH_XMLNS_CURRENT ) , "local" ) , GetMetricStatisticsResponse . class , obj ) ; jaxbMarshaller . marshal ( jAXBElement , writer ) ; } } catch ( JAXBException e ) { String errMsg = "failed to marshall object to xml, localPartQName=" + localPartQName + ", requestVersion=" + requestVersion ; log . error ( "{}, exception message: {}" , errMsg , e . getLinkedException ( ) ) ; throw new AwsMockException ( errMsg , e ) ; } String ret = writer . toString ( ) ; if ( "true" . equalsIgnoreCase ( PropertiesUtils . getProperty ( Constants . PROP_NAME_ELASTICFOX_COMPATIBLE ) ) && null != requestVersion && requestVersion . equals ( PropertiesUtils . getProperty ( Constants . PROP_NAME_EC2_API_VERSION_ELASTICFOX ) ) ) { ret = StringUtils . replaceOnce ( ret , PropertiesUtils . getProperty ( Constants . PROP_NAME_CLOUDWATCH_API_VERSION_CURRENT_IMPL ) , PropertiesUtils . getProperty ( Constants . PROP_NAME_EC2_API_VERSION_ELASTICFOX ) ) ; } return ret ; } | marshall object to string . |
6,351 | public MockRouteTable createRouteTable ( final String cidrBlock , final String vpcId ) { MockRouteTable ret = new MockRouteTable ( ) ; ret . setRouteTableId ( "rtb-" + UUID . randomUUID ( ) . toString ( ) . substring ( 0 , ROUTETABLE_ID_POSTFIX_LENGTH ) ) ; ret . setVpcId ( vpcId ) ; MockRoute mockRoute = new MockRoute ( ) ; mockRoute . setGatewayId ( "local" ) ; mockRoute . setDestinationCidrBlock ( cidrBlock ) ; mockRoute . setState ( "active" ) ; mockRoute . setOrigin ( "CreateRouteTable" ) ; List < MockRoute > routeSet = new ArrayList < MockRoute > ( ) ; routeSet . add ( mockRoute ) ; ret . setRouteSet ( routeSet ) ; allMockRouteTables . put ( ret . getRouteTableId ( ) , ret ) ; return ret ; } | Create the mock RouteTable . |
6,352 | public MockRouteTable deleteRouteTable ( final String routetableId ) { if ( routetableId != null && allMockRouteTables . containsKey ( routetableId ) ) { return allMockRouteTables . remove ( routetableId ) ; } return null ; } | Delete RouteTable . |
6,353 | public MockRoute createRoute ( final String destinationCidrBlock , final String internetGatewayId , final String routeTableId ) { MockRoute ret = new MockRoute ( ) ; ret . setDestinationCidrBlock ( destinationCidrBlock ) ; ret . setGatewayId ( internetGatewayId ) ; ret . setOrigin ( "CreateRoute" ) ; MockRouteTable mockRouteTable = getMockRouteTable ( routeTableId ) ; if ( mockRouteTable != null ) { mockRouteTable . getRouteSet ( ) . add ( ret ) ; } return ret ; } | Create the mock Route . |
6,354 | public MockRouteTable getMockRouteTable ( final String routetableId ) { if ( routetableId != null ) { return allMockRouteTables . get ( routetableId ) ; } return null ; } | Get mock RouteTable instance by RouteTable ID . |
6,355 | public MockSecurityGroup createSecurityGroup ( final String groupName , final String groupDescription , final String vpcId ) { MockSecurityGroup ret = new MockSecurityGroup ( ) ; ret . setGroupName ( groupName ) ; ret . setGroupDescription ( groupDescription ) ; ret . setGroupId ( "sg-" + UUID . randomUUID ( ) . toString ( ) . substring ( 0 , SECURITYGROUP_ID_POSTFIX_LENGTH ) ) ; ret . setVpcId ( vpcId ) ; MockIpPermissionType mockIpPermissionType = new MockIpPermissionType ( ) ; mockIpPermissionType . setIpProtocol ( "-1" ) ; List < String > ipRanges = new ArrayList < String > ( ) ; ipRanges . add ( "0.0.0.0/0" ) ; mockIpPermissionType . setIpRanges ( ipRanges ) ; List < MockIpPermissionType > mockIpPermissionTypes = new ArrayList < MockIpPermissionType > ( ) ; mockIpPermissionTypes . add ( mockIpPermissionType ) ; ret . setIpPermissionsEgress ( mockIpPermissionTypes ) ; List < MockIpPermissionType > mockIpPermissionTypesIngress = new ArrayList < MockIpPermissionType > ( ) ; ret . setIpPermissions ( mockIpPermissionTypesIngress ) ; allMockSecurityGroup . put ( ret . getGroupId ( ) , ret ) ; return ret ; } | Create the mock SecurityGroup . |
6,356 | public MockSecurityGroup authorizeSecurityGroupIngress ( final String groupId , final String ipProtocol , final Integer fromPort , final Integer toPort , final String cidrIp ) { if ( groupId == null ) { return null ; } MockSecurityGroup ret = allMockSecurityGroup . get ( groupId ) ; if ( ret != null ) { MockIpPermissionType mockIpPermissionType = new MockIpPermissionType ( ) ; mockIpPermissionType . setIpProtocol ( ipProtocol ) ; mockIpPermissionType . setFromPort ( fromPort ) ; mockIpPermissionType . setToPort ( toPort ) ; List < String > ipRanges = new ArrayList < String > ( ) ; ipRanges . add ( cidrIp ) ; mockIpPermissionType . setIpRanges ( ipRanges ) ; List < MockIpPermissionType > mockIpPermissionTypes = ret . getIpPermissions ( ) ; mockIpPermissionTypes . add ( mockIpPermissionType ) ; ret . setIpPermissions ( mockIpPermissionTypes ) ; allMockSecurityGroup . put ( ret . getGroupId ( ) , ret ) ; } return ret ; } | Authorize the mock SecurityGroup to Ingress IpProtocol . |
6,357 | public MockSecurityGroup deleteSecurityGroup ( final String securityGroupId ) { if ( securityGroupId != null && allMockSecurityGroup . containsKey ( securityGroupId ) ) { return allMockSecurityGroup . remove ( securityGroupId ) ; } return null ; } | Delete MockSecurityGroup . |
6,358 | public static List < Instance > runInstances ( final String imageId , final int runCount ) { AWSCredentials credentials = new BasicAWSCredentials ( "foo" , "bar" ) ; AmazonEC2Client amazonEC2Client = new AmazonEC2Client ( credentials ) ; String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/" ; amazonEC2Client . setEndpoint ( ec2Endpoint ) ; String instanceType = "m1.large" ; RunInstancesRequest request = new RunInstancesRequest ( ) ; final int minRunCount = runCount ; final int maxRunCount = runCount ; request . withImageId ( imageId ) . withInstanceType ( instanceType ) . withMinCount ( minRunCount ) . withMaxCount ( maxRunCount ) ; RunInstancesResult result = amazonEC2Client . runInstances ( request ) ; return result . getReservation ( ) . getInstances ( ) ; } | Run some new ec2 instances . |
6,359 | public MockTags createTags ( final List < String > resourcesSet , final Map < String , String > tagSet ) { MockTags ret = new MockTags ( ) ; ret . setResourcesSet ( resourcesSet ) ; ret . setTagSet ( tagSet ) ; allMockTags . add ( ret ) ; return ret ; } | Create the mock Tags . |
6,360 | public boolean deleteTags ( final List < String > resources ) { for ( MockTags mockTags : allMockTags ) { if ( mockTags . getResourcesSet ( ) . containsAll ( resources ) ) { allMockTags . remove ( mockTags ) ; return true ; } } return false ; } | Delete Mock tags . |
6,361 | public static Set < String > getPropertiesByPrefix ( final String propertyNamePrefix ) { Set < String > ret = new TreeSet < String > ( ) ; Set < Object > keys = properties . keySet ( ) ; for ( Object key : keys ) { if ( null != key && key . toString ( ) . startsWith ( propertyNamePrefix ) ) { ret . add ( properties . getProperty ( key . toString ( ) ) ) ; } } return ret ; } | Get a set of properties those share the same given name prefix . |
6,362 | public static int getIntFromProperty ( final String propertyName ) { try { return Integer . parseInt ( properties . getProperty ( propertyName ) ) ; } catch ( NumberFormatException e ) { log . error ( "NumberFormatException caught during reading property from properties file: " + e . getMessage ( ) ) ; return 0 ; } } | Get int type of property value by name . |
6,363 | public static void startScheduler ( int threadPoolSize , String annotatedJobsPackageName ) throws SundialSchedulerException { try { createScheduler ( threadPoolSize , annotatedJobsPackageName ) ; getScheduler ( ) . start ( ) ; } catch ( SchedulerException e ) { throw new SundialSchedulerException ( "COULD NOT START SUNDIAL SCHEDULER!!!" , e ) ; } } | Starts the Sundial Scheduler |
6,364 | public static void startJob ( String jobName ) throws SundialSchedulerException { try { getScheduler ( ) . triggerJob ( jobName , null ) ; } catch ( SchedulerException e ) { throw new SundialSchedulerException ( "ERROR STARTING JOB!!!" , e ) ; } } | Starts a Job matching the given Job Name |
6,365 | public static void removeJob ( String jobName ) throws SundialSchedulerException { try { getScheduler ( ) . deleteJob ( jobName ) ; } catch ( SchedulerException e ) { throw new SundialSchedulerException ( "ERROR REMOVING JOB!!!" , e ) ; } } | Removes a Job matching the given Job Name |
6,366 | public static void startJob ( String jobName , Map < String , Object > params ) throws SundialSchedulerException { try { JobDataMap jobDataMap = new JobDataMap ( ) ; for ( String key : params . keySet ( ) ) { jobDataMap . put ( key , params . get ( key ) ) ; } getScheduler ( ) . triggerJob ( jobName , jobDataMap ) ; } catch ( SchedulerException e ) { throw new SundialSchedulerException ( "ERROR STARTING JOB!!!" , e ) ; } } | Starts a Job matching the the given Job Name found in jobs . xml or jobs manually added . |
6,367 | public static void removeTrigger ( String triggerName ) throws SundialSchedulerException { try { getScheduler ( ) . unscheduleJob ( triggerName ) ; } catch ( SchedulerException e ) { throw new SundialSchedulerException ( "ERROR REMOVING TRIGGER!!!" , e ) ; } } | Removes a Trigger matching the the given Trigger Name |
6,368 | public static List < String > getAllJobNames ( ) throws SundialSchedulerException { List < String > allJobNames = new ArrayList < String > ( ) ; try { Set < String > allJobKeys = getScheduler ( ) . getJobKeys ( ) ; for ( String jobKey : allJobKeys ) { allJobNames . add ( jobKey ) ; } } catch ( SchedulerException e ) { throw new SundialSchedulerException ( "COULD NOT GET JOB NAMES!!!" , e ) ; } Collections . sort ( allJobNames ) ; return allJobNames ; } | Generates an alphabetically sorted List of all Job names in the DEFAULT job group |
6,369 | public static Map < String , List < Trigger > > getAllJobsAndTriggers ( ) throws SundialSchedulerException { Map < String , List < Trigger > > allJobsMap = new TreeMap < String , List < Trigger > > ( ) ; try { Set < String > allJobKeys = getScheduler ( ) . getJobKeys ( ) ; for ( String jobKey : allJobKeys ) { List < Trigger > triggers = getScheduler ( ) . getTriggersOfJob ( jobKey ) ; allJobsMap . put ( jobKey , triggers ) ; } } catch ( SchedulerException e ) { throw new SundialSchedulerException ( "COULD NOT GET JOB NAMES!!!" , e ) ; } return allJobsMap ; } | Generates a Map of all Job names with corresponding Triggers |
6,370 | public static void shutdown ( ) throws SundialSchedulerException { logger . debug ( "shutdown() called." ) ; try { getScheduler ( ) . shutdown ( ) ; scheduler = null ; } catch ( Exception e ) { throw new SundialSchedulerException ( "COULD NOT SHUTDOWN SCHEDULER!!!" , e ) ; } } | Halts the Scheduler s firing of Triggers and cleans up all resources associated with the Scheduler . |
6,371 | private void initDocumentParser ( ) throws ParserConfigurationException { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory . newInstance ( ) ; docBuilderFactory . setNamespaceAware ( false ) ; docBuilderFactory . setValidating ( true ) ; docBuilderFactory . setAttribute ( "http://java.sun.com/xml/jaxp/properties/schemaLanguage" , "http://www.w3.org/2001/XMLSchema" ) ; docBuilderFactory . setAttribute ( "http://java.sun.com/xml/jaxp/properties/schemaSource" , resolveSchemaSource ( ) ) ; docBuilder = docBuilderFactory . newDocumentBuilder ( ) ; docBuilder . setErrorHandler ( this ) ; xpath = XPathFactory . newInstance ( ) . newXPath ( ) ; } | Initializes the XML parser . |
6,372 | public void processFile ( String fileName , boolean failOnFileNotFound ) throws Exception { boolean fileFound = false ; InputStream f = null ; try { String furl = null ; File file = new File ( fileName ) ; if ( ! file . exists ( ) ) { URL url = classLoadHelper . getResource ( fileName ) ; if ( url != null ) { try { furl = URLDecoder . decode ( url . getPath ( ) , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { furl = url . getPath ( ) ; } file = new File ( furl ) ; try { f = url . openStream ( ) ; } catch ( IOException ignor ) { } } } else { try { f = new java . io . FileInputStream ( file ) ; } catch ( FileNotFoundException e ) { } } if ( f == null ) { fileFound = false ; } else { fileFound = true ; } } finally { try { if ( f != null ) { f . close ( ) ; } } catch ( IOException ioe ) { logger . warn ( "Error closing jobs file " + fileName , ioe ) ; } } if ( ! fileFound ) { if ( failOnFileNotFound ) { throw new SchedulerException ( "File named '" + fileName + "' does not exist." ) ; } else { logger . warn ( "File named '" + fileName + "' does not exist. This is OK if you don't want to use an XML job config file." ) ; } } else { processFile ( fileName ) ; } } | Process the xml file in the given location and schedule all of the jobs defined within it . |
6,373 | public void scheduleJobs ( Scheduler sched ) throws SchedulerException { List < JobDetail > jobs = new LinkedList < JobDetail > ( getLoadedJobs ( ) ) ; List < OperableTrigger > triggers = new LinkedList < OperableTrigger > ( getLoadedTriggers ( ) ) ; logger . info ( "Adding " + jobs . size ( ) + " jobs, " + triggers . size ( ) + " triggers." ) ; for ( JobDetail jobDetail : jobs ) { logger . info ( "Scheduled job: {} " , jobDetail ) ; sched . addJob ( jobDetail ) ; } for ( OperableTrigger trigger : triggers ) { logger . info ( "Scheduled trigger: {}" , trigger ) ; if ( trigger . getStartTime ( ) == null ) { trigger . setStartTime ( new Date ( ) ) ; } Trigger dupeT = sched . getTrigger ( trigger . getName ( ) ) ; if ( dupeT != null ) { if ( ! dupeT . getJobName ( ) . equals ( trigger . getJobName ( ) ) ) { logger . warn ( "Possibly duplicately named ({}) triggers in jobs xml file! " , trigger . getName ( ) ) ; } sched . rescheduleJob ( trigger . getName ( ) , trigger ) ; } else { logger . debug ( "Scheduling job: " + trigger . getJobName ( ) + " with trigger: " + trigger . getName ( ) ) ; try { sched . scheduleJob ( trigger ) ; } catch ( ObjectAlreadyExistsException e ) { logger . debug ( "Adding trigger: " + trigger . getName ( ) + " for job: " + trigger . getJobName ( ) + " failed because the trigger already existed." ) ; } } } } | Schedules the given sets of jobs and triggers . |
6,374 | public ThreadGroup getSchedulerThreadGroup ( ) { if ( threadGroup == null ) { threadGroup = new ThreadGroup ( "QuartzScheduler" ) ; if ( quartzSchedulerResources . getMakeSchedulerThreadDaemon ( ) ) { threadGroup . setDaemon ( true ) ; } } return threadGroup ; } | Returns the name of the thread group for Quartz s main threads . |
6,375 | protected void initContextContainer ( JobExecutionContext jobExecutionContext ) { JobContext jobContext = new JobContext ( ) ; jobContext . addQuartzContext ( jobExecutionContext ) ; contextContainer . set ( jobContext ) ; } | Initialize the ThreadLocal with a JobExecutionContext object |
6,376 | public void shutdown ( ) { synchronized ( nextRunnableLock ) { isShutdown = true ; if ( workers == null ) { return ; } Iterator < WorkerThread > workerThreads = workers . iterator ( ) ; while ( workerThreads . hasNext ( ) ) { WorkerThread wt = workerThreads . next ( ) ; JobRunShell jobRunShell = wt . getRunnable ( ) ; if ( jobRunShell != null ) { log . info ( "Waiting for Job to shutdown: {}" , wt . getRunnable ( ) . getJobName ( ) ) ; } wt . shutdown ( ) ; availWorkers . remove ( wt ) ; } nextRunnableLock . notifyAll ( ) ; } } | Terminate any worker threads in this thread group . |
6,377 | public List < Trigger > getTriggersForJob ( String jobKey ) { ArrayList < Trigger > trigList = new ArrayList < Trigger > ( ) ; synchronized ( lock ) { for ( int i = 0 ; i < wrappedTriggers . size ( ) ; i ++ ) { TriggerWrapper tw = wrappedTriggers . get ( i ) ; if ( tw . jobKey . equals ( jobKey ) ) { trigList . add ( ( OperableTrigger ) tw . trigger . clone ( ) ) ; } } } return trigList ; } | Get all of the Triggers that are associated to the given Job . |
6,378 | public String getMessage ( ) { if ( getValidationExceptions ( ) . size ( ) == 0 ) { return super . getMessage ( ) ; } StringBuffer sb = new StringBuffer ( ) ; boolean first = true ; for ( Iterator iter = getValidationExceptions ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { Exception e = ( Exception ) iter . next ( ) ; if ( ! first ) { sb . append ( '\n' ) ; first = false ; } sb . append ( e . getMessage ( ) ) ; } return sb . toString ( ) ; } | Returns the detail message string . |
6,379 | public void addQuartzContext ( JobExecutionContext jobExecutionContext ) { for ( Object mapKey : jobExecutionContext . getMergedJobDataMap ( ) . keySet ( ) ) { map . put ( ( String ) mapKey , jobExecutionContext . getMergedJobDataMap ( ) . get ( mapKey ) ) ; } map . put ( KEY_JOB_NAME , jobExecutionContext . getJobDetail ( ) . getName ( ) ) ; map . put ( KEY_TRIGGER_NAME , ( jobExecutionContext . getTrigger ( ) . getName ( ) ) ) ; if ( jobExecutionContext . getTrigger ( ) instanceof CronTrigger ) { map . put ( KEY_TRIGGER_CRON_EXPRESSION , ( ( CronTrigger ) jobExecutionContext . getTrigger ( ) ) . getCronExpression ( ) ) ; } } | Add all the mappings from the JobExecutionContext to the JobContext |
6,380 | @ SuppressWarnings ( "unchecked" ) public < T > T get ( String key ) { T value = ( T ) map . get ( key ) ; return value ; } | Get a value from a key out of the JobContext |
6,381 | @ SuppressWarnings ( "unchecked" ) public < T > T getRequiredValue ( String key ) { T value = ( T ) map . get ( key ) ; if ( value == null ) { throw new RequiredParameterException ( ) ; } return value ; } | Get a required value from a key out of the Job Context |
6,382 | public static CronTriggerBuilder cronTriggerBuilder ( String cronExpression ) throws ParseException { CronExpression . validateExpression ( cronExpression ) ; return new CronTriggerBuilder ( cronExpression ) ; } | Create a CronScheduleBuilder with the given cron - expression . |
6,383 | public String escape ( String string ) { int end = string . length ( ) ; int index = nextEscapeIndex ( string , 0 , end ) ; return index == end ? string : escapeSlow ( string , index ) ; } | Returns the escaped form of a given literal string . |
6,384 | public void tick ( long duration , TimeUnit timeUnit ) { long remaining = toTicks ( duration , timeUnit ) ; do { remaining = deltaQueue . tick ( remaining ) ; runUntilIdle ( ) ; } while ( deltaQueue . isNotEmpty ( ) && remaining > 0 ) ; } | Runs time forwards by a given duration executing any commands scheduled for execution during that time period and any background tasks spawned by the scheduled tasks . Therefore when a call to tick returns the executor will be idle . |
6,385 | public void assertIsSatisfied ( ) { if ( firstError != null ) { throw firstError ; } else if ( ! dispatcher . isSatisfied ( ) ) { throw expectationErrorTranslator . translate ( ExpectationError . notAllSatisfied ( this ) ) ; } } | Fails the test if there are any expectations that have not been met . |
6,386 | public ScriptedAction where ( String name , Object value ) { try { interpreter . set ( name , value ) ; } catch ( EvalError e ) { throw new IllegalArgumentException ( "invalid name binding" , e ) ; } return this ; } | Defines a variable that can be referred to by the script . |
6,387 | @ SuppressWarnings ( "unchecked" ) private < T > T asMockedType ( @ SuppressWarnings ( "unused" ) T mockObject , Object capturingImposter ) { return ( T ) capturingImposter ; } | Damn you Java generics! Damn you to HELL! |
6,388 | protected synchronized void sendUpdates ( ) { log . debug ( "sendUpdates" ) ; final int currentVersion = getVersion ( ) ; log . debug ( "Current version: {}" , currentVersion ) ; final String name = getName ( ) ; Set < ISharedObjectEvent > ownerEvents = ownerMessage . getEvents ( ) ; if ( ! ownerEvents . isEmpty ( ) ) { final TreeSet < ISharedObjectEvent > events = new TreeSet < > ( ownerEvents ) ; ownerEvents . removeAll ( events ) ; if ( source != null ) { final RTMPConnection con = ( RTMPConnection ) source ; SharedObjectService . submitTask ( ( ) -> { Red5 . setConnectionLocal ( con ) ; con . sendSharedObjectMessage ( name , currentVersion , persistent , events ) ; Red5 . setConnectionLocal ( null ) ; } ) ; } } else if ( log . isTraceEnabled ( ) ) { log . trace ( "No owner events to send" ) ; } if ( ! syncEvents . isEmpty ( ) ) { final TreeSet < ISharedObjectEvent > events = new TreeSet < > ( syncEvents ) ; syncEvents . removeAll ( events ) ; Set < IEventListener > listeners = getListeners ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Listeners: {}" , listeners ) ; } listeners . stream ( ) . filter ( listener -> listener != source ) . forEach ( listener -> { final RTMPConnection con = ( RTMPConnection ) listener ; if ( con . isConnected ( ) ) { SharedObjectService . submitTask ( ( ) -> { Red5 . setConnectionLocal ( con ) ; con . sendSharedObjectMessage ( name , currentVersion , persistent , events ) ; Red5 . setConnectionLocal ( null ) ; } ) ; } else { log . debug ( "Skipping {} connection: {}" , RTMP . states [ con . getStateCode ( ) ] , con . getId ( ) ) ; if ( con . isDisconnected ( ) ) { unregister ( con ) ; } } } ) ; } else if ( log . isTraceEnabled ( ) ) { log . trace ( "No sync events to send" ) ; } } | Send update notification over data channel of RTMP connection |
6,389 | protected void notifyModified ( ) { log . debug ( "notifyModified - modified: {} update counter: {}" , modified . get ( ) , updateCounter . get ( ) ) ; if ( updateCounter . get ( ) == 0 ) { if ( modified . get ( ) ) { updateVersion ( ) ; lastModified = System . currentTimeMillis ( ) ; if ( storage == null || ! storage . save ( this ) ) { log . warn ( "Could not store shared object" ) ; } } sendUpdates ( ) ; modified . compareAndSet ( true , false ) ; } } | Send notification about modification of SO |
6,390 | protected void returnAttributeValue ( String name ) { ownerMessage . addEvent ( Type . CLIENT_UPDATE_DATA , name , getAttribute ( name ) ) ; } | Return an attribute value to the owner . |
6,391 | public Object getAttribute ( String name , Object value ) { log . debug ( "getAttribute - name: {} value: {}" , name , value ) ; Object result = null ; if ( name != null ) { result = attributes . putIfAbsent ( name , value ) ; if ( result == null ) { modified . set ( true ) ; final SharedObjectEvent event = new SharedObjectEvent ( Type . CLIENT_UPDATE_DATA , name , value ) ; if ( ownerMessage . addEvent ( event ) && syncEvents . add ( event ) ) { notifyModified ( ) ; changeStats . incrementAndGet ( ) ; } result = value ; } } return result ; } | Return attribute by name and set if it doesn t exist yet . |
6,392 | public boolean removeAttribute ( String name ) { boolean result = true ; final SharedObjectEvent event = new SharedObjectEvent ( Type . CLIENT_DELETE_DATA , name , null ) ; if ( ownerMessage . addEvent ( event ) ) { if ( super . removeAttribute ( name ) ) { modified . set ( true ) ; syncEvents . add ( event ) ; deleteStats . incrementAndGet ( ) ; } else { result = false ; } notifyModified ( ) ; } return result ; } | Removes attribute with given name |
6,393 | protected void sendMessage ( String handler , List < ? > arguments ) { final SharedObjectEvent event = new SharedObjectEvent ( Type . CLIENT_SEND_MESSAGE , handler , arguments ) ; if ( ownerMessage . addEvent ( event ) ) { syncEvents . add ( event ) ; sendStats . incrementAndGet ( ) ; if ( log . isTraceEnabled ( ) ) { log . trace ( "Send message: {}" , arguments ) ; } } } | Broadcast event to event handler |
6,394 | protected boolean register ( IEventListener listener ) { log . debug ( "register - listener: {}" , listener ) ; boolean registered = listeners . add ( listener ) ; if ( registered ) { listenerStats . increment ( ) ; ownerMessage . addEvent ( Type . CLIENT_INITIAL_DATA , null , null ) ; if ( ! isPersistent ( ) ) { ownerMessage . addEvent ( Type . CLIENT_CLEAR_DATA , null , null ) ; } if ( ! attributes . isEmpty ( ) ) { ownerMessage . addEvent ( new SharedObjectEvent ( Type . CLIENT_UPDATE_DATA , null , getAttributes ( ) ) ) ; } notifyModified ( ) ; } return registered ; } | Register event listener |
6,395 | protected void unregister ( IEventListener listener ) { log . debug ( "unregister - listener: {}" , listener ) ; if ( listeners . remove ( listener ) ) { listenerStats . decrement ( ) ; } } | Unregister event listener |
6,396 | protected void checkRelease ( ) { if ( ! isPersistent ( ) && listeners . isEmpty ( ) && ! isAcquired ( ) ) { log . info ( "Deleting shared object {} because all clients disconnected and it is no longer acquired" , name ) ; if ( storage != null ) { if ( ! storage . remove ( this ) ) { log . error ( "Could not remove shared object" ) ; } } close ( ) ; } } | Check if shared object must be released . |
6,397 | protected void beginUpdate ( IEventListener listener ) { log . debug ( "beginUpdate - listener: {}" , listener ) ; source = listener ; updateCounter . incrementAndGet ( ) ; } | Begin update of this Shared Object and setting listener |
6,398 | protected boolean clear ( ) { log . debug ( "clear" ) ; super . removeAttributes ( ) ; ownerMessage . addEvent ( Type . CLIENT_CLEAR_DATA , name , null ) ; notifyModified ( ) ; changeStats . incrementAndGet ( ) ; return true ; } | Deletes all the attributes and sends a clear event to all listeners . The persistent data object is also removed from a persistent shared object . |
6,399 | protected void close ( ) { log . debug ( "close" ) ; closed . compareAndSet ( false , true ) ; super . removeAttributes ( ) ; listeners . clear ( ) ; syncEvents . clear ( ) ; ownerMessage . getEvents ( ) . clear ( ) ; } | Detaches a reference from this shared object reset it s state this will destroy the reference immediately . This is useful when you don t want to proxy a shared object any longer . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.