repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.createSecurityGroup | 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;
} | java | 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;
} | [
"private",
"CreateSecurityGroupResponseType",
"createSecurityGroup",
"(",
"final",
"String",
"groupName",
",",
"final",
"String",
"groupDescription",
",",
"final",
"String",
"vpcId",
")",
"{",
"CreateSecurityGroupResponseType",
"ret",
"=",
"new",
"CreateSecurityGroupRespons... | Handles "createSecurityGroup" request to create SecurityGroup and returns response with a SecurityGroup.
@param vpcId vpc Id for SecurityGroup.
@param groupName group Name.
@param groupDescription group Desc.
@return a CreateSecurityGroupResponseType with our new SecurityGroup | [
"Handles",
"createSecurityGroup",
"request",
"to",
"create",
"SecurityGroup",
"and",
"returns",
"response",
"with",
"a",
"SecurityGroup",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1494-L1502 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.authorizeSecurityGroupIngress | 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;
} | java | 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;
} | [
"private",
"AuthorizeSecurityGroupIngressResponseType",
"authorizeSecurityGroupIngress",
"(",
"final",
"String",
"groupId",
",",
"final",
"String",
"ipProtocol",
",",
"final",
"Integer",
"fromPort",
",",
"final",
"Integer",
"toPort",
",",
"final",
"String",
"cidrIp",
")... | Handles "authorizeSecurityGroupIngress" request to SecurityGroup and returns response with a SecurityGroup.
@param groupId group Id for SecurityGroup.
@param ipProtocol Ip protocol Name.
@param fromPort from port ranges.
@param toPort to port ranges.
@param cidrIp cidr Ip for Permission
@return a AuthorizeSecurityGroupIngressResponseType with our new SecurityGroup | [
"Handles",
"authorizeSecurityGroupIngress",
"request",
"to",
"SecurityGroup",
"and",
"returns",
"response",
"with",
"a",
"SecurityGroup",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1513-L1519 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.authorizeSecurityGroupEgress | 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;
} | java | 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;
} | [
"private",
"AuthorizeSecurityGroupEgressResponseType",
"authorizeSecurityGroupEgress",
"(",
"final",
"String",
"groupId",
",",
"final",
"String",
"ipProtocol",
",",
"final",
"Integer",
"fromPort",
",",
"final",
"Integer",
"toPort",
",",
"final",
"String",
"cidrIp",
")",... | Handles "authorizeSecurityGroupEgress" request to SecurityGroup and returns response with a SecurityGroup.
@param groupId group Id for SecurityGroup.
@param ipProtocol Ip protocol Name.
@param fromPort from port ranges.
@param toPort to port ranges.
@param cidrIp cidr Ip for Permission
@return a AuthorizeSecurityGroupEgressResponseType with our new SecurityGroup | [
"Handles",
"authorizeSecurityGroupEgress",
"request",
"to",
"SecurityGroup",
"and",
"returns",
"response",
"with",
"a",
"SecurityGroup",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1530-L1536 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.createInternetGateway | 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;
} | java | 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;
} | [
"private",
"CreateInternetGatewayResponseType",
"createInternetGateway",
"(",
")",
"{",
"CreateInternetGatewayResponseType",
"ret",
"=",
"new",
"CreateInternetGatewayResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
".",... | Handles "createInternetGateway" request to create InternetGateway and returns response with a InternetGateway.
@return a CreateInternetGatewayResponseType with our new InternetGateway | [
"Handles",
"createInternetGateway",
"request",
"to",
"create",
"InternetGateway",
"and",
"returns",
"response",
"with",
"a",
"InternetGateway",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1542-L1551 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.deleteRouteTable | private DeleteRouteTableResponseType deleteRouteTable(final String routeTableId) {
DeleteRouteTableResponseType ret = new DeleteRouteTableResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockRouteTableController.deleteRouteTable(routeTableId);
return ret;
} | java | private DeleteRouteTableResponseType deleteRouteTable(final String routeTableId) {
DeleteRouteTableResponseType ret = new DeleteRouteTableResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockRouteTableController.deleteRouteTable(routeTableId);
return ret;
} | [
"private",
"DeleteRouteTableResponseType",
"deleteRouteTable",
"(",
"final",
"String",
"routeTableId",
")",
"{",
"DeleteRouteTableResponseType",
"ret",
"=",
"new",
"DeleteRouteTableResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",... | Handles "deleteRouteTable" request to delete routetable and returns response with a route table.
@param routeTableId Route table Id.
@return a CreateRouteTableResponseType with route table | [
"Handles",
"deleteRouteTable",
"request",
"to",
"delete",
"routetable",
"and",
"returns",
"response",
"with",
"a",
"route",
"table",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1558-L1563 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.deleteSubnet | private DeleteSubnetResponseType deleteSubnet(final String subnetId) {
DeleteSubnetResponseType ret = new DeleteSubnetResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockSubnetController.deleteSubnet(subnetId);
return ret;
} | java | private DeleteSubnetResponseType deleteSubnet(final String subnetId) {
DeleteSubnetResponseType ret = new DeleteSubnetResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockSubnetController.deleteSubnet(subnetId);
return ret;
} | [
"private",
"DeleteSubnetResponseType",
"deleteSubnet",
"(",
"final",
"String",
"subnetId",
")",
"{",
"DeleteSubnetResponseType",
"ret",
"=",
"new",
"DeleteSubnetResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
"."... | Handles "deleteSubnet" request to delete subnet and returns response with a subnet.
@param subnetId Subnet Id.
@return a DeleteSubnetResponseType with subnet. | [
"Handles",
"deleteSubnet",
"request",
"to",
"delete",
"subnet",
"and",
"returns",
"response",
"with",
"a",
"subnet",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1570-L1575 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.deleteSecurityGroup | private DeleteSecurityGroupResponseType deleteSecurityGroup(final String securityGroupId) {
DeleteSecurityGroupResponseType ret = new DeleteSecurityGroupResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockSecurityGroupController.deleteSecurityGroup(securityGroupId);
return ret;
} | java | private DeleteSecurityGroupResponseType deleteSecurityGroup(final String securityGroupId) {
DeleteSecurityGroupResponseType ret = new DeleteSecurityGroupResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockSecurityGroupController.deleteSecurityGroup(securityGroupId);
return ret;
} | [
"private",
"DeleteSecurityGroupResponseType",
"deleteSecurityGroup",
"(",
"final",
"String",
"securityGroupId",
")",
"{",
"DeleteSecurityGroupResponseType",
"ret",
"=",
"new",
"DeleteSecurityGroupResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
... | Handles "deleteSecurityGroup" request to delete SecurityGroup and returns response with a SecurityGroup.
@param securityGroupId SecurityGroup Id.
@return a DeleteSecurityGroupResponseType with SecurityGroup. | [
"Handles",
"deleteSecurityGroup",
"request",
"to",
"delete",
"SecurityGroup",
"and",
"returns",
"response",
"with",
"a",
"SecurityGroup",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1582-L1587 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.deleteVolume | private DeleteVolumeResponseType deleteVolume(final String volumeId) {
DeleteVolumeResponseType ret = new DeleteVolumeResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockVolumeController.deleteVolume(volumeId);
return ret;
} | java | private DeleteVolumeResponseType deleteVolume(final String volumeId) {
DeleteVolumeResponseType ret = new DeleteVolumeResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockVolumeController.deleteVolume(volumeId);
return ret;
} | [
"private",
"DeleteVolumeResponseType",
"deleteVolume",
"(",
"final",
"String",
"volumeId",
")",
"{",
"DeleteVolumeResponseType",
"ret",
"=",
"new",
"DeleteVolumeResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
"."... | Handles "deleteVolume" request to delete volume and returns response with a volume.
@param volumeId Volume Id.
@return a DeleteVolumeResponseType with volume. | [
"Handles",
"deleteVolume",
"request",
"to",
"delete",
"volume",
"and",
"returns",
"response",
"with",
"a",
"volume",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1594-L1599 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.isVolumeIdExists | 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;
} | java | 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;
} | [
"private",
"boolean",
"isVolumeIdExists",
"(",
"final",
"List",
"<",
"String",
">",
"volumeIds",
",",
"final",
"String",
"volumeId",
")",
"{",
"if",
"(",
"volumeIds",
"!=",
"null",
"&&",
"volumeIds",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"for",
"(... | Check whether volumeId exists in list.
@param volumeIds List of volume Ids.
@param volumeId to check in the list.
@return true if volumeId is valid. | [
"Check",
"whether",
"volumeId",
"exists",
"in",
"list",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1730-L1740 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.describeSubnets | 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;
} | java | 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;
} | [
"private",
"DescribeSubnetsResponseType",
"describeSubnets",
"(",
")",
"{",
"DescribeSubnetsResponseType",
"ret",
"=",
"new",
"DescribeSubnetsResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
... | Handles "describeSubnets" request and returns response with a subnet Set.
@return a DescribeSubnetsResponseType with Created Vpcs | [
"Handles",
"describeSubnets",
"request",
"and",
"returns",
"response",
"with",
"a",
"subnet",
"Set",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1747-L1777 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.describeInternetGateways | 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;
} | java | 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;
} | [
"private",
"DescribeInternetGatewaysResponseType",
"describeInternetGateways",
"(",
")",
"{",
"DescribeInternetGatewaysResponseType",
"ret",
"=",
"new",
"DescribeInternetGatewaysResponseType",
"(",
")",
";",
"InternetGatewaySetType",
"internetGatewaySet",
"=",
"new",
"InternetGat... | Handles "describeInternetGateways" request and returns response with a Internet gateway.
@return a DescribeInternetGatewaysResponseType with Created InternetGateways. | [
"Handles",
"describeInternetGateways",
"request",
"and",
"returns",
"response",
"with",
"a",
"Internet",
"gateway",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1784-L1824 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.describeSecurityGroups | 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();
// initialize securityGroupItem
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()) {
// initialize ipPermission
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()) {
// initialize ipPermission
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;
} | java | 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();
// initialize securityGroupItem
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()) {
// initialize ipPermission
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()) {
// initialize ipPermission
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;
} | [
"private",
"DescribeSecurityGroupsResponseType",
"describeSecurityGroups",
"(",
")",
"{",
"DescribeSecurityGroupsResponseType",
"ret",
"=",
"new",
"DescribeSecurityGroupsResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
... | Handles "describeSecurityGroups" request and returns response with a security group.
@return a DescribeInternetGatewaysResponseType with our predefined internet gateway in aws-mock.properties (or if
not overridden, as defined in aws-mock-default.properties) | [
"Handles",
"describeSecurityGroups",
"request",
"and",
"returns",
"response",
"with",
"a",
"security",
"group",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1832-L1880 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.describeVpcs | 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;
} | java | 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;
} | [
"private",
"DescribeVpcsResponseType",
"describeVpcs",
"(",
")",
"{",
"DescribeVpcsResponseType",
"ret",
"=",
"new",
"DescribeVpcsResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
")",
")",
... | Handles "describeVpcs" request and returns response with a vpc.
@return a DescribeVpcsResponseType with our predefined vpc in aws-mock.properties (or if not overridden, as
defined in aws-mock-default.properties) | [
"Handles",
"describeVpcs",
"request",
"and",
"returns",
"response",
"with",
"a",
"vpc",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1888-L1912 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.describeTags | 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;
} | java | 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;
} | [
"private",
"DescribeTagsResponseType",
"describeTags",
"(",
")",
"{",
"DescribeTagsResponseType",
"ret",
"=",
"new",
"DescribeTagsResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
")",
")",
... | Handles "describeTags" request and returns response with a Tags.
@return a DescribeTagsResponseType with our predefined Tags in aws-mock.properties (or if not overridden, as
defined in aws-mock-default.properties) | [
"Handles",
"describeTags",
"request",
"and",
"returns",
"response",
"with",
"a",
"Tags",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1920-L1941 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.createTags | 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;
} | java | 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;
} | [
"private",
"CreateTagsResponseType",
"createTags",
"(",
"final",
"List",
"<",
"String",
">",
"resourcesSet",
",",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"tagSet",
")",
"{",
"CreateTagsResponseType",
"ret",
"=",
"new",
"CreateTagsResponseType",
"(",
"... | Handles "createTags" request and create new Tags.
@param resourcesSet List of resourceIds.
@param tagSet Map for key, value of tags.
@return a CreateTagsResponseType with Status of Tags. | [
"Handles",
"createTags",
"request",
"and",
"create",
"new",
"Tags",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1949-L1956 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.deleteTags | private DeleteTagsResponseType deleteTags(final List<String> resources) {
DeleteTagsResponseType ret = new DeleteTagsResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockTagsController.deleteTags(resources);
return ret;
} | java | private DeleteTagsResponseType deleteTags(final List<String> resources) {
DeleteTagsResponseType ret = new DeleteTagsResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockTagsController.deleteTags(resources);
return ret;
} | [
"private",
"DeleteTagsResponseType",
"deleteTags",
"(",
"final",
"List",
"<",
"String",
">",
"resources",
")",
"{",
"DeleteTagsResponseType",
"ret",
"=",
"new",
"DeleteTagsResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
... | Handles "deleteTags" request and delete Tags and returns response.
@param resources : List of resource Id to be deleted.
@return a DeleteTagsResponseType with Status | [
"Handles",
"deleteTags",
"request",
"and",
"delete",
"Tags",
"and",
"returns",
"response",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1963-L1969 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.createVpc | 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;
} | java | 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;
} | [
"private",
"CreateVpcResponseType",
"createVpc",
"(",
"final",
"String",
"cidrBlock",
",",
"final",
"String",
"instanceTenancy",
")",
"{",
"CreateVpcResponseType",
"ret",
"=",
"new",
"CreateVpcResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
... | Handles "createVpc" request and create new Vpc.
@param cidrBlock : vpc cidrBlock.
@param instanceTenancy : vpc instanceTenancy.
@return a CreateVpcResponseType with new Vpc. | [
"Handles",
"createVpc",
"request",
"and",
"create",
"new",
"Vpc",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1977-L1990 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.deleteVpc | private DeleteVpcResponseType deleteVpc(final String vpcId) {
DeleteVpcResponseType ret = new DeleteVpcResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockVpcController.deleteVpc(vpcId);
return ret;
} | java | private DeleteVpcResponseType deleteVpc(final String vpcId) {
DeleteVpcResponseType ret = new DeleteVpcResponseType();
ret.setRequestId(UUID.randomUUID().toString());
mockVpcController.deleteVpc(vpcId);
return ret;
} | [
"private",
"DeleteVpcResponseType",
"deleteVpc",
"(",
"final",
"String",
"vpcId",
")",
"{",
"DeleteVpcResponseType",
"ret",
"=",
"new",
"DeleteVpcResponseType",
"(",
")",
";",
"ret",
".",
"setRequestId",
"(",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",... | Handles "deleteVpc" request and delete Vpc and returns response.
@param vpcId : Vpc Id to be deleted.
@return a DeleteVpcResponseType with new Vpc | [
"Handles",
"deleteVpc",
"request",
"and",
"delete",
"Vpc",
"and",
"returns",
"response",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L1997-L2003 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.getXmlError | 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));
// fake a random UUID as request ID
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;
} | java | 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));
// fake a random UUID as request ID
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;
} | [
"private",
"String",
"getXmlError",
"(",
"final",
"String",
"errorCode",
",",
"final",
"String",
"errorMessage",
")",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"data",
"=",
"new",
"HashMap",
"<",
"String",
",",
"Object",
">",
"(",
")",
";",
"data",
... | Generate error response body in xml and write it with writer.
@param errorCode
the error code wrapped in the xml response
@param errorMessage
the error message wrapped in the xml response
@return xml body for an error message which can be recognized by AWS clients | [
"Generate",
"error",
"response",
"body",
"in",
"xml",
"and",
"write",
"it",
"with",
"writer",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L2014-L2030 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java | MockEC2QueryHandler.getBlankResponseXml | 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;
} | java | 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;
} | [
"private",
"String",
"getBlankResponseXml",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"data",
"=",
"new",
"HashMap",
"<",
"String",
",",
"Object",
">",
"(",
")",
";",
"data",
".",
"put",
"(",
"\"requestID\"",
",",
"UUID",
".",
"randomUUI... | Generate blank response body in xml and write it with writer.
@return xml body blank response which can be recognized by AWS clients | [
"Generate",
"blank",
"response",
"body",
"in",
"xml",
"and",
"write",
"it",
"with",
"writer",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEC2QueryHandler.java#L2037-L2050 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java | MockEc2Controller.describeInstances | public Collection<AbstractMockEc2Instance> describeInstances(final Set<String> instanceIDs) {
if (null == instanceIDs || instanceIDs.size() == 0) {
return allMockEc2Instances.values();
} else {
return getInstances(instanceIDs);
}
} | java | public Collection<AbstractMockEc2Instance> describeInstances(final Set<String> instanceIDs) {
if (null == instanceIDs || instanceIDs.size() == 0) {
return allMockEc2Instances.values();
} else {
return getInstances(instanceIDs);
}
} | [
"public",
"Collection",
"<",
"AbstractMockEc2Instance",
">",
"describeInstances",
"(",
"final",
"Set",
"<",
"String",
">",
"instanceIDs",
")",
"{",
"if",
"(",
"null",
"==",
"instanceIDs",
"||",
"instanceIDs",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"re... | List mock ec2 instances in current aws-mock.
@param instanceIDs
a filter of specified instance IDs for the target instance to describe
@return a collection of {@link AbstractMockEc2Instance} with specified instance IDs, or all of the mock ec2
instances if no instance IDs as filtered | [
"List",
"mock",
"ec2",
"instances",
"in",
"current",
"aws",
"-",
"mock",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java#L102-L108 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java | MockEc2Controller.listInstanceIDs | 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;
}
} | java | 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;
}
} | [
"public",
"List",
"<",
"String",
">",
"listInstanceIDs",
"(",
"final",
"Set",
"<",
"String",
">",
"instanceIDs",
")",
"{",
"Set",
"<",
"String",
">",
"allInstanceIDs",
"=",
"allMockEc2Instances",
".",
"keySet",
"(",
")",
";",
"if",
"(",
"null",
"==",
"in... | List mock ec2 instance IDs in current aws-mock.
@param instanceIDs
a filter of specified instance IDs for the target instance to describe
@return a collection of IDs with specified instance IDs, or all of the mock ec2 instanceIDs if not filtered | [
"List",
"mock",
"ec2",
"instance",
"IDs",
"in",
"current",
"aws",
"-",
"mock",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java#L117-L130 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java | MockEc2Controller.stopInstances | 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;
} | java | 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;
} | [
"public",
"List",
"<",
"InstanceStateChangeType",
">",
"stopInstances",
"(",
"final",
"Set",
"<",
"String",
">",
"instanceIDs",
")",
"{",
"List",
"<",
"InstanceStateChangeType",
">",
"ret",
"=",
"new",
"ArrayList",
"<",
"InstanceStateChangeType",
">",
"(",
")",
... | Stop one or more existing mock ec2 instances.
@param instanceIDs
a set of instance IDs for those instances to stop
@return a list of state change messages (typically running to stopping) | [
"Stop",
"one",
"or",
"more",
"existing",
"mock",
"ec2",
"instances",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java#L267-L295 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java | MockEc2Controller.getInstances | private Collection<AbstractMockEc2Instance> getInstances(final Set<String> instanceIDs) {
Collection<AbstractMockEc2Instance> ret = new ArrayList<AbstractMockEc2Instance>();
for (String instanceID : instanceIDs) {
ret.add(getMockEc2Instance(instanceID));
}
return ret;
} | java | private Collection<AbstractMockEc2Instance> getInstances(final Set<String> instanceIDs) {
Collection<AbstractMockEc2Instance> ret = new ArrayList<AbstractMockEc2Instance>();
for (String instanceID : instanceIDs) {
ret.add(getMockEc2Instance(instanceID));
}
return ret;
} | [
"private",
"Collection",
"<",
"AbstractMockEc2Instance",
">",
"getInstances",
"(",
"final",
"Set",
"<",
"String",
">",
"instanceIDs",
")",
"{",
"Collection",
"<",
"AbstractMockEc2Instance",
">",
"ret",
"=",
"new",
"ArrayList",
"<",
"AbstractMockEc2Instance",
">",
... | Get mock ec2 instances by instance IDs.
@param instanceIDs
IDs of the mock ec2 instances to get
@return the mock ec2 instances object | [
"Get",
"mock",
"ec2",
"instances",
"by",
"instance",
"IDs",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java#L361-L367 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java | MockEc2Controller.destroyCleanupTerminatedInstanceTimer | public void destroyCleanupTerminatedInstanceTimer() {
cleanupTerminatedInstancesScheduledFuture.cancel(true);
cleanupTerminatedInstancesScheduledFuture = null;
cleanupTerminatedInstancesTimer.shutdown();
cleanupTerminatedInstancesTimer = null;
} | java | public void destroyCleanupTerminatedInstanceTimer() {
cleanupTerminatedInstancesScheduledFuture.cancel(true);
cleanupTerminatedInstancesScheduledFuture = null;
cleanupTerminatedInstancesTimer.shutdown();
cleanupTerminatedInstancesTimer = null;
} | [
"public",
"void",
"destroyCleanupTerminatedInstanceTimer",
"(",
")",
"{",
"cleanupTerminatedInstancesScheduledFuture",
".",
"cancel",
"(",
"true",
")",
";",
"cleanupTerminatedInstancesScheduledFuture",
"=",
"null",
";",
"cleanupTerminatedInstancesTimer",
".",
"shutdown",
"(",... | Cancel the internal timer of cleaning up terminated mock ec2 instances. | [
"Cancel",
"the",
"internal",
"timer",
"of",
"cleaning",
"up",
"terminated",
"mock",
"ec2",
"instances",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockEc2Controller.java#L433-L438 | train |
treelogic-swe/aws-mock | example/java/full/client-usage/DescribeImagesExample.java | DescribeImagesExample.describeAllImages | public static List<Image> describeAllImages() {
// pass any credentials as aws-mock does not authenticate them at all
AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);
// the mock endpoint for ec2 which runs on your computer
String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
amazonEC2Client.setEndpoint(ec2Endpoint);
// describe all AMIs in aws-mock.
DescribeImagesResult result = amazonEC2Client.describeImages();
return result.getImages();
} | java | public static List<Image> describeAllImages() {
// pass any credentials as aws-mock does not authenticate them at all
AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);
// the mock endpoint for ec2 which runs on your computer
String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
amazonEC2Client.setEndpoint(ec2Endpoint);
// describe all AMIs in aws-mock.
DescribeImagesResult result = amazonEC2Client.describeImages();
return result.getImages();
} | [
"public",
"static",
"List",
"<",
"Image",
">",
"describeAllImages",
"(",
")",
"{",
"// pass any credentials as aws-mock does not authenticate them at all",
"AWSCredentials",
"credentials",
"=",
"new",
"BasicAWSCredentials",
"(",
"\"foo\"",
",",
"\"bar\"",
")",
";",
"Amazo... | Describe all available AMIs within aws-mock.
@return a list of AMIs | [
"Describe",
"all",
"available",
"AMIs",
"within",
"aws",
"-",
"mock",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/example/java/full/client-usage/DescribeImagesExample.java#L30-L43 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockVpcController.java | MockVpcController.createVpc | 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);
// Make sure only one VPC is default.
synchronized (this) {
if (allMockVpcInstances.size() == 0) {
ret.setIsDefault(true);
} else {
ret.setIsDefault(false);
}
allMockVpcInstances.put(ret.getVpcId(), ret);
}
return ret;
} | java | 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);
// Make sure only one VPC is default.
synchronized (this) {
if (allMockVpcInstances.size() == 0) {
ret.setIsDefault(true);
} else {
ret.setIsDefault(false);
}
allMockVpcInstances.put(ret.getVpcId(), ret);
}
return ret;
} | [
"public",
"MockVpc",
"createVpc",
"(",
"final",
"String",
"cidrBlock",
",",
"final",
"String",
"instanceTenancy",
")",
"{",
"MockVpc",
"ret",
"=",
"new",
"MockVpc",
"(",
")",
";",
"ret",
".",
"setCidrBlock",
"(",
"cidrBlock",
")",
";",
"ret",
".",
"setVpcI... | Create the mock VPC.
@param cidrBlock VPC cidr block.
@param instanceTenancy VPC instance tenancy.
@return mock VPC. | [
"Create",
"the",
"mock",
"VPC",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockVpcController.java#L80-L98 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockVpcController.java | MockVpcController.deleteVpc | public MockVpc deleteVpc(final String vpcId) {
if (vpcId != null && allMockVpcInstances.containsKey(vpcId)) {
return allMockVpcInstances.remove(vpcId);
}
return null;
} | java | public MockVpc deleteVpc(final String vpcId) {
if (vpcId != null && allMockVpcInstances.containsKey(vpcId)) {
return allMockVpcInstances.remove(vpcId);
}
return null;
} | [
"public",
"MockVpc",
"deleteVpc",
"(",
"final",
"String",
"vpcId",
")",
"{",
"if",
"(",
"vpcId",
"!=",
"null",
"&&",
"allMockVpcInstances",
".",
"containsKey",
"(",
"vpcId",
")",
")",
"{",
"return",
"allMockVpcInstances",
".",
"remove",
"(",
"vpcId",
")",
... | Delete vpc.
@param vpcId
vpcId to be deleted
@return Mock vpc. | [
"Delete",
"vpc",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockVpcController.java#L107-L113 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/cloudwatch/control/MockCloudWatchQueryHandler.java | MockCloudWatchQueryHandler.getMetricStatistics | 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;
} | java | 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;
} | [
"private",
"GetMetricStatisticsResponse",
"getMetricStatistics",
"(",
"final",
"String",
"[",
"]",
"statistics",
",",
"final",
"DateTime",
"startTime",
",",
"final",
"DateTime",
"endTime",
",",
"final",
"int",
"period",
",",
"final",
"String",
"metricName",
")",
"... | Handles "GetMetricStatistics" request, as simple as without any filters
to use.
@param statistics
Metric statistics.
@param startTime
Metric statistics start time.
@param endTime
Metric statistics end time.
@param period
Metric collection period.
@param metricName
Metric Name.
@return a GetMetricStatisticsResult for metricName. | [
"Handles",
"GetMetricStatistics",
"request",
"as",
"simple",
"as",
"without",
"any",
"filters",
"to",
"use",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/cloudwatch/control/MockCloudWatchQueryHandler.java#L339-L367 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/cloudwatch/control/MockCloudWatchQueryHandler.java | MockCloudWatchQueryHandler.describeAlarms | 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;
} | java | 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;
} | [
"private",
"DescribeAlarmsResponse",
"describeAlarms",
"(",
")",
"{",
"DescribeAlarmsResponse",
"ret",
"=",
"new",
"DescribeAlarmsResponse",
"(",
")",
";",
"DescribeAlarmsResult",
"result",
"=",
"new",
"DescribeAlarmsResult",
"(",
")",
";",
"MetricAlarms",
"metricAlarms... | Handles "describeAlarms" request.
@return a GetMetricStatisticsResult for metricName. | [
"Handles",
"describeAlarms",
"request",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/cloudwatch/control/MockCloudWatchQueryHandler.java#L374-L396 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/cloudwatch/control/MockCloudWatchQueryHandler.java | MockCloudWatchQueryHandler.toXMLGregorianCalendar | 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;
} | java | 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;
} | [
"private",
"XMLGregorianCalendar",
"toXMLGregorianCalendar",
"(",
"final",
"DateTime",
"date",
")",
"{",
"GregorianCalendar",
"gCalendar",
"=",
"new",
"GregorianCalendar",
"(",
"date",
".",
"getZone",
"(",
")",
".",
"toTimeZone",
"(",
")",
")",
";",
"gCalendar",
... | Converts java.util.Date to javax.xml.datatype.XMLGregorianCalendar.
@param date
Date parameter.
@return a XMLGregorianCalendar for date. | [
"Converts",
"java",
".",
"util",
".",
"Date",
"to",
"javax",
".",
"xml",
".",
"datatype",
".",
"XMLGregorianCalendar",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/cloudwatch/control/MockCloudWatchQueryHandler.java#L405-L417 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/cloudwatch/control/MockCloudWatchQueryHandler.java | MockCloudWatchQueryHandler.getMetricUnit | 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);
} | java | 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);
} | [
"private",
"StandardUnit",
"getMetricUnit",
"(",
"final",
"String",
"metricName",
")",
"{",
"String",
"result",
"=",
"null",
";",
"if",
"(",
"metricName",
".",
"equals",
"(",
"Constants",
".",
"CPU_UTILIZATION",
")",
")",
"{",
"result",
"=",
"Constants",
"."... | Get the Metric Unit.
@param metricName
Metric Name parameter.
@return Standard Unit Value. | [
"Get",
"the",
"Metric",
"Unit",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/cloudwatch/control/MockCloudWatchQueryHandler.java#L659-L695 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/common/util/TemplateUtils.java | TemplateUtils.write | public static void write(final String templateFilename, final Map<String, Object> data,
final Writer writer) {
Template tmpl = null;
try {
/*-
* note that we don't need to cache templates by ourselves since getTemplate() does that internally already
*/
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);
}
} | java | public static void write(final String templateFilename, final Map<String, Object> data,
final Writer writer) {
Template tmpl = null;
try {
/*-
* note that we don't need to cache templates by ourselves since getTemplate() does that internally already
*/
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);
}
} | [
"public",
"static",
"void",
"write",
"(",
"final",
"String",
"templateFilename",
",",
"final",
"Map",
"<",
"String",
",",
"Object",
">",
"data",
",",
"final",
"Writer",
"writer",
")",
"{",
"Template",
"tmpl",
"=",
"null",
";",
"try",
"{",
"/*-\n ... | Process with given template + data and then put result to writer.
@param templateFilename
filename of the .ftl file
@param data
data to fill in the template, as pairs of key-values
@param writer
target writer to print the result | [
"Process",
"with",
"given",
"template",
"+",
"data",
"and",
"then",
"put",
"result",
"to",
"writer",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/common/util/TemplateUtils.java#L68-L110 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/common/util/TemplateUtils.java | TemplateUtils.get | public static String get(final String templateName, final Map<String, Object> data) {
StringWriter writer = new StringWriter();
write(templateName, data, writer);
return writer.toString();
} | java | public static String get(final String templateName, final Map<String, Object> data) {
StringWriter writer = new StringWriter();
write(templateName, data, writer);
return writer.toString();
} | [
"public",
"static",
"String",
"get",
"(",
"final",
"String",
"templateName",
",",
"final",
"Map",
"<",
"String",
",",
"Object",
">",
"data",
")",
"{",
"StringWriter",
"writer",
"=",
"new",
"StringWriter",
"(",
")",
";",
"write",
"(",
"templateName",
",",
... | Process with given template + data and get result as a string.
@param templateName
filename of the .ftl file
@param data
data to fill in the template, as pairs of key-values
@return processed result from template and data | [
"Process",
"with",
"given",
"template",
"+",
"data",
"and",
"get",
"result",
"as",
"a",
"string",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/common/util/TemplateUtils.java#L121-L125 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/common/util/PersistenceUtils.java | PersistenceUtils.saveAll | public static void saveAll(final Object obj, final PersistenceStoreType storeType) {
try {
File file = new File(persistenceStorePath + File.separator + storeType);
// create necessary parent directories on file system
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());
}
} | java | public static void saveAll(final Object obj, final PersistenceStoreType storeType) {
try {
File file = new File(persistenceStorePath + File.separator + storeType);
// create necessary parent directories on file system
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());
}
} | [
"public",
"static",
"void",
"saveAll",
"(",
"final",
"Object",
"obj",
",",
"final",
"PersistenceStoreType",
"storeType",
")",
"{",
"try",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"persistenceStorePath",
"+",
"File",
".",
"separator",
"+",
"storeType",
"... | Save object to the binary file defined as filename in property "persistence.store.file".
@param obj the object to save, which should be serializable
@param storeType the store type | [
"Save",
"object",
"to",
"the",
"binary",
"file",
"defined",
"as",
"filename",
"in",
"property",
"persistence",
".",
"store",
".",
"file",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/common/util/PersistenceUtils.java#L132-L156 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/common/util/PersistenceUtils.java | PersistenceUtils.loadAll | 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) {
// no saved file to load from
log.warn("no saved file to load from: {}", e.getMessage());
return null;
} catch (IOException e) {
// failed to load from the saved file
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;
} | java | 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) {
// no saved file to load from
log.warn("no saved file to load from: {}", e.getMessage());
return null;
} catch (IOException e) {
// failed to load from the saved file
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;
} | [
"public",
"static",
"Object",
"loadAll",
"(",
"final",
"PersistenceStoreType",
"storeType",
")",
"{",
"Object",
"ret",
"=",
"null",
";",
"try",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"persistenceStorePath",
"+",
"File",
".",
"separator",
"+",
"storeTy... | Load object from the binary file defined as filename in property.
@param storeType the store type
@return the loaded object. | [
"Load",
"object",
"from",
"the",
"binary",
"file",
"defined",
"as",
"filename",
"in",
"property",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/common/util/PersistenceUtils.java#L164-L191 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockVolumeController.java | MockVolumeController.createVolume | 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;
} | java | 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;
} | [
"public",
"MockVolume",
"createVolume",
"(",
"final",
"String",
"volumeType",
",",
"final",
"String",
"size",
",",
"final",
"String",
"availabilityZone",
",",
"final",
"int",
"iops",
",",
"final",
"String",
"snapshotId",
")",
"{",
"MockVolume",
"ret",
"=",
"ne... | Create the mock Volume.
@param volumeType of Volume.
@param size : Volume size.
@param availabilityZone : Volume availability zone.
@param iops : Volume iops count
@param snapshotId : Volume's SnapshotId.
@return mock Volume. | [
"Create",
"the",
"mock",
"Volume",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockVolumeController.java#L84-L100 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockVolumeController.java | MockVolumeController.deleteVolume | public MockVolume deleteVolume(final String volumeId) {
if (volumeId != null && allMockVolumes.containsKey(volumeId)) {
return allMockVolumes.remove(volumeId);
}
return null;
} | java | public MockVolume deleteVolume(final String volumeId) {
if (volumeId != null && allMockVolumes.containsKey(volumeId)) {
return allMockVolumes.remove(volumeId);
}
return null;
} | [
"public",
"MockVolume",
"deleteVolume",
"(",
"final",
"String",
"volumeId",
")",
"{",
"if",
"(",
"volumeId",
"!=",
"null",
"&&",
"allMockVolumes",
".",
"containsKey",
"(",
"volumeId",
")",
")",
"{",
"return",
"allMockVolumes",
".",
"remove",
"(",
"volumeId",
... | Delete Mock Volume.
@param volumeId
volumeId to be deleted
@return Mock volume. | [
"Delete",
"Mock",
"Volume",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockVolumeController.java#L109-L116 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/common/listener/AppServletContextListener.java | AppServletContextListener.contextInitialized | @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.");
} | java | @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.");
} | [
"@",
"Override",
"public",
"final",
"void",
"contextInitialized",
"(",
"final",
"ServletContextEvent",
"sce",
")",
"{",
"if",
"(",
"persistenceEnabled",
")",
"{",
"// Load ec2 instances",
"AbstractMockEc2Instance",
"[",
"]",
"instanceArray",
"=",
"(",
"AbstractMockEc2... | We load the saved instances if persistence of enabled, on web application starting.
@param sce
the context event object | [
"We",
"load",
"the",
"saved",
"instances",
"if",
"persistence",
"of",
"enabled",
"on",
"web",
"application",
"starting",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/common/listener/AppServletContextListener.java#L74-L139 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/common/listener/AppServletContextListener.java | AppServletContextListener.contextDestroyed | @Override
public final void contextDestroyed(final ServletContextEvent sce) {
Collection<AbstractMockEc2Instance> instances = MockEc2Controller.getInstance()
.getAllMockEc2Instances();
for (AbstractMockEc2Instance instance : instances) {
// cancel and destroy the internal timers for all instances on
// web app stopping
instance.destroyInternalTimer();
}
if (persistenceEnabled) {
// put all instances into an array which is serializable and type-cast safe for persistence
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.");
} | java | @Override
public final void contextDestroyed(final ServletContextEvent sce) {
Collection<AbstractMockEc2Instance> instances = MockEc2Controller.getInstance()
.getAllMockEc2Instances();
for (AbstractMockEc2Instance instance : instances) {
// cancel and destroy the internal timers for all instances on
// web app stopping
instance.destroyInternalTimer();
}
if (persistenceEnabled) {
// put all instances into an array which is serializable and type-cast safe for persistence
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.");
} | [
"@",
"Override",
"public",
"final",
"void",
"contextDestroyed",
"(",
"final",
"ServletContextEvent",
"sce",
")",
"{",
"Collection",
"<",
"AbstractMockEc2Instance",
">",
"instances",
"=",
"MockEc2Controller",
".",
"getInstance",
"(",
")",
".",
"getAllMockEc2Instances",... | We save the instances if persistence of enabled, on web application shutting-down.
@param sce
the context event object | [
"We",
"save",
"the",
"instances",
"if",
"persistence",
"of",
"enabled",
"on",
"web",
"application",
"shutting",
"-",
"down",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/common/listener/AppServletContextListener.java#L147-L208 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/cloudwatch/util/JAXBUtilCW.java | JAXBUtilCW.marshall | public static String marshall(final GetMetricStatisticsResponse obj,
final String localPartQName, final String requestVersion) {
StringWriter writer = new StringWriter();
try {
/*-
* call jaxbMarshaller.marshal() synchronized (fixes the issue of
* java.lang.ArrayIndexOutOfBoundsException: -1
* at com.sun.xml.internal.bind.v2.util.CollisionCheckStack.pushNocheck(CollisionCheckStack.java:117))
* in case of jaxbMarshaller.marshal() is called concurrently
*/
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 elasticfox.compatible set to true, we replace the version number in the xml
* to match the version of elasticfox so that it could successfully accept the xml as reponse.
*/
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;
} | java | public static String marshall(final GetMetricStatisticsResponse obj,
final String localPartQName, final String requestVersion) {
StringWriter writer = new StringWriter();
try {
/*-
* call jaxbMarshaller.marshal() synchronized (fixes the issue of
* java.lang.ArrayIndexOutOfBoundsException: -1
* at com.sun.xml.internal.bind.v2.util.CollisionCheckStack.pushNocheck(CollisionCheckStack.java:117))
* in case of jaxbMarshaller.marshal() is called concurrently
*/
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 elasticfox.compatible set to true, we replace the version number in the xml
* to match the version of elasticfox so that it could successfully accept the xml as reponse.
*/
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;
} | [
"public",
"static",
"String",
"marshall",
"(",
"final",
"GetMetricStatisticsResponse",
"obj",
",",
"final",
"String",
"localPartQName",
",",
"final",
"String",
"requestVersion",
")",
"{",
"StringWriter",
"writer",
"=",
"new",
"StringWriter",
"(",
")",
";",
"try",
... | marshall object to string.
@param obj
GetMetricStatisticsResponse to be serialized and built into xml
@param localPartQName
local part of the QName
@param requestVersion
the version of CloudWatch API used by client (aws-sdk, cmd-line tools or other
third-party client tools)
@return xml representation bound to the given object | [
"marshall",
"object",
"to",
"string",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/cloudwatch/util/JAXBUtilCW.java#L86-L135 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockRouteTableController.java | MockRouteTableController.createRouteTable | 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;
} | java | 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;
} | [
"public",
"MockRouteTable",
"createRouteTable",
"(",
"final",
"String",
"cidrBlock",
",",
"final",
"String",
"vpcId",
")",
"{",
"MockRouteTable",
"ret",
"=",
"new",
"MockRouteTable",
"(",
")",
";",
"ret",
".",
"setRouteTableId",
"(",
"\"rtb-\"",
"+",
"UUID",
"... | Create the mock RouteTable.
@param cidrBlock VPC cidr block.
@param vpcId vpc Id for RouteTable.
@return mock RouteTable. | [
"Create",
"the",
"mock",
"RouteTable",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockRouteTableController.java#L83-L101 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockRouteTableController.java | MockRouteTableController.deleteRouteTable | public MockRouteTable deleteRouteTable(final String routetableId) {
if (routetableId != null && allMockRouteTables.containsKey(routetableId)) {
return allMockRouteTables.remove(routetableId);
}
return null;
} | java | public MockRouteTable deleteRouteTable(final String routetableId) {
if (routetableId != null && allMockRouteTables.containsKey(routetableId)) {
return allMockRouteTables.remove(routetableId);
}
return null;
} | [
"public",
"MockRouteTable",
"deleteRouteTable",
"(",
"final",
"String",
"routetableId",
")",
"{",
"if",
"(",
"routetableId",
"!=",
"null",
"&&",
"allMockRouteTables",
".",
"containsKey",
"(",
"routetableId",
")",
")",
"{",
"return",
"allMockRouteTables",
".",
"rem... | Delete RouteTable.
@param routetableId
RouteTableId to be deleted
@return Mock RouteTable. | [
"Delete",
"RouteTable",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockRouteTableController.java#L110-L116 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockRouteTableController.java | MockRouteTableController.createRoute | 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;
} | java | 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;
} | [
"public",
"MockRoute",
"createRoute",
"(",
"final",
"String",
"destinationCidrBlock",
",",
"final",
"String",
"internetGatewayId",
",",
"final",
"String",
"routeTableId",
")",
"{",
"MockRoute",
"ret",
"=",
"new",
"MockRoute",
"(",
")",
";",
"ret",
".",
"setDesti... | Create the mock Route.
@param destinationCidrBlock : Route destinationCidrBlock.
@param internetGatewayId : for gateway Id.
@param routeTableId : for Route.
@return mock Route. | [
"Create",
"the",
"mock",
"Route",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockRouteTableController.java#L125-L139 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockRouteTableController.java | MockRouteTableController.getMockRouteTable | public MockRouteTable getMockRouteTable(final String routetableId) {
if (routetableId != null) {
return allMockRouteTables.get(routetableId);
}
return null;
} | java | public MockRouteTable getMockRouteTable(final String routetableId) {
if (routetableId != null) {
return allMockRouteTables.get(routetableId);
}
return null;
} | [
"public",
"MockRouteTable",
"getMockRouteTable",
"(",
"final",
"String",
"routetableId",
")",
"{",
"if",
"(",
"routetableId",
"!=",
"null",
")",
"{",
"return",
"allMockRouteTables",
".",
"get",
"(",
"routetableId",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get mock RouteTable instance by RouteTable ID.
@param routetableId
ID of the mock RouteTable to get
@return the mock RouteTable object | [
"Get",
"mock",
"RouteTable",
"instance",
"by",
"RouteTable",
"ID",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockRouteTableController.java#L148-L154 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockSecurityGroupController.java | MockSecurityGroupController.createSecurityGroup | 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;
} | java | 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;
} | [
"public",
"MockSecurityGroup",
"createSecurityGroup",
"(",
"final",
"String",
"groupName",
",",
"final",
"String",
"groupDescription",
",",
"final",
"String",
"vpcId",
")",
"{",
"MockSecurityGroup",
"ret",
"=",
"new",
"MockSecurityGroup",
"(",
")",
";",
"ret",
"."... | Create the mock SecurityGroup.
@param groupName group Name.
@param groupDescription group Description.
@param vpcId vpc Id for Security Group.
@return mock Security Group. | [
"Create",
"the",
"mock",
"SecurityGroup",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockSecurityGroupController.java#L86-L107 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockSecurityGroupController.java | MockSecurityGroupController.authorizeSecurityGroupIngress | 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;
} | java | 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;
} | [
"public",
"MockSecurityGroup",
"authorizeSecurityGroupIngress",
"(",
"final",
"String",
"groupId",
",",
"final",
"String",
"ipProtocol",
",",
"final",
"Integer",
"fromPort",
",",
"final",
"Integer",
"toPort",
",",
"final",
"String",
"cidrIp",
")",
"{",
"if",
"(",
... | Authorize the mock SecurityGroup to Ingress IpProtocol.
@param groupId group Id.
@param ipProtocol ipProtocol Ingress.
@param fromPort fromPort for Security Group.
@param toPort toPort for Security Group.
@param cidrIp cidrIp for Ingress
@return mock Security Group. | [
"Authorize",
"the",
"mock",
"SecurityGroup",
"to",
"Ingress",
"IpProtocol",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockSecurityGroupController.java#L118-L138 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockSecurityGroupController.java | MockSecurityGroupController.deleteSecurityGroup | public MockSecurityGroup deleteSecurityGroup(final String securityGroupId) {
if (securityGroupId != null && allMockSecurityGroup.containsKey(securityGroupId)) {
return allMockSecurityGroup.remove(securityGroupId);
}
return null;
} | java | public MockSecurityGroup deleteSecurityGroup(final String securityGroupId) {
if (securityGroupId != null && allMockSecurityGroup.containsKey(securityGroupId)) {
return allMockSecurityGroup.remove(securityGroupId);
}
return null;
} | [
"public",
"MockSecurityGroup",
"deleteSecurityGroup",
"(",
"final",
"String",
"securityGroupId",
")",
"{",
"if",
"(",
"securityGroupId",
"!=",
"null",
"&&",
"allMockSecurityGroup",
".",
"containsKey",
"(",
"securityGroupId",
")",
")",
"{",
"return",
"allMockSecurityGr... | Delete MockSecurityGroup.
@param securityGroupId
securityGroupId to be deleted
@return MockSecurityGroup. | [
"Delete",
"MockSecurityGroup",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockSecurityGroupController.java#L178-L185 | train |
treelogic-swe/aws-mock | example/java/simple/RunInstancesExample.java | RunInstancesExample.runInstances | public static List<Instance> runInstances(final String imageId, final int runCount) {
// pass any credentials as aws-mock does not authenticate them at all
AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);
// the mock endpoint for ec2 which runs on your computer
String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
amazonEC2Client.setEndpoint(ec2Endpoint);
// instance type
String instanceType = "m1.large";
// run 10 instances
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();
} | java | public static List<Instance> runInstances(final String imageId, final int runCount) {
// pass any credentials as aws-mock does not authenticate them at all
AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);
// the mock endpoint for ec2 which runs on your computer
String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
amazonEC2Client.setEndpoint(ec2Endpoint);
// instance type
String instanceType = "m1.large";
// run 10 instances
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();
} | [
"public",
"static",
"List",
"<",
"Instance",
">",
"runInstances",
"(",
"final",
"String",
"imageId",
",",
"final",
"int",
"runCount",
")",
"{",
"// pass any credentials as aws-mock does not authenticate them at all",
"AWSCredentials",
"credentials",
"=",
"new",
"BasicAWSC... | Run some new ec2 instances.
@param imageId
AMI for running new instances from
@param runCount
count of instances to run
@return a list of started instances | [
"Run",
"some",
"new",
"ec2",
"instances",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/example/java/simple/RunInstancesExample.java#L35-L56 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockTagsController.java | MockTagsController.createTags | 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;
} | java | 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;
} | [
"public",
"MockTags",
"createTags",
"(",
"final",
"List",
"<",
"String",
">",
"resourcesSet",
",",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"tagSet",
")",
"{",
"MockTags",
"ret",
"=",
"new",
"MockTags",
"(",
")",
";",
"ret",
".",
"setResourcesS... | Create the mock Tags.
@param resourcesSet List of resourceIds.
@param tagSet Map for key, value of tags.
@return mock Tags. | [
"Create",
"the",
"mock",
"Tags",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockTagsController.java#L74-L83 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/ec2/control/MockTagsController.java | MockTagsController.deleteTags | public boolean deleteTags(final List<String> resources) {
for (MockTags mockTags : allMockTags) {
if (mockTags.getResourcesSet().containsAll(resources)) {
allMockTags.remove(mockTags);
return true;
}
}
return false;
} | java | public boolean deleteTags(final List<String> resources) {
for (MockTags mockTags : allMockTags) {
if (mockTags.getResourcesSet().containsAll(resources)) {
allMockTags.remove(mockTags);
return true;
}
}
return false;
} | [
"public",
"boolean",
"deleteTags",
"(",
"final",
"List",
"<",
"String",
">",
"resources",
")",
"{",
"for",
"(",
"MockTags",
"mockTags",
":",
"allMockTags",
")",
"{",
"if",
"(",
"mockTags",
".",
"getResourcesSet",
"(",
")",
".",
"containsAll",
"(",
"resourc... | Delete Mock tags.
@param resources
resources's tags to be deleted
@return Mock tags. | [
"Delete",
"Mock",
"tags",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/ec2/control/MockTagsController.java#L92-L102 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/common/util/PropertiesUtils.java | PropertiesUtils.getPropertiesByPrefix | 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;
} | java | 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;
} | [
"public",
"static",
"Set",
"<",
"String",
">",
"getPropertiesByPrefix",
"(",
"final",
"String",
"propertyNamePrefix",
")",
"{",
"Set",
"<",
"String",
">",
"ret",
"=",
"new",
"TreeSet",
"<",
"String",
">",
"(",
")",
";",
"Set",
"<",
"Object",
">",
"keys",... | Get a set of properties those share the same given name prefix.
@param propertyNamePrefix
prefix of name
@return the set of values whose property names share the same prefix | [
"Get",
"a",
"set",
"of",
"properties",
"those",
"share",
"the",
"same",
"given",
"name",
"prefix",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/common/util/PropertiesUtils.java#L105-L116 | train |
treelogic-swe/aws-mock | src/main/java/com/tlswe/awsmock/common/util/PropertiesUtils.java | PropertiesUtils.getIntFromProperty | 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;
}
} | java | 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;
}
} | [
"public",
"static",
"int",
"getIntFromProperty",
"(",
"final",
"String",
"propertyName",
")",
"{",
"try",
"{",
"return",
"Integer",
".",
"parseInt",
"(",
"properties",
".",
"getProperty",
"(",
"propertyName",
")",
")",
";",
"}",
"catch",
"(",
"NumberFormatExce... | Get int type of property value by name.
@param propertyName
name of the property to get
@return int type of value | [
"Get",
"int",
"type",
"of",
"property",
"value",
"by",
"name",
"."
] | 1d1058c0ebbd0615efa28695481e36ae3ffc58a0 | https://github.com/treelogic-swe/aws-mock/blob/1d1058c0ebbd0615efa28695481e36ae3ffc58a0/src/main/java/com/tlswe/awsmock/common/util/PropertiesUtils.java#L125-L133 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/SundialJobScheduler.java | SundialJobScheduler.startScheduler | 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);
}
} | java | 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);
}
} | [
"public",
"static",
"void",
"startScheduler",
"(",
"int",
"threadPoolSize",
",",
"String",
"annotatedJobsPackageName",
")",
"throws",
"SundialSchedulerException",
"{",
"try",
"{",
"createScheduler",
"(",
"threadPoolSize",
",",
"annotatedJobsPackageName",
")",
";",
"getS... | Starts the Sundial Scheduler
@param threadPoolSize
@param annotatedJobsPackageName A comma(,) or colon(:) can be used to specify multiple packages
to scan for Jobs. | [
"Starts",
"the",
"Sundial",
"Scheduler"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/SundialJobScheduler.java#L84-L93 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/SundialJobScheduler.java | SundialJobScheduler.startJob | public static void startJob(String jobName) throws SundialSchedulerException {
try {
getScheduler().triggerJob(jobName, null);
} catch (SchedulerException e) {
throw new SundialSchedulerException("ERROR STARTING JOB!!!", e);
}
} | java | public static void startJob(String jobName) throws SundialSchedulerException {
try {
getScheduler().triggerJob(jobName, null);
} catch (SchedulerException e) {
throw new SundialSchedulerException("ERROR STARTING JOB!!!", e);
}
} | [
"public",
"static",
"void",
"startJob",
"(",
"String",
"jobName",
")",
"throws",
"SundialSchedulerException",
"{",
"try",
"{",
"getScheduler",
"(",
")",
".",
"triggerJob",
"(",
"jobName",
",",
"null",
")",
";",
"}",
"catch",
"(",
"SchedulerException",
"e",
"... | Starts a Job matching the given Job Name
@param jobName | [
"Starts",
"a",
"Job",
"matching",
"the",
"given",
"Job",
"Name"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/SundialJobScheduler.java#L271-L278 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/SundialJobScheduler.java | SundialJobScheduler.removeJob | public static void removeJob(String jobName) throws SundialSchedulerException {
try {
getScheduler().deleteJob(jobName);
} catch (SchedulerException e) {
throw new SundialSchedulerException("ERROR REMOVING JOB!!!", e);
}
} | java | public static void removeJob(String jobName) throws SundialSchedulerException {
try {
getScheduler().deleteJob(jobName);
} catch (SchedulerException e) {
throw new SundialSchedulerException("ERROR REMOVING JOB!!!", e);
}
} | [
"public",
"static",
"void",
"removeJob",
"(",
"String",
"jobName",
")",
"throws",
"SundialSchedulerException",
"{",
"try",
"{",
"getScheduler",
"(",
")",
".",
"deleteJob",
"(",
"jobName",
")",
";",
"}",
"catch",
"(",
"SchedulerException",
"e",
")",
"{",
"thr... | Removes a Job matching the given Job Name
@param jobName | [
"Removes",
"a",
"Job",
"matching",
"the",
"given",
"Job",
"Name"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/SundialJobScheduler.java#L285-L292 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/SundialJobScheduler.java | SundialJobScheduler.startJob | public static void startJob(String jobName, Map<String, Object> params)
throws SundialSchedulerException {
try {
JobDataMap jobDataMap = new JobDataMap();
for (String key : params.keySet()) {
// logger.debug("key= " + key);
// logger.debug("value= " + pParams.get(key));
jobDataMap.put(key, params.get(key));
}
getScheduler().triggerJob(jobName, jobDataMap);
} catch (SchedulerException e) {
throw new SundialSchedulerException("ERROR STARTING JOB!!!", e);
}
} | java | public static void startJob(String jobName, Map<String, Object> params)
throws SundialSchedulerException {
try {
JobDataMap jobDataMap = new JobDataMap();
for (String key : params.keySet()) {
// logger.debug("key= " + key);
// logger.debug("value= " + pParams.get(key));
jobDataMap.put(key, params.get(key));
}
getScheduler().triggerJob(jobName, jobDataMap);
} catch (SchedulerException e) {
throw new SundialSchedulerException("ERROR STARTING JOB!!!", e);
}
} | [
"public",
"static",
"void",
"startJob",
"(",
"String",
"jobName",
",",
"Map",
"<",
"String",
",",
"Object",
">",
"params",
")",
"throws",
"SundialSchedulerException",
"{",
"try",
"{",
"JobDataMap",
"jobDataMap",
"=",
"new",
"JobDataMap",
"(",
")",
";",
"for"... | Starts a Job matching the the given Job Name found in jobs.xml or jobs manually added.
@param jobName | [
"Starts",
"a",
"Job",
"matching",
"the",
"the",
"given",
"Job",
"Name",
"found",
"in",
"jobs",
".",
"xml",
"or",
"jobs",
"manually",
"added",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/SundialJobScheduler.java#L299-L314 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/SundialJobScheduler.java | SundialJobScheduler.removeTrigger | public static void removeTrigger(String triggerName) throws SundialSchedulerException {
try {
getScheduler().unscheduleJob(triggerName);
} catch (SchedulerException e) {
throw new SundialSchedulerException("ERROR REMOVING TRIGGER!!!", e);
}
} | java | public static void removeTrigger(String triggerName) throws SundialSchedulerException {
try {
getScheduler().unscheduleJob(triggerName);
} catch (SchedulerException e) {
throw new SundialSchedulerException("ERROR REMOVING TRIGGER!!!", e);
}
} | [
"public",
"static",
"void",
"removeTrigger",
"(",
"String",
"triggerName",
")",
"throws",
"SundialSchedulerException",
"{",
"try",
"{",
"getScheduler",
"(",
")",
".",
"unscheduleJob",
"(",
"triggerName",
")",
";",
"}",
"catch",
"(",
"SchedulerException",
"e",
")... | Removes a Trigger matching the the given Trigger Name
@param triggerName | [
"Removes",
"a",
"Trigger",
"matching",
"the",
"the",
"given",
"Trigger",
"Name"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/SundialJobScheduler.java#L490-L497 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/SundialJobScheduler.java | SundialJobScheduler.getAllJobNames | 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;
} | java | 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;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"getAllJobNames",
"(",
")",
"throws",
"SundialSchedulerException",
"{",
"List",
"<",
"String",
">",
"allJobNames",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"try",
"{",
"Set",
"<",
"String",... | Generates an alphabetically sorted List of all Job names in the DEFAULT job group
@return | [
"Generates",
"an",
"alphabetically",
"sorted",
"List",
"of",
"all",
"Job",
"names",
"in",
"the",
"DEFAULT",
"job",
"group"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/SundialJobScheduler.java#L504-L518 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/SundialJobScheduler.java | SundialJobScheduler.getAllJobsAndTriggers | 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;
} | java | 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;
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"List",
"<",
"Trigger",
">",
">",
"getAllJobsAndTriggers",
"(",
")",
"throws",
"SundialSchedulerException",
"{",
"Map",
"<",
"String",
",",
"List",
"<",
"Trigger",
">",
">",
"allJobsMap",
"=",
"new",
"TreeMap",
... | Generates a Map of all Job names with corresponding Triggers
@return | [
"Generates",
"a",
"Map",
"of",
"all",
"Job",
"names",
"with",
"corresponding",
"Triggers"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/SundialJobScheduler.java#L525-L540 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/SundialJobScheduler.java | SundialJobScheduler.shutdown | 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);
}
} | java | 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);
}
} | [
"public",
"static",
"void",
"shutdown",
"(",
")",
"throws",
"SundialSchedulerException",
"{",
"logger",
".",
"debug",
"(",
"\"shutdown() called.\"",
")",
";",
"try",
"{",
"getScheduler",
"(",
")",
".",
"shutdown",
"(",
")",
";",
"scheduler",
"=",
"null",
";"... | Halts the Scheduler's firing of Triggers, and cleans up all resources associated with the
Scheduler. | [
"Halts",
"the",
"Scheduler",
"s",
"firing",
"of",
"Triggers",
"and",
"cleans",
"up",
"all",
"resources",
"associated",
"with",
"the",
"Scheduler",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/SundialJobScheduler.java#L565-L575 | train |
knowm/Sundial | src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessor.java | XMLSchedulingDataProcessor.initDocumentParser | 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();
} | java | 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();
} | [
"private",
"void",
"initDocumentParser",
"(",
")",
"throws",
"ParserConfigurationException",
"{",
"DocumentBuilderFactory",
"docBuilderFactory",
"=",
"DocumentBuilderFactory",
".",
"newInstance",
"(",
")",
";",
"docBuilderFactory",
".",
"setNamespaceAware",
"(",
"false",
... | Initializes the XML parser.
@throws ParserConfigurationException | [
"Initializes",
"the",
"XML",
"parser",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessor.java#L127-L146 | train |
knowm/Sundial | src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessor.java | XMLSchedulingDataProcessor.processFile | public void processFile(String fileName, boolean failOnFileNotFound) throws Exception {
boolean fileFound = false;
InputStream f = null;
try {
String furl = null;
File file = new File(fileName); // files in filesystem
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) {
// Swallow the exception
}
}
} else {
try {
f = new java.io.FileInputStream(file);
} catch (FileNotFoundException e) {
// ignore
}
}
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);
}
} | java | public void processFile(String fileName, boolean failOnFileNotFound) throws Exception {
boolean fileFound = false;
InputStream f = null;
try {
String furl = null;
File file = new File(fileName); // files in filesystem
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) {
// Swallow the exception
}
}
} else {
try {
f = new java.io.FileInputStream(file);
} catch (FileNotFoundException e) {
// ignore
}
}
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);
}
} | [
"public",
"void",
"processFile",
"(",
"String",
"fileName",
",",
"boolean",
"failOnFileNotFound",
")",
"throws",
"Exception",
"{",
"boolean",
"fileFound",
"=",
"false",
";",
"InputStream",
"f",
"=",
"null",
";",
"try",
"{",
"String",
"furl",
"=",
"null",
";"... | Process the xml file in the given location, and schedule all of the jobs defined within it.
@param fileName meta data file name. | [
"Process",
"the",
"xml",
"file",
"in",
"the",
"given",
"location",
"and",
"schedule",
"all",
"of",
"the",
"jobs",
"defined",
"within",
"it",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessor.java#L171-L229 | train |
knowm/Sundial | src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessor.java | XMLSchedulingDataProcessor.scheduleJobs | 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 trigger with name already exists
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.");
}
}
}
} | java | 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 trigger with name already exists
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.");
}
}
}
} | [
"public",
"void",
"scheduleJobs",
"(",
"Scheduler",
"sched",
")",
"throws",
"SchedulerException",
"{",
"List",
"<",
"JobDetail",
">",
"jobs",
"=",
"new",
"LinkedList",
"<",
"JobDetail",
">",
"(",
"getLoadedJobs",
"(",
")",
")",
";",
"List",
"<",
"OperableTri... | Schedules the given sets of jobs and triggers.
@param sched job scheduler.
@exception SchedulerException if the Job or Trigger cannot be added to the Scheduler, or there
is an internal Scheduler error. | [
"Schedules",
"the",
"given",
"sets",
"of",
"jobs",
"and",
"triggers",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessor.java#L537-L583 | train |
knowm/Sundial | src/main/java/org/quartz/QuartzScheduler.java | QuartzScheduler.getSchedulerThreadGroup | public ThreadGroup getSchedulerThreadGroup() {
if (threadGroup == null) {
threadGroup = new ThreadGroup("QuartzScheduler");
if (quartzSchedulerResources.getMakeSchedulerThreadDaemon()) {
threadGroup.setDaemon(true);
}
}
return threadGroup;
} | java | public ThreadGroup getSchedulerThreadGroup() {
if (threadGroup == null) {
threadGroup = new ThreadGroup("QuartzScheduler");
if (quartzSchedulerResources.getMakeSchedulerThreadDaemon()) {
threadGroup.setDaemon(true);
}
}
return threadGroup;
} | [
"public",
"ThreadGroup",
"getSchedulerThreadGroup",
"(",
")",
"{",
"if",
"(",
"threadGroup",
"==",
"null",
")",
"{",
"threadGroup",
"=",
"new",
"ThreadGroup",
"(",
"\"QuartzScheduler\"",
")",
";",
"if",
"(",
"quartzSchedulerResources",
".",
"getMakeSchedulerThreadDa... | Returns the name of the thread group for Quartz's main threads. | [
"Returns",
"the",
"name",
"of",
"the",
"thread",
"group",
"for",
"Quartz",
"s",
"main",
"threads",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/quartz/QuartzScheduler.java#L145-L155 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/JobContainer.java | JobContainer.initContextContainer | protected void initContextContainer(JobExecutionContext jobExecutionContext) {
JobContext jobContext = new JobContext();
jobContext.addQuartzContext(jobExecutionContext);
contextContainer.set(jobContext);
} | java | protected void initContextContainer(JobExecutionContext jobExecutionContext) {
JobContext jobContext = new JobContext();
jobContext.addQuartzContext(jobExecutionContext);
contextContainer.set(jobContext);
} | [
"protected",
"void",
"initContextContainer",
"(",
"JobExecutionContext",
"jobExecutionContext",
")",
"{",
"JobContext",
"jobContext",
"=",
"new",
"JobContext",
"(",
")",
";",
"jobContext",
".",
"addQuartzContext",
"(",
"jobExecutionContext",
")",
";",
"contextContainer"... | Initialize the ThreadLocal with a JobExecutionContext object
@param jobExecutionContext | [
"Initialize",
"the",
"ThreadLocal",
"with",
"a",
"JobExecutionContext",
"object"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/JobContainer.java#L25-L30 | train |
knowm/Sundial | src/main/java/org/quartz/core/SimpleThreadPool.java | SimpleThreadPool.shutdown | @Override
public void shutdown() {
synchronized (nextRunnableLock) {
isShutdown = true;
if (workers == null) {
return;
}
// signal each worker thread to shut down
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);
}
// Active worker threads will shut down after finishing their
// current job.
nextRunnableLock.notifyAll();
}
} | java | @Override
public void shutdown() {
synchronized (nextRunnableLock) {
isShutdown = true;
if (workers == null) {
return;
}
// signal each worker thread to shut down
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);
}
// Active worker threads will shut down after finishing their
// current job.
nextRunnableLock.notifyAll();
}
} | [
"@",
"Override",
"public",
"void",
"shutdown",
"(",
")",
"{",
"synchronized",
"(",
"nextRunnableLock",
")",
"{",
"isShutdown",
"=",
"true",
";",
"if",
"(",
"workers",
"==",
"null",
")",
"{",
"return",
";",
"}",
"// signal each worker thread to shut down",
"Ite... | Terminate any worker threads in this thread group.
<p>Jobs currently in progress will complete. | [
"Terminate",
"any",
"worker",
"threads",
"in",
"this",
"thread",
"group",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/quartz/core/SimpleThreadPool.java#L231-L258 | train |
knowm/Sundial | src/main/java/org/quartz/core/RAMJobStore.java | RAMJobStore.getTriggersForJob | @Override
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;
} | java | @Override
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;
} | [
"@",
"Override",
"public",
"List",
"<",
"Trigger",
">",
"getTriggersForJob",
"(",
"String",
"jobKey",
")",
"{",
"ArrayList",
"<",
"Trigger",
">",
"trigList",
"=",
"new",
"ArrayList",
"<",
"Trigger",
">",
"(",
")",
";",
"synchronized",
"(",
"lock",
")",
"... | Get all of the Triggers that are associated to the given Job.
<p>If there are no matches, a zero-length array should be returned. | [
"Get",
"all",
"of",
"the",
"Triggers",
"that",
"are",
"associated",
"to",
"the",
"given",
"Job",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/quartz/core/RAMJobStore.java#L364-L379 | train |
knowm/Sundial | src/main/java/org/quartz/plugins/xml/ValidationException.java | ValidationException.getMessage | @Override
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();
} | java | @Override
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();
} | [
"@",
"Override",
"public",
"String",
"getMessage",
"(",
")",
"{",
"if",
"(",
"getValidationExceptions",
"(",
")",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"return",
"super",
".",
"getMessage",
"(",
")",
";",
"}",
"StringBuffer",
"sb",
"=",
"new",
... | Returns the detail message string.
@return the detail message string. | [
"Returns",
"the",
"detail",
"message",
"string",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/quartz/plugins/xml/ValidationException.java#L76-L99 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/JobContext.java | JobContext.addQuartzContext | public void addQuartzContext(JobExecutionContext jobExecutionContext) {
for (Object mapKey : jobExecutionContext.getMergedJobDataMap().keySet()) {
// logger.debug("added key: " + (String) mapKey);
// logger.debug("added value: " + (String)
// jobExecutionContext.getMergedJobDataMap().get(mapKey));
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());
}
} | java | public void addQuartzContext(JobExecutionContext jobExecutionContext) {
for (Object mapKey : jobExecutionContext.getMergedJobDataMap().keySet()) {
// logger.debug("added key: " + (String) mapKey);
// logger.debug("added value: " + (String)
// jobExecutionContext.getMergedJobDataMap().get(mapKey));
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());
}
} | [
"public",
"void",
"addQuartzContext",
"(",
"JobExecutionContext",
"jobExecutionContext",
")",
"{",
"for",
"(",
"Object",
"mapKey",
":",
"jobExecutionContext",
".",
"getMergedJobDataMap",
"(",
")",
".",
"keySet",
"(",
")",
")",
"{",
"// logger.debug(\"added key: \" + (... | Add all the mappings from the JobExecutionContext to the JobContext
@param jobExecutionContext | [
"Add",
"all",
"the",
"mappings",
"from",
"the",
"JobExecutionContext",
"to",
"the",
"JobContext"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/JobContext.java#L33-L48 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/JobContext.java | JobContext.get | @SuppressWarnings("unchecked")
public <T> T get(String key) {
T value = (T) map.get(key);
return value;
} | java | @SuppressWarnings("unchecked")
public <T> T get(String key) {
T value = (T) map.get(key);
return value;
} | [
"@",
"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
@param key
@return | [
"Get",
"a",
"value",
"from",
"a",
"key",
"out",
"of",
"the",
"JobContext"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/JobContext.java#L67-L72 | train |
knowm/Sundial | src/main/java/org/knowm/sundial/JobContext.java | JobContext.getRequiredValue | @SuppressWarnings("unchecked")
public <T> T getRequiredValue(String key) {
T value = (T) map.get(key);
if (value == null) {
throw new RequiredParameterException();
}
return value;
} | java | @SuppressWarnings("unchecked")
public <T> T getRequiredValue(String key) {
T value = (T) map.get(key);
if (value == null) {
throw new RequiredParameterException();
}
return value;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"<",
"T",
">",
"T",
"getRequiredValue",
"(",
"String",
"key",
")",
"{",
"T",
"value",
"=",
"(",
"T",
")",
"map",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"value",
"==",
"null",
")",
... | Get a required value from a key out of the Job Context
@param key
@return | [
"Get",
"a",
"required",
"value",
"from",
"a",
"key",
"out",
"of",
"the",
"Job",
"Context"
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/knowm/sundial/JobContext.java#L80-L88 | train |
knowm/Sundial | src/main/java/org/quartz/builders/CronTriggerBuilder.java | CronTriggerBuilder.cronTriggerBuilder | public static CronTriggerBuilder cronTriggerBuilder(String cronExpression) throws ParseException {
CronExpression.validateExpression(cronExpression);
return new CronTriggerBuilder(cronExpression);
} | java | public static CronTriggerBuilder cronTriggerBuilder(String cronExpression) throws ParseException {
CronExpression.validateExpression(cronExpression);
return new CronTriggerBuilder(cronExpression);
} | [
"public",
"static",
"CronTriggerBuilder",
"cronTriggerBuilder",
"(",
"String",
"cronExpression",
")",
"throws",
"ParseException",
"{",
"CronExpression",
".",
"validateExpression",
"(",
"cronExpression",
")",
";",
"return",
"new",
"CronTriggerBuilder",
"(",
"cronExpression... | Create a CronScheduleBuilder with the given cron-expression.
@param cronExpression the cron expression to base the schedule on.
@return the new CronScheduleBuilder
@throws ParseException
@see CronExpression | [
"Create",
"a",
"CronScheduleBuilder",
"with",
"the",
"given",
"cron",
"-",
"expression",
"."
] | 0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62 | https://github.com/knowm/Sundial/blob/0d61549fdfb8d6f884a1f2eed7e32ad39e2f4c62/src/main/java/org/quartz/builders/CronTriggerBuilder.java#L59-L63 | train |
chargebee/chargebee-java | src/main/java/com/chargebee/gdata/UnicodeEscaper.java | UnicodeEscaper.escape | public String escape(String string) {
int end = string.length();
int index = nextEscapeIndex(string, 0, end);
return index == end ? string : escapeSlow(string, index);
} | java | public String escape(String string) {
int end = string.length();
int index = nextEscapeIndex(string, 0, end);
return index == end ? string : escapeSlow(string, index);
} | [
"public",
"String",
"escape",
"(",
"String",
"string",
")",
"{",
"int",
"end",
"=",
"string",
".",
"length",
"(",
")",
";",
"int",
"index",
"=",
"nextEscapeIndex",
"(",
"string",
",",
"0",
",",
"end",
")",
";",
"return",
"index",
"==",
"end",
"?",
... | Returns the escaped form of a given literal string.
<p>If you are escaping input in arbitrary successive chunks, then it is not
generally safe to use this method. If an input string ends with an
unmatched high surrogate character, then this method will throw
{@link IllegalArgumentException}. You should either ensure your input is
valid <a href="http://en.wikipedia.org/wiki/UTF-16">UTF-16</a> before
calling this method or use an escaped {@link Appendable} (as returned by
{@link #escape(Appendable)}) which can cope with arbitrarily split input.
<p><b>Note:</b> When implementing an escaper it is a good idea to override
this method for efficiency by inlining the implementation of
{@link #nextEscapeIndex(CharSequence, int, int)} directly. Doing this for
{@link PercentEscaper} more than doubled the performance for unescaped
strings (as measured by {@link CharEscapersBenchmark}).
@param string the literal string to be escaped
@return the escaped form of {@code string}
@throws NullPointerException if {@code string} is null
@throws IllegalArgumentException if invalid surrogate characters are
encountered | [
"Returns",
"the",
"escaped",
"form",
"of",
"a",
"given",
"literal",
"string",
"."
] | 0772f9af799492bd94b789a39a8ae56f91d47c05 | https://github.com/chargebee/chargebee-java/blob/0772f9af799492bd94b789a39a8ae56f91d47c05/src/main/java/com/chargebee/gdata/UnicodeEscaper.java#L140-L144 | train |
jmock-developers/jmock-library | jmock/src/main/java/org/jmock/lib/concurrent/DeterministicScheduler.java | DeterministicScheduler.tick | public void tick(long duration, TimeUnit timeUnit) {
long remaining = toTicks(duration, timeUnit);
do {
remaining = deltaQueue.tick(remaining);
runUntilIdle();
} while (deltaQueue.isNotEmpty() && remaining > 0);
} | java | public void tick(long duration, TimeUnit timeUnit) {
long remaining = toTicks(duration, timeUnit);
do {
remaining = deltaQueue.tick(remaining);
runUntilIdle();
} while (deltaQueue.isNotEmpty() && remaining > 0);
} | [
"public",
"void",
"tick",
"(",
"long",
"duration",
",",
"TimeUnit",
"timeUnit",
")",
"{",
"long",
"remaining",
"=",
"toTicks",
"(",
"duration",
",",
"timeUnit",
")",
";",
"do",
"{",
"remaining",
"=",
"deltaQueue",
".",
"tick",
"(",
"remaining",
")",
";",... | 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.
@param duration
@param timeUnit | [
"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",
... | a6a9d32f3ed0df4a959d3c7421d5f336279b9962 | https://github.com/jmock-developers/jmock-library/blob/a6a9d32f3ed0df4a959d3c7421d5f336279b9962/jmock/src/main/java/org/jmock/lib/concurrent/DeterministicScheduler.java#L40-L48 | train |
jmock-developers/jmock-library | jmock/src/main/java/org/jmock/Mockery.java | Mockery.assertIsSatisfied | public void assertIsSatisfied() {
if (firstError != null) {
throw firstError;
}
else if (!dispatcher.isSatisfied()) {
throw expectationErrorTranslator.translate(
ExpectationError.notAllSatisfied(this));
}
} | java | public void assertIsSatisfied() {
if (firstError != null) {
throw firstError;
}
else if (!dispatcher.isSatisfied()) {
throw expectationErrorTranslator.translate(
ExpectationError.notAllSatisfied(this));
}
} | [
"public",
"void",
"assertIsSatisfied",
"(",
")",
"{",
"if",
"(",
"firstError",
"!=",
"null",
")",
"{",
"throw",
"firstError",
";",
"}",
"else",
"if",
"(",
"!",
"dispatcher",
".",
"isSatisfied",
"(",
")",
")",
"{",
"throw",
"expectationErrorTranslator",
"."... | Fails the test if there are any expectations that have not been met. | [
"Fails",
"the",
"test",
"if",
"there",
"are",
"any",
"expectations",
"that",
"have",
"not",
"been",
"met",
"."
] | a6a9d32f3ed0df4a959d3c7421d5f336279b9962 | https://github.com/jmock-developers/jmock-library/blob/a6a9d32f3ed0df4a959d3c7421d5f336279b9962/jmock/src/main/java/org/jmock/Mockery.java#L225-L233 | train |
jmock-developers/jmock-library | jmock/src/main/java/org/jmock/lib/script/ScriptedAction.java | ScriptedAction.where | public ScriptedAction where(String name, Object value) {
try {
interpreter.set(name, value);
}
catch (EvalError e) {
throw new IllegalArgumentException("invalid name binding", e);
}
return this;
} | java | public ScriptedAction where(String name, Object value) {
try {
interpreter.set(name, value);
}
catch (EvalError e) {
throw new IllegalArgumentException("invalid name binding", e);
}
return this;
} | [
"public",
"ScriptedAction",
"where",
"(",
"String",
"name",
",",
"Object",
"value",
")",
"{",
"try",
"{",
"interpreter",
".",
"set",
"(",
"name",
",",
"value",
")",
";",
"}",
"catch",
"(",
"EvalError",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentExcep... | Defines a variable that can be referred to by the script.
@param name
the name of the variable
@param value
the value of the variable
@return
the action, so that more variables can be defined if needed | [
"Defines",
"a",
"variable",
"that",
"can",
"be",
"referred",
"to",
"by",
"the",
"script",
"."
] | a6a9d32f3ed0df4a959d3c7421d5f336279b9962 | https://github.com/jmock-developers/jmock-library/blob/a6a9d32f3ed0df4a959d3c7421d5f336279b9962/jmock/src/main/java/org/jmock/lib/script/ScriptedAction.java#L97-L105 | train |
jmock-developers/jmock-library | jmock/src/main/java/org/jmock/internal/InvocationExpectationBuilder.java | InvocationExpectationBuilder.asMockedType | @SuppressWarnings("unchecked")
private <T> T asMockedType(@SuppressWarnings("unused") T mockObject,
Object capturingImposter)
{
return (T) capturingImposter;
} | java | @SuppressWarnings("unchecked")
private <T> T asMockedType(@SuppressWarnings("unused") T mockObject,
Object capturingImposter)
{
return (T) capturingImposter;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"private",
"<",
"T",
">",
"T",
"asMockedType",
"(",
"@",
"SuppressWarnings",
"(",
"\"unused\"",
")",
"T",
"mockObject",
",",
"Object",
"capturingImposter",
")",
"{",
"return",
"(",
"T",
")",
"capturingImposte... | Damn you Java generics! Damn you to HELL! | [
"Damn",
"you",
"Java",
"generics!",
"Damn",
"you",
"to",
"HELL!"
] | a6a9d32f3ed0df4a959d3c7421d5f336279b9962 | https://github.com/jmock-developers/jmock-library/blob/a6a9d32f3ed0df4a959d3c7421d5f336279b9962/jmock/src/main/java/org/jmock/internal/InvocationExpectationBuilder.java#L77-L82 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.sendUpdates | protected synchronized void sendUpdates() {
log.debug("sendUpdates");
// get the current version
final int currentVersion = getVersion();
log.debug("Current version: {}", currentVersion);
// get the name
final String name = getName();
//get owner events
Set<ISharedObjectEvent> ownerEvents = ownerMessage.getEvents();
if (!ownerEvents.isEmpty()) {
// get all current owner events - single ordered set going to the event owner
final TreeSet<ISharedObjectEvent> events = new TreeSet<>(ownerEvents);
ownerEvents.removeAll(events);
// send update to "owner" of this update request
if (source != null) {
final RTMPConnection con = (RTMPConnection) source;
// create a worker
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");
}
// tell all the listeners
if (!syncEvents.isEmpty()) {
// get all current sync events
final TreeSet<ISharedObjectEvent> events = new TreeSet<>(syncEvents);
syncEvents.removeAll(events);
// get the listeners
Set<IEventListener> listeners = getListeners();
if (log.isDebugEnabled()) {
log.debug("Listeners: {}", listeners);
}
// updates all registered clients of this shared object
listeners.stream().filter(listener -> listener != source).forEach(listener -> {
final RTMPConnection con = (RTMPConnection) listener;
if (con.isConnected()) {
// create a worker
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 the connection is 'disconnected' remove it
if (con.isDisconnected()) {
unregister(con);
}
}
});
} else if (log.isTraceEnabled()) {
log.trace("No sync events to send");
}
} | java | protected synchronized void sendUpdates() {
log.debug("sendUpdates");
// get the current version
final int currentVersion = getVersion();
log.debug("Current version: {}", currentVersion);
// get the name
final String name = getName();
//get owner events
Set<ISharedObjectEvent> ownerEvents = ownerMessage.getEvents();
if (!ownerEvents.isEmpty()) {
// get all current owner events - single ordered set going to the event owner
final TreeSet<ISharedObjectEvent> events = new TreeSet<>(ownerEvents);
ownerEvents.removeAll(events);
// send update to "owner" of this update request
if (source != null) {
final RTMPConnection con = (RTMPConnection) source;
// create a worker
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");
}
// tell all the listeners
if (!syncEvents.isEmpty()) {
// get all current sync events
final TreeSet<ISharedObjectEvent> events = new TreeSet<>(syncEvents);
syncEvents.removeAll(events);
// get the listeners
Set<IEventListener> listeners = getListeners();
if (log.isDebugEnabled()) {
log.debug("Listeners: {}", listeners);
}
// updates all registered clients of this shared object
listeners.stream().filter(listener -> listener != source).forEach(listener -> {
final RTMPConnection con = (RTMPConnection) listener;
if (con.isConnected()) {
// create a worker
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 the connection is 'disconnected' remove it
if (con.isDisconnected()) {
unregister(con);
}
}
});
} else if (log.isTraceEnabled()) {
log.trace("No sync events to send");
}
} | [
"protected",
"synchronized",
"void",
"sendUpdates",
"(",
")",
"{",
"log",
".",
"debug",
"(",
"\"sendUpdates\"",
")",
";",
"// get the current version\r",
"final",
"int",
"currentVersion",
"=",
"getVersion",
"(",
")",
";",
"log",
".",
"debug",
"(",
"\"Current ver... | Send update notification over data channel of RTMP connection | [
"Send",
"update",
"notification",
"over",
"data",
"channel",
"of",
"RTMP",
"connection"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L301-L358 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.notifyModified | protected void notifyModified() {
log.debug("notifyModified - modified: {} update counter: {}", modified.get(), updateCounter.get());
if (updateCounter.get() == 0) {
if (modified.get()) {
// client sent at least one update -> increase version of SO
updateVersion();
lastModified = System.currentTimeMillis();
if (storage == null || !storage.save(this)) {
log.warn("Could not store shared object");
}
}
sendUpdates();
modified.compareAndSet(true, false);
}
} | java | protected void notifyModified() {
log.debug("notifyModified - modified: {} update counter: {}", modified.get(), updateCounter.get());
if (updateCounter.get() == 0) {
if (modified.get()) {
// client sent at least one update -> increase version of SO
updateVersion();
lastModified = System.currentTimeMillis();
if (storage == null || !storage.save(this)) {
log.warn("Could not store shared object");
}
}
sendUpdates();
modified.compareAndSet(true, false);
}
} | [
"protected",
"void",
"notifyModified",
"(",
")",
"{",
"log",
".",
"debug",
"(",
"\"notifyModified - modified: {} update counter: {}\"",
",",
"modified",
".",
"get",
"(",
")",
",",
"updateCounter",
".",
"get",
"(",
")",
")",
";",
"if",
"(",
"updateCounter",
"."... | Send notification about modification of SO | [
"Send",
"notification",
"about",
"modification",
"of",
"SO"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L363-L377 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.returnAttributeValue | protected void returnAttributeValue(String name) {
ownerMessage.addEvent(Type.CLIENT_UPDATE_DATA, name, getAttribute(name));
} | java | protected void returnAttributeValue(String name) {
ownerMessage.addEvent(Type.CLIENT_UPDATE_DATA, name, getAttribute(name));
} | [
"protected",
"void",
"returnAttributeValue",
"(",
"String",
"name",
")",
"{",
"ownerMessage",
".",
"addEvent",
"(",
"Type",
".",
"CLIENT_UPDATE_DATA",
",",
"name",
",",
"getAttribute",
"(",
"name",
")",
")",
";",
"}"
] | Return an attribute value to the owner.
@param name
name | [
"Return",
"an",
"attribute",
"value",
"to",
"the",
"owner",
"."
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L395-L397 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.getAttribute | @Override
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) {
// no previous value
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;
} | java | @Override
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) {
// no previous value
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;
} | [
"@",
"Override",
"public",
"Object",
"getAttribute",
"(",
"String",
"name",
",",
"Object",
"value",
")",
"{",
"log",
".",
"debug",
"(",
"\"getAttribute - name: {} value: {}\"",
",",
"name",
",",
"value",
")",
";",
"Object",
"result",
"=",
"null",
";",
"if",
... | Return attribute by name and set if it doesn't exist yet.
@param name
Attribute name
@param value
Value to set if attribute doesn't exist
@return Attribute value | [
"Return",
"attribute",
"by",
"name",
"and",
"set",
"if",
"it",
"doesn",
"t",
"exist",
"yet",
"."
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L408-L426 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.removeAttribute | @Override
public boolean removeAttribute(String name) {
boolean result = true;
// Send confirmation to client
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;
} | java | @Override
public boolean removeAttribute(String name) {
boolean result = true;
// Send confirmation to client
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;
} | [
"@",
"Override",
"public",
"boolean",
"removeAttribute",
"(",
"String",
"name",
")",
"{",
"boolean",
"result",
"=",
"true",
";",
"// Send confirmation to client\r",
"final",
"SharedObjectEvent",
"event",
"=",
"new",
"SharedObjectEvent",
"(",
"Type",
".",
"CLIENT_DEL... | Removes attribute with given name
@param name
Attribute
@return true if there's such an attribute and it was removed, false otherwise | [
"Removes",
"attribute",
"with",
"given",
"name"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L490-L506 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.sendMessage | 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);
}
}
} | java | 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);
}
}
} | [
"protected",
"void",
"sendMessage",
"(",
"String",
"handler",
",",
"List",
"<",
"?",
">",
"arguments",
")",
"{",
"final",
"SharedObjectEvent",
"event",
"=",
"new",
"SharedObjectEvent",
"(",
"Type",
".",
"CLIENT_SEND_MESSAGE",
",",
"handler",
",",
"arguments",
... | Broadcast event to event handler
@param handler
Event handler
@param arguments
Arguments | [
"Broadcast",
"event",
"to",
"event",
"handler"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L516-L525 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.register | protected boolean register(IEventListener listener) {
log.debug("register - listener: {}", listener);
boolean registered = listeners.add(listener);
if (registered) {
listenerStats.increment();
// prepare response for new client
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()));
}
// we call notifyModified here to send response if we're not in a beginUpdate block
notifyModified();
}
return registered;
} | java | protected boolean register(IEventListener listener) {
log.debug("register - listener: {}", listener);
boolean registered = listeners.add(listener);
if (registered) {
listenerStats.increment();
// prepare response for new client
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()));
}
// we call notifyModified here to send response if we're not in a beginUpdate block
notifyModified();
}
return registered;
} | [
"protected",
"boolean",
"register",
"(",
"IEventListener",
"listener",
")",
"{",
"log",
".",
"debug",
"(",
"\"register - listener: {}\"",
",",
"listener",
")",
";",
"boolean",
"registered",
"=",
"listeners",
".",
"add",
"(",
"listener",
")",
";",
"if",
"(",
... | Register event listener
@param listener
Event listener
@return true if listener was added | [
"Register",
"event",
"listener"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L580-L597 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.unregister | protected void unregister(IEventListener listener) {
log.debug("unregister - listener: {}", listener);
if (listeners.remove(listener)) {
listenerStats.decrement();
}
} | java | protected void unregister(IEventListener listener) {
log.debug("unregister - listener: {}", listener);
if (listeners.remove(listener)) {
listenerStats.decrement();
}
} | [
"protected",
"void",
"unregister",
"(",
"IEventListener",
"listener",
")",
"{",
"log",
".",
"debug",
"(",
"\"unregister - listener: {}\"",
",",
"listener",
")",
";",
"if",
"(",
"listeners",
".",
"remove",
"(",
"listener",
")",
")",
"{",
"listenerStats",
".",
... | Unregister event listener
@param listener
Event listener | [
"Unregister",
"event",
"listener"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L605-L610 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.checkRelease | 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();
}
} | java | 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();
}
} | [
"protected",
"void",
"checkRelease",
"(",
")",
"{",
"if",
"(",
"!",
"isPersistent",
"(",
")",
"&&",
"listeners",
".",
"isEmpty",
"(",
")",
"&&",
"!",
"isAcquired",
"(",
")",
")",
"{",
"log",
".",
"info",
"(",
"\"Deleting shared object {} because all clients ... | Check if shared object must be released. | [
"Check",
"if",
"shared",
"object",
"must",
"be",
"released",
"."
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L615-L625 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.beginUpdate | protected void beginUpdate(IEventListener listener) {
log.debug("beginUpdate - listener: {}", listener);
source = listener;
// increase number of pending updates
updateCounter.incrementAndGet();
} | java | protected void beginUpdate(IEventListener listener) {
log.debug("beginUpdate - listener: {}", listener);
source = listener;
// increase number of pending updates
updateCounter.incrementAndGet();
} | [
"protected",
"void",
"beginUpdate",
"(",
"IEventListener",
"listener",
")",
"{",
"log",
".",
"debug",
"(",
"\"beginUpdate - listener: {}\"",
",",
"listener",
")",
";",
"source",
"=",
"listener",
";",
"// increase number of pending updates\r",
"updateCounter",
".",
"in... | Begin update of this Shared Object and setting listener
@param listener
Update with listener | [
"Begin",
"update",
"of",
"this",
"Shared",
"Object",
"and",
"setting",
"listener"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L650-L655 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.clear | protected boolean clear() {
log.debug("clear");
super.removeAttributes();
// send confirmation to client
ownerMessage.addEvent(Type.CLIENT_CLEAR_DATA, name, null);
notifyModified();
changeStats.incrementAndGet();
return true;
} | java | protected boolean clear() {
log.debug("clear");
super.removeAttributes();
// send confirmation to client
ownerMessage.addEvent(Type.CLIENT_CLEAR_DATA, name, null);
notifyModified();
changeStats.incrementAndGet();
return true;
} | [
"protected",
"boolean",
"clear",
"(",
")",
"{",
"log",
".",
"debug",
"(",
"\"clear\"",
")",
";",
"super",
".",
"removeAttributes",
"(",
")",
";",
"// send confirmation to client\r",
"ownerMessage",
".",
"addEvent",
"(",
"Type",
".",
"CLIENT_CLEAR_DATA",
",",
"... | Deletes all the attributes and sends a clear event to all listeners. The persistent data object is also removed from a persistent
shared object.
@return true on success, false otherwise | [
"Deletes",
"all",
"the",
"attributes",
"and",
"sends",
"a",
"clear",
"event",
"to",
"all",
"listeners",
".",
"The",
"persistent",
"data",
"object",
"is",
"also",
"removed",
"from",
"a",
"persistent",
"shared",
"object",
"."
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L713-L721 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObject.java | SharedObject.close | protected void close() {
log.debug("close");
closed.compareAndSet(false, true);
// clear collections
super.removeAttributes();
listeners.clear();
syncEvents.clear();
ownerMessage.getEvents().clear();
} | java | protected void close() {
log.debug("close");
closed.compareAndSet(false, true);
// clear collections
super.removeAttributes();
listeners.clear();
syncEvents.clear();
ownerMessage.getEvents().clear();
} | [
"protected",
"void",
"close",
"(",
")",
"{",
"log",
".",
"debug",
"(",
"\"close\"",
")",
";",
"closed",
".",
"compareAndSet",
"(",
"false",
",",
"true",
")",
";",
"// clear collections\r",
"super",
".",
"removeAttributes",
"(",
")",
";",
"listeners",
".",
... | 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. | [
"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",
"obje... | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObject.java#L727-L735 | train |
Red5/red5-server-common | src/main/java/org/red5/server/ClientRegistry.java | ClientRegistry.addClient | private void addClient(String id, IClient client) {
// check to see if the id already exists first
if (!hasClient(id)) {
clients.put(id, client);
} else {
log.debug("Client id: {} already registered", id);
}
} | java | private void addClient(String id, IClient client) {
// check to see if the id already exists first
if (!hasClient(id)) {
clients.put(id, client);
} else {
log.debug("Client id: {} already registered", id);
}
} | [
"private",
"void",
"addClient",
"(",
"String",
"id",
",",
"IClient",
"client",
")",
"{",
"// check to see if the id already exists first\r",
"if",
"(",
"!",
"hasClient",
"(",
"id",
")",
")",
"{",
"clients",
".",
"put",
"(",
"id",
",",
"client",
")",
";",
"... | Add the client to the registry | [
"Add",
"the",
"client",
"to",
"the",
"registry"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/ClientRegistry.java#L97-L104 | train |
Red5/red5-server-common | src/main/java/org/red5/server/ClientRegistry.java | ClientRegistry.getClientList | public ClientList<Client> getClientList() {
ClientList<Client> list = new ClientList<Client>();
for (IClient c : clients.values()) {
list.add((Client) c);
}
return list;
} | java | public ClientList<Client> getClientList() {
ClientList<Client> list = new ClientList<Client>();
for (IClient c : clients.values()) {
list.add((Client) c);
}
return list;
} | [
"public",
"ClientList",
"<",
"Client",
">",
"getClientList",
"(",
")",
"{",
"ClientList",
"<",
"Client",
">",
"list",
"=",
"new",
"ClientList",
"<",
"Client",
">",
"(",
")",
";",
"for",
"(",
"IClient",
"c",
":",
"clients",
".",
"values",
"(",
")",
")... | Returns a list of Clients. | [
"Returns",
"a",
"list",
"of",
"Clients",
"."
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/ClientRegistry.java#L117-L123 | train |
Red5/red5-server-common | src/main/java/org/red5/server/ClientRegistry.java | ClientRegistry.getClients | @SuppressWarnings("unchecked")
protected Collection<IClient> getClients() {
if (!hasClients()) {
// avoid creating new Collection object if no clients exist.
return Collections.EMPTY_SET;
}
return Collections.unmodifiableCollection(clients.values());
} | java | @SuppressWarnings("unchecked")
protected Collection<IClient> getClients() {
if (!hasClients()) {
// avoid creating new Collection object if no clients exist.
return Collections.EMPTY_SET;
}
return Collections.unmodifiableCollection(clients.values());
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"protected",
"Collection",
"<",
"IClient",
">",
"getClients",
"(",
")",
"{",
"if",
"(",
"!",
"hasClients",
"(",
")",
")",
"{",
"// avoid creating new Collection object if no clients exist.\r",
"return",
"Collections"... | Return collection of clients
@return Collection of clients | [
"Return",
"collection",
"of",
"clients"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/ClientRegistry.java#L147-L154 | train |
Red5/red5-server-common | src/main/java/org/red5/server/ClientRegistry.java | ClientRegistry.newClient | public IClient newClient(Object[] params) throws ClientNotFoundException, ClientRejectedException {
// derive client id from the connection params or use next
String id = nextId();
IClient client = new Client(id, this);
addClient(id, client);
return client;
} | java | public IClient newClient(Object[] params) throws ClientNotFoundException, ClientRejectedException {
// derive client id from the connection params or use next
String id = nextId();
IClient client = new Client(id, this);
addClient(id, client);
return client;
} | [
"public",
"IClient",
"newClient",
"(",
"Object",
"[",
"]",
"params",
")",
"throws",
"ClientNotFoundException",
",",
"ClientRejectedException",
"{",
"// derive client id from the connection params or use next\r",
"String",
"id",
"=",
"nextId",
"(",
")",
";",
"IClient",
"... | Return client from next id with given params
@param params
Client params
@return Client object
@throws ClientNotFoundException
if client not found
@throws ClientRejectedException
if client rejected | [
"Return",
"client",
"from",
"next",
"id",
"with",
"given",
"params"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/ClientRegistry.java#L195-L201 | train |
Red5/red5-server-common | src/main/java/org/red5/server/ClientRegistry.java | ClientRegistry.nextId | public String nextId() {
String id = "-1";
do {
// when we reach max int, reset to zero
if (nextId.get() == Integer.MAX_VALUE) {
nextId.set(0);
}
id = String.format("%d", nextId.getAndIncrement());
} while (hasClient(id));
return id;
} | java | public String nextId() {
String id = "-1";
do {
// when we reach max int, reset to zero
if (nextId.get() == Integer.MAX_VALUE) {
nextId.set(0);
}
id = String.format("%d", nextId.getAndIncrement());
} while (hasClient(id));
return id;
} | [
"public",
"String",
"nextId",
"(",
")",
"{",
"String",
"id",
"=",
"\"-1\"",
";",
"do",
"{",
"// when we reach max int, reset to zero\r",
"if",
"(",
"nextId",
".",
"get",
"(",
")",
"==",
"Integer",
".",
"MAX_VALUE",
")",
"{",
"nextId",
".",
"set",
"(",
"0... | Return next client id
@return Next client id | [
"Return",
"next",
"client",
"id"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/ClientRegistry.java#L208-L218 | train |
Red5/red5-server-common | src/main/java/org/red5/server/so/SharedObjectService.java | SharedObjectService.getStore | private IPersistenceStore getStore(IScope scope, boolean persistent) {
IPersistenceStore store;
if (!persistent) {
// Use special store for non-persistent shared objects
if (!scope.hasAttribute(SO_TRANSIENT_STORE)) {
store = new RamPersistence(scope);
scope.setAttribute(SO_TRANSIENT_STORE, store);
return store;
}
return (IPersistenceStore) scope.getAttribute(SO_TRANSIENT_STORE);
}
// Evaluate configuration for persistent shared objects
if (!scope.hasAttribute(SO_PERSISTENCE_STORE)) {
try {
store = PersistenceUtils.getPersistenceStore(scope, persistenceClassName);
log.info("Created persistence store {} for shared objects", store);
} catch (Exception err) {
log.warn("Could not create persistence store ({}) for shared objects, falling back to Ram persistence", persistenceClassName, err);
store = new RamPersistence(scope);
}
scope.setAttribute(SO_PERSISTENCE_STORE, store);
return store;
}
return (IPersistenceStore) scope.getAttribute(SO_PERSISTENCE_STORE);
} | java | private IPersistenceStore getStore(IScope scope, boolean persistent) {
IPersistenceStore store;
if (!persistent) {
// Use special store for non-persistent shared objects
if (!scope.hasAttribute(SO_TRANSIENT_STORE)) {
store = new RamPersistence(scope);
scope.setAttribute(SO_TRANSIENT_STORE, store);
return store;
}
return (IPersistenceStore) scope.getAttribute(SO_TRANSIENT_STORE);
}
// Evaluate configuration for persistent shared objects
if (!scope.hasAttribute(SO_PERSISTENCE_STORE)) {
try {
store = PersistenceUtils.getPersistenceStore(scope, persistenceClassName);
log.info("Created persistence store {} for shared objects", store);
} catch (Exception err) {
log.warn("Could not create persistence store ({}) for shared objects, falling back to Ram persistence", persistenceClassName, err);
store = new RamPersistence(scope);
}
scope.setAttribute(SO_PERSISTENCE_STORE, store);
return store;
}
return (IPersistenceStore) scope.getAttribute(SO_PERSISTENCE_STORE);
} | [
"private",
"IPersistenceStore",
"getStore",
"(",
"IScope",
"scope",
",",
"boolean",
"persistent",
")",
"{",
"IPersistenceStore",
"store",
";",
"if",
"(",
"!",
"persistent",
")",
"{",
"// Use special store for non-persistent shared objects\r",
"if",
"(",
"!",
"scope",
... | Return scope store
@param scope
Scope
@param persistent
Persistent store or not?
@return Scope's store | [
"Return",
"scope",
"store"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/so/SharedObjectService.java#L112-L136 | train |
Red5/red5-server-common | src/main/java/org/red5/server/api/persistence/PersistenceUtils.java | PersistenceUtils.getPersistenceStoreConstructor | private static Constructor<?> getPersistenceStoreConstructor(Class<?> theClass, Class<?>[] interfaces) throws Exception {
Constructor<?> constructor = null;
for (Class<?> interfaceClass : interfaces) {
try {
constructor = theClass.getConstructor(new Class[] { interfaceClass });
} catch (NoSuchMethodException err) {
// Ignore this error
}
if (constructor != null) {
break;
}
constructor = getPersistenceStoreConstructor(theClass, interfaceClass.getInterfaces());
if (constructor != null) {
break;
}
}
return constructor;
} | java | private static Constructor<?> getPersistenceStoreConstructor(Class<?> theClass, Class<?>[] interfaces) throws Exception {
Constructor<?> constructor = null;
for (Class<?> interfaceClass : interfaces) {
try {
constructor = theClass.getConstructor(new Class[] { interfaceClass });
} catch (NoSuchMethodException err) {
// Ignore this error
}
if (constructor != null) {
break;
}
constructor = getPersistenceStoreConstructor(theClass, interfaceClass.getInterfaces());
if (constructor != null) {
break;
}
}
return constructor;
} | [
"private",
"static",
"Constructor",
"<",
"?",
">",
"getPersistenceStoreConstructor",
"(",
"Class",
"<",
"?",
">",
"theClass",
",",
"Class",
"<",
"?",
">",
"[",
"]",
"interfaces",
")",
"throws",
"Exception",
"{",
"Constructor",
"<",
"?",
">",
"constructor",
... | Returns persistence store object class constructor
@param theClass
Persistence store class
@param interfaces
Interfaces that are being implemented by persistence store object class
@return Constructor
@throws Exception | [
"Returns",
"persistence",
"store",
"object",
"class",
"constructor"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/api/persistence/PersistenceUtils.java#L43-L60 | train |
Red5/red5-server-common | src/main/java/org/red5/server/net/rtmp/message/ChunkHeader.java | ChunkHeader.read | public static ChunkHeader read(IoBuffer in) {
int remaining = in.remaining();
if (remaining > 0) {
byte headerByte = in.get();
ChunkHeader h = new ChunkHeader();
// going to check highest 2 bits
h.format = (byte) ((0b11000000 & headerByte) >> 6);
int fmt = headerByte & 0x3f;
switch (fmt) {
case 0:
// two byte header
h.size = 2;
if (remaining < 2) {
throw new ProtocolException("Bad chunk header, at least 2 bytes are expected");
}
h.channelId = 64 + (in.get() & 0xff);
break;
case 1:
// three byte header
h.size = 3;
if (remaining < 3) {
throw new ProtocolException("Bad chunk header, at least 3 bytes are expected");
}
byte b1 = in.get();
byte b2 = in.get();
h.channelId = 64 + ((b2 & 0xff) << 8 | (b1 & 0xff));
break;
default:
// single byte header
h.size = 1;
h.channelId = 0x3f & headerByte;
break;
}
// check channel id is valid
if (h.channelId < 0) {
throw new ProtocolException("Bad channel id: " + h.channelId);
}
log.trace("CHUNK header byte {}, count {}, header {}, channel {}", String.format("%02x", headerByte), h.size, 0, h.channelId);
return h;
} else {
// at least one byte for valid decode
throw new ProtocolException("Bad chunk header, at least 1 byte is expected");
}
} | java | public static ChunkHeader read(IoBuffer in) {
int remaining = in.remaining();
if (remaining > 0) {
byte headerByte = in.get();
ChunkHeader h = new ChunkHeader();
// going to check highest 2 bits
h.format = (byte) ((0b11000000 & headerByte) >> 6);
int fmt = headerByte & 0x3f;
switch (fmt) {
case 0:
// two byte header
h.size = 2;
if (remaining < 2) {
throw new ProtocolException("Bad chunk header, at least 2 bytes are expected");
}
h.channelId = 64 + (in.get() & 0xff);
break;
case 1:
// three byte header
h.size = 3;
if (remaining < 3) {
throw new ProtocolException("Bad chunk header, at least 3 bytes are expected");
}
byte b1 = in.get();
byte b2 = in.get();
h.channelId = 64 + ((b2 & 0xff) << 8 | (b1 & 0xff));
break;
default:
// single byte header
h.size = 1;
h.channelId = 0x3f & headerByte;
break;
}
// check channel id is valid
if (h.channelId < 0) {
throw new ProtocolException("Bad channel id: " + h.channelId);
}
log.trace("CHUNK header byte {}, count {}, header {}, channel {}", String.format("%02x", headerByte), h.size, 0, h.channelId);
return h;
} else {
// at least one byte for valid decode
throw new ProtocolException("Bad chunk header, at least 1 byte is expected");
}
} | [
"public",
"static",
"ChunkHeader",
"read",
"(",
"IoBuffer",
"in",
")",
"{",
"int",
"remaining",
"=",
"in",
".",
"remaining",
"(",
")",
";",
"if",
"(",
"remaining",
">",
"0",
")",
"{",
"byte",
"headerByte",
"=",
"in",
".",
"get",
"(",
")",
";",
"Chu... | Read chunk header from the buffer.
@param in
buffer
@return ChunkHeader instance | [
"Read",
"chunk",
"header",
"from",
"the",
"buffer",
"."
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/net/rtmp/message/ChunkHeader.java#L121-L164 | train |
Red5/red5-server-common | src/main/java/org/red5/server/stream/consumer/SlicedFileConsumer.java | SlicedFileConsumer.acquireWriteFuture | private boolean acquireWriteFuture(int sliceLength) {
if (sliceLength > 0) {
Object writeResult = null;
// determine a good timeout value based on the slice length to write
int timeout = sliceLength * 500;
// check for existing future
if (writerFuture != null) {
try {
// wait for a result from the last writer
writeResult = writerFuture.get(timeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
log.warn("Exception waiting for write result. Timeout: {}ms", timeout, e);
return false;
}
}
log.debug("Write future result (expect null): {}", writeResult);
return true;
}
return false;
} | java | private boolean acquireWriteFuture(int sliceLength) {
if (sliceLength > 0) {
Object writeResult = null;
// determine a good timeout value based on the slice length to write
int timeout = sliceLength * 500;
// check for existing future
if (writerFuture != null) {
try {
// wait for a result from the last writer
writeResult = writerFuture.get(timeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
log.warn("Exception waiting for write result. Timeout: {}ms", timeout, e);
return false;
}
}
log.debug("Write future result (expect null): {}", writeResult);
return true;
}
return false;
} | [
"private",
"boolean",
"acquireWriteFuture",
"(",
"int",
"sliceLength",
")",
"{",
"if",
"(",
"sliceLength",
">",
"0",
")",
"{",
"Object",
"writeResult",
"=",
"null",
";",
"// determine a good timeout value based on the slice length to write\r",
"int",
"timeout",
"=",
"... | Get the WriteFuture with a timeout based on the length of the slice to write.
@param sliceLength
@return true if successful and false otherwise | [
"Get",
"the",
"WriteFuture",
"with",
"a",
"timeout",
"based",
"on",
"the",
"length",
"of",
"the",
"slice",
"to",
"write",
"."
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/stream/consumer/SlicedFileConsumer.java#L376-L395 | train |
Red5/red5-server-common | src/main/java/org/red5/server/stream/consumer/SlicedFileConsumer.java | SlicedFileConsumer.uninit | public void uninit() {
if (initialized.get()) {
log.debug("Uninit");
if (writer != null) {
if (writerFuture != null) {
try {
writerFuture.get();
} catch (Exception e) {
log.warn("Exception waiting for write result on uninit", e);
}
if (writerFuture.cancel(false)) {
log.debug("Future completed");
}
}
writerFuture = null;
// write all the queued items
doWrites();
// clear the queue
queue.clear();
queue = null;
// close the writer
writer.close();
writer = null;
}
// clear path ref
path = null;
}
} | java | public void uninit() {
if (initialized.get()) {
log.debug("Uninit");
if (writer != null) {
if (writerFuture != null) {
try {
writerFuture.get();
} catch (Exception e) {
log.warn("Exception waiting for write result on uninit", e);
}
if (writerFuture.cancel(false)) {
log.debug("Future completed");
}
}
writerFuture = null;
// write all the queued items
doWrites();
// clear the queue
queue.clear();
queue = null;
// close the writer
writer.close();
writer = null;
}
// clear path ref
path = null;
}
} | [
"public",
"void",
"uninit",
"(",
")",
"{",
"if",
"(",
"initialized",
".",
"get",
"(",
")",
")",
"{",
"log",
".",
"debug",
"(",
"\"Uninit\"",
")",
";",
"if",
"(",
"writer",
"!=",
"null",
")",
"{",
"if",
"(",
"writerFuture",
"!=",
"null",
")",
"{",... | Reset or uninitialize | [
"Reset",
"or",
"uninitialize"
] | 39ae73710c25bda86d70b13ef37ae707962217b9 | https://github.com/Red5/red5-server-common/blob/39ae73710c25bda86d70b13ef37ae707962217b9/src/main/java/org/red5/server/stream/consumer/SlicedFileConsumer.java#L499-L526 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.