Created
March 8, 2012 07:35
-
-
Save enesakar/1999418 to your computer and use it in GitHub Desktop.
Hazelcast MapStore Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyMapStore implements MapStore<String, Contact> { | |
private AmazonSimpleDB sdb; | |
private void init() { | |
try { | |
sdb = new AmazonSimpleDBClient(new PropertiesCredentials(getClass().getClassLoader().getResourceAsStream("AwsCredentials.properties"))); | |
createDomainIfNotExists("Contact"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
private void createDomainIfNotExists(String domainName) { | |
if (!sdb.listDomains().getDomainNames().contains(domainName)) | |
sdb.createDomain(new CreateDomainRequest(domainName)); | |
} | |
public void store(String key, Contact contact) { | |
List<ReplaceableAttribute> attrList = new ArrayList<ReplaceableAttribute>(); | |
attrList.add(new ReplaceableAttribute("Phone", contact.getPhone(), true)); | |
attrList.add(new ReplaceableAttribute("Name", contact.getName(), true)); | |
sdb.putAttributes(new PutAttributesRequest("Contact", contact.getName(), attrList)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment