-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix-bugs-to-run' into distribute-resource-managers
- Loading branch information
Showing
26 changed files
with
847 additions
and
226 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package Server.Common; | ||
|
||
import Server.Interface.*; | ||
|
||
import java.util.*; | ||
import java.rmi.RemoteException; | ||
import java.io.*; | ||
|
||
public class CustomerResourceManager extends AbstractRMHashMapManager implements ICustomerResourceManager | ||
{ | ||
private String m_name=""; | ||
|
||
public CustomerResourceManager(String p_name) { | ||
m_name = p_name; | ||
}; | ||
|
||
public int newCustomer(int xid) throws RemoteException { | ||
Trace.info("RM::newCustomer(" + xid + ") called"); | ||
// Generate a globally unique ID for the new customer | ||
int cid = Integer.parseInt(String.valueOf(xid) + | ||
String.valueOf(Calendar.getInstance().get(Calendar.MILLISECOND)) + | ||
String.valueOf(Math.round(Math.random() * 100 + 1))); | ||
Customer customer = new Customer(cid); | ||
writeData(xid, customer.getKey(), customer); | ||
Trace.info("RM::newCustomer(" + cid + ") returns ID=" + cid); | ||
return cid; | ||
} | ||
|
||
public boolean newCustomer(int xid, int customerID) throws RemoteException | ||
{ | ||
Trace.info("RM::newCustomer(" + xid + ", " + customerID + ") called"); | ||
Customer customer = (Customer)readData(xid, Customer.getKey(customerID)); | ||
if (customer == null) | ||
{ | ||
customer = new Customer(customerID); | ||
writeData(xid, customer.getKey(), customer); | ||
Trace.info("RM::newCustomer(" + xid + ", " + customerID + ") created a new customer"); | ||
return true; | ||
} | ||
else | ||
{ | ||
Trace.info("INFO: RM::newCustomer(" + xid + ", " + customerID + ") failed--customer already exists"); | ||
return false; | ||
} | ||
} | ||
|
||
|
||
public boolean deleteCustomer(int xid, int customerID) throws RemoteException | ||
{ | ||
Trace.info("RM::deleteCustomer(" + xid + ", " + customerID + ") called"); | ||
Customer customer = (Customer)readData(xid, Customer.getKey(customerID)); | ||
if (customer == null) | ||
{ | ||
Trace.warn("RM::deleteCustomer(" + xid + ", " + customerID + ") failed--customer doesn't exist"); | ||
return false; | ||
} | ||
else | ||
{ | ||
// Increase the reserved numbers of all reservable items which the customer reserved. | ||
RMHashMap reservations = customer.getReservations(); | ||
for (String reservedKey : reservations.keySet()) | ||
{ | ||
ReservedItem reserveditem = customer.getReservedItem(reservedKey); | ||
Trace.info("RM::deleteCustomer(" + xid + ", " + customerID + ") has reserved " + reserveditem.getKey() + " " + reserveditem.getCount() + " times"); | ||
ReservableItem item = (ReservableItem)readData(xid, reserveditem.getKey()); | ||
Trace.info("RM::deleteCustomer(" + xid + ", " + customerID + ") has reserved " + reserveditem.getKey() + " which is reserved " + item.getReserved() + " times and is still available " + item.getCount() + " times"); | ||
item.setReserved(item.getReserved() - reserveditem.getCount()); | ||
item.setCount(item.getCount() + reserveditem.getCount()); | ||
writeData(xid, item.getKey(), item); | ||
} | ||
|
||
// Remove the customer from the storage | ||
removeData(xid, customer.getKey()); | ||
Trace.info("RM::deleteCustomer(" + xid + ", " + customerID + ") succeeded"); | ||
return true; | ||
} | ||
} | ||
|
||
public String queryCustomerInfo(int xid, int customerID) throws RemoteException | ||
{ | ||
Trace.info("RM::queryCustomerInfo(" + xid + ", " + customerID + ") called"); | ||
Customer customer = (Customer)readData(xid, Customer.getKey(customerID)); | ||
if (customer == null) | ||
{ | ||
Trace.warn("RM::queryCustomerInfo(" + xid + ", " + customerID + ") failed--customer doesn't exist"); | ||
// NOTE: don't change this--WC counts on this value indicating a customer does not exist... | ||
return ""; | ||
} | ||
else | ||
{ | ||
Trace.info("RM::queryCustomerInfo(" + xid + ", " + customerID + ")"); | ||
System.out.println(customer.getBill()); | ||
return customer.getBill(); | ||
} | ||
} | ||
|
||
public String getName() throws RemoteException | ||
{ | ||
return m_name; | ||
} | ||
|
||
public Customer getCustomer(int xid, int customerID) throws RemoteException | ||
{ | ||
return (Customer)readData(xid, Customer.getKey(customerID)); | ||
} | ||
} |
Oops, something went wrong.