Skip to content

Commit

Permalink
simple db makeover
Browse files Browse the repository at this point in the history
  • Loading branch information
akamel001 committed Apr 8, 2012
1 parent 563f8ae commit 24f2817
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions server/SimpleDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import rpc.RpcServer;
import rpc.message.RpcMessageCall;
Expand Down Expand Up @@ -38,16 +40,16 @@ public final class SimpleDB extends Thread {
private static AmazonSimpleDBClient sdbc = null;
private static String AttrName = "IPP";

private static final HashSet<IPP> localMbrList = new HashSet<IPP>();
//private static final HashSet<IPP> localMbrList = new HashSet<IPP>();
Set<IPP> localMbrList = Collections.newSetFromMap(new ConcurrentHashMap<IPP, Boolean>());
private static SimpleDB db = new SimpleDB();

private SimpleDB() {
oAWSCredentials = new BasicAWSCredentials(getKey(), getSecret());
sdbc = new AmazonSimpleDBClient(oAWSCredentials);
}

public synchronized void createDomain(String domain){
public void createDomain(String domain){
if(DEBUG) System.out.println("Connecting and creating domain (" + domain + ")");
sdbc.createDomain(new CreateDomainRequest(domain));

Expand All @@ -73,14 +75,14 @@ public synchronized void createDomain(String domain){
}
}

public synchronized void deleteDomain(String domain){
public void deleteDomain(String domain){
if(DEBUG) System.out.println("Deleting domain ("+domain +")");
DeleteDomainRequest deleteDomainRequest = new DeleteDomainRequest();
deleteDomainRequest.setDomainName(domain);
sdbc.deleteDomain(deleteDomainRequest);
}

public synchronized void memberRefresh(){
public void memberRefresh(){
//Set the local MbrSet to empty.
localMbrList.clear();

Expand Down Expand Up @@ -135,11 +137,11 @@ public synchronized void memberRefresh(){
}
}

public synchronized void deleteLocalMember(IPP ipp){
public void deleteLocalMember(IPP ipp){
localMbrList.remove(ipp);
}

public synchronized void putLocalMember(IPP ipp){
public void putLocalMember(IPP ipp){
localMbrList.add(ipp);
}

Expand All @@ -152,7 +154,7 @@ private String trimAndToString(ArrayList<IPP> list){
return " ";
return list.toString().replace("[", "").replace("]", "");
}
public synchronized ArrayList<IPP> getLocalMembers(){
public ArrayList<IPP> getLocalMembers(){
ArrayList<IPP> result = new ArrayList<IPP>();
result.addAll(localMbrList);
return result;
Expand Down Expand Up @@ -189,7 +191,7 @@ private ArrayList<IPP> getMembers(){
return servers;
}

public synchronized void listDomains(PrintWriter out) {
public void listDomains(PrintWriter out) {
for(String domainName : sdbc.listDomains().getDomainNames()){
out.println("Domain: " + domainName);
}
Expand Down Expand Up @@ -225,7 +227,7 @@ public void run() {
double probOfRefresh = 1.0/localMbrList.size();
double rand = generator.nextDouble();

//if(rand <= probOfRefresh)
if(rand <= probOfRefresh)
memberRefresh();
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down

0 comments on commit 24f2817

Please sign in to comment.