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
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>3.8.1</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>com.hazelcast</groupId> | |
<artifactId>hazelcast</artifactId> |
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(); |
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 Contact load(String key) { | |
SelectRequest req = new SelectRequest("select * from Contact where itemName() = '" + key + "'"); | |
SelectResult result = sdb.select(req); | |
if (!result.getItems().isEmpty()) { | |
Item item = result.getItems().get(0); | |
return formContact(item.getAttributes()); | |
} else { | |
return null; | |
} | |
} |
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
<map-store enabled="true"> | |
<class-name>com.hazelsimpledb.service.MyMapStore</class-name> | |
<write-delay-seconds>0</write-delay-seconds> | |
</map-store> |
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
<dependency> | |
<groupId>com.hazelcast</groupId> | |
<artifactId>hazelcast</artifactId> | |
<version>1.9.4.4</version> | |
</dependency> | |
<dependency> | |
<groupId>com.hazelcast</groupId> | |
<artifactId>hazelcast-cloud</artifactId> | |
<version>1.9.4.4</version> | |
</dependency> |
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
package com.hazelsimpledb.model; | |
import java.io.Serializable; | |
public class Contact implements Serializable{ | |
private String name; | |
private String phone; | |
.... | |
} |
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> { | |
public void store(String key, Contact contact) { | |
DataService.getInstance().addContact(contact.getPhone(), contact.getName()); | |
} | |
public void storeAll(Map<String, Contact> contactMap) { | |
for(String key: contactMap.keySet()) { | |
store(key, contactMap.get(key)); | |
} | |
} |
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 void addContact(String phone, String name) { | |
List<ReplaceableAttribute> attrList = new ArrayList<ReplaceableAttribute>(); | |
attrList.add(new ReplaceableAttribute("Phone", phone, true)); | |
attrList.add(new ReplaceableAttribute("Name", name, true)); | |
sdb.putAttributes(new PutAttributesRequest("Contact", name, attrList)); | |
} | |
public Contact loadContact(String name) { | |
SelectRequest req = new SelectRequest("select * from Contact where itemName() = '" + name + "'"); | |
SelectResult result = sdb.select(req); | |
if (!result.getItems().isEmpty()) { |
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
<map-store enabled="true"> | |
<class-name>com.hazelsimpledb.service.MyMapStore</class-name> | |
<write-delay-seconds>0</write-delay-seconds> | |
</map-store> |
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
private void save(HttpServletRequest request) { | |
String phone = request.getParameter("phone"); | |
String name = request.getParameter("name"); | |
Map<String, Contact> mapContacts = Hazelcast.getMap("Contacts"); | |
mapContacts.put(name, new Contact(name, phone)); | |
request.setAttribute("message","Contact has been added."); | |
} | |
private void search(HttpServletRequest request) { | |
Map<String, Contact> mapContacts = Hazelcast.getMap("Contacts"); |
OlderNewer