diff --git a/ws/src/middleware/MwHandler.java b/ws/src/middleware/MwHandler.java new file mode 100644 index 0000000..e3e01e0 --- /dev/null +++ b/ws/src/middleware/MwHandler.java @@ -0,0 +1,19 @@ +package middleware; + +import javax.xml.ws.handler.soap.SOAPMessageContext; + +import server.PerfHandler; + +public class MwHandler extends PerfHandler { + + public boolean handleMessage(SOAPMessageContext mc) { + // Don't continue if PerfHandler doesn't want to + if (!super.handleMessage(mc)) + return false; + + /* Any custom code for the MW here... */ + + return true; + } + +} diff --git a/ws/src/middleware/ResourceManagerImpl.java b/ws/src/middleware/ResourceManagerImpl.java index 3232a7e..1c0bc13 100644 --- a/ws/src/middleware/ResourceManagerImpl.java +++ b/ws/src/middleware/ResourceManagerImpl.java @@ -11,12 +11,14 @@ import java.net.URL; import java.util.*; +import javax.jws.HandlerChain; import javax.jws.WebService; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; @WebService(endpointInterface = "server.ws.ResourceManager") +@HandlerChain(file="mw_handler.xml") public class ResourceManagerImpl implements server.ws.ResourceManager { private static final int PROXY_POOL_SIZE = 4; @@ -74,7 +76,6 @@ public ResourceManagerImpl() } public boolean abort(int id) { - long start = System.nanoTime(); boolean result = true; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -116,12 +117,10 @@ public boolean abort(int id) { } } - log("abort", id, start); return result; } public boolean addCars(int id, String location, int numCars, int carPrice) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { @@ -132,7 +131,6 @@ public boolean addCars(int id, String location, int numCars, int carPrice) { _lockManager.Lock(id, Car.getKey(location), LockManager.WRITE); } catch (Exception e) { abort(id); - log("addCars", id, start); return false; } _transactionManager.addTransactionRM(id, TransactionManager.CAR); @@ -142,13 +140,11 @@ public boolean addCars(int id, String location, int numCars, int carPrice) { carProxies.checkIn(proxy); } - log("addCars", id, start); return result; } public boolean addFlight(int id, int flightNumber, int numSeats, int flightPrice) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { @@ -159,7 +155,6 @@ public boolean addFlight(int id, int flightNumber, int numSeats, _lockManager.Lock(id, Flight.getKey(flightNumber), LockManager.WRITE); } catch (Exception e) { abort(id); - log("addFlight", id, start); return false; } _transactionManager.addTransactionRM(id, TransactionManager.FLIGHT); @@ -168,12 +163,10 @@ public boolean addFlight(int id, int flightNumber, int numSeats, result = proxy.addFlight(id, flightNumber, numSeats, flightPrice); flightProxies.checkIn(proxy); } - log("addFlight", id, start); return result; } public boolean addRooms(int id, String location, int numRooms, int roomPrice) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -183,7 +176,6 @@ public boolean addRooms(int id, String location, int numRooms, int roomPrice) { _lockManager.Lock(id, Room.getKey(location), LockManager.WRITE); } catch (Exception e) { abort(id); - log("addRooms", id, start); return false; } _transactionManager.addTransactionRM(id, TransactionManager.ROOM); @@ -192,12 +184,10 @@ public boolean addRooms(int id, String location, int numRooms, int roomPrice) { result = proxy.addRooms(id, location, numRooms, roomPrice); roomProxies.checkIn(proxy); } - log("addRooms", id, start); return result; } public boolean commit(int id) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -238,12 +228,10 @@ public boolean commit(int id) { } } - log("commit", id, start); return result; } public boolean deleteCars(int id, String location) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -253,7 +241,6 @@ public boolean deleteCars(int id, String location) { _lockManager.Lock(id, Car.getKey(location), LockManager.WRITE); } catch (Exception e) { abort(id); - log("deleteCars", id, start); return false; } _transactionManager.addTransactionRM(id, TransactionManager.CAR); @@ -263,12 +250,10 @@ public boolean deleteCars(int id, String location) { carProxies.checkIn(proxy); } - log("deleteCars", id, start); return result; } public boolean deleteCustomer(int id, int customerId) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -278,7 +263,6 @@ public boolean deleteCustomer(int id, int customerId) { _lockManager.Lock(id, Customer.getKey(customerId), LockManager.WRITE); } catch (Exception e) { abort(id); - log("deleteCustomer", id, start); return false; } @@ -312,12 +296,10 @@ public boolean deleteCustomer(int id, int customerId) { } } - log("deleteCustomer", id, start); return result; } public boolean deleteFlight(int id, int flightNumber) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -327,7 +309,6 @@ public boolean deleteFlight(int id, int flightNumber) { _lockManager.Lock(id, Flight.getKey(flightNumber), LockManager.WRITE); } catch (Exception e) { abort(id); - log("deleteFlight", id, start); return false; } _transactionManager.addTransactionRM(id, TransactionManager.FLIGHT); @@ -337,12 +318,10 @@ public boolean deleteFlight(int id, int flightNumber) { flightProxies.checkIn(proxy); } - log("deleteFlight", id, start); return result; } public boolean deleteRooms(int id, String location) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { @@ -353,7 +332,6 @@ public boolean deleteRooms(int id, String location) { _lockManager.Lock(id, Room.getKey(location), LockManager.WRITE); } catch (Exception e) { abort(id); - log("deleteRooms", id, start); return false; } _transactionManager.addTransactionRM(id, TransactionManager.ROOM); @@ -363,12 +341,10 @@ public boolean deleteRooms(int id, String location) { roomProxies.checkIn(proxy); } - log("deleteRooms", id, start); return result; } public int newCustomer(int id) { - long start = System.nanoTime(); int result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -381,12 +357,10 @@ public int newCustomer(int id) { customerProxies.checkIn(proxy); } - log("newCustomer", id, start); return result; } public boolean newCustomerId(int id, int customerId) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -396,7 +370,6 @@ public boolean newCustomerId(int id, int customerId) { _lockManager.Lock(id, Customer.getKey(customerId), LockManager.WRITE); } catch (Exception e) { abort(id); - log("newCustomerId", id, start); return false; } _transactionManager.addTransactionRM(id, TransactionManager.CUSTOMER); @@ -407,12 +380,10 @@ public boolean newCustomerId(int id, int customerId) { result = proxy.newCustomerId(id, customerId); customerProxies.checkIn(proxy); } - log("newCustomerId", id, start); return result; } public int queryCars(int id, String location) { - long start = System.nanoTime(); int result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -422,19 +393,16 @@ public int queryCars(int id, String location) { _lockManager.Lock(id, Car.getKey(location), LockManager.READ); } catch (Exception e) { abort(id); - log("queryCars", id, start); return -1; } ResourceManager proxy = carProxies.checkOut(); result = proxy.queryCars(id, location); carProxies.checkIn(proxy); } - log("queryCars", id, start); return result; } public int queryCarsPrice(int id, String location) { - long start = System.nanoTime(); int result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -444,7 +412,6 @@ public int queryCarsPrice(int id, String location) { _lockManager.Lock(id, Car.getKey(location), LockManager.READ); } catch (Exception e) { abort(id); - log("queryCarsPrice", id, start); return -1; } ResourceManager proxy = carProxies.checkOut(); @@ -452,12 +419,10 @@ public int queryCarsPrice(int id, String location) { carProxies.checkIn(proxy); } - log("queryCarsPrice", id, start); return result; } public String queryCustomerInfo(int id, int customerId) { - long start = System.nanoTime(); String result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -467,7 +432,6 @@ public String queryCustomerInfo(int id, int customerId) { _lockManager.Lock(id, Customer.getKey(customerId), LockManager.READ); } catch (Exception e) { abort(id); - log("queryCustomerInfo", id, start); return null; } ResourceManager customerProxy = customerProxies.checkOut(); @@ -512,12 +476,10 @@ public String queryCustomerInfo(int id, int customerId) { } } - log("queryCustomerInfo", id, start); return result; } public int queryFlight(int id, int flightNumber) { - long start = System.nanoTime(); int result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -527,19 +489,16 @@ public int queryFlight(int id, int flightNumber) { _lockManager.Lock(id, Flight.getKey(flightNumber), LockManager.READ); } catch (Exception e) { abort(id); - log("queryFlight", id, start); return -1; } ResourceManager proxy = flightProxies.checkOut(); result = proxy.queryFlight(id, flightNumber); flightProxies.checkIn(proxy); } - log("queryFlight", id, start); return result; } public int queryFlightPrice(int id, int flightNumber) { - long start = System.nanoTime(); int result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -549,19 +508,16 @@ public int queryFlightPrice(int id, int flightNumber) { _lockManager.Lock(id, Flight.getKey(flightNumber), LockManager.READ); } catch (Exception e) { abort(id); - log("queryFlightPrice", id, start); return -1; } ResourceManager proxy = flightProxies.checkOut(); result = proxy.queryFlightPrice(id, flightNumber); flightProxies.checkIn(proxy); } - log("queryFlightPrice", id, start); return result; } public int queryRooms(int id, String location) { - long start = System.nanoTime(); int result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -571,20 +527,16 @@ public int queryRooms(int id, String location) { _lockManager.Lock(id, Room.getKey(location), LockManager.READ); } catch (Exception e) { abort(id); - log("queryRooms", id, start); return -1; } ResourceManager proxy = roomProxies.checkOut(); result = proxy.queryRooms(id, location); roomProxies.checkIn(proxy); } - - log("queryRooms", id, start); return result; } public int queryRoomsPrice(int id, String location) { - long start = System.nanoTime(); int result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -594,21 +546,17 @@ public int queryRoomsPrice(int id, String location) { _lockManager.Lock(id, Room.getKey(location), LockManager.READ); } catch (Exception e) { abort(id); - log("queryRoomsPrice", id, start); return -1; } ResourceManager proxy = roomProxies.checkOut(); result = proxy.queryRoomsPrice(id, location); roomProxies.checkIn(proxy); } - - log("queryRoomsPrice", id, start); - + return result; } public boolean reserveCar(int id, int customerId, String location) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -619,7 +567,6 @@ public boolean reserveCar(int id, int customerId, String location) { _lockManager.Lock(id, Customer.getKey(customerId), LockManager.WRITE); } catch (Exception e) { abort(id); - log("reserveCar", id, start); return false; } ResourceManager proxy = customerProxies.checkOut(); @@ -637,13 +584,12 @@ public boolean reserveCar(int id, int customerId, String location) { else result = false; } - log("reserveCar", id, start); - + return result; } public boolean reserveFlight(int id, int customerId, int flightNumber) { - long start = System.nanoTime(); + boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -654,7 +600,6 @@ public boolean reserveFlight(int id, int customerId, int flightNumber) { _lockManager.Lock(id, Customer.getKey(customerId), LockManager.WRITE); } catch (Exception e) { abort(id); - log("reserveFlight", id, start); return false; } ResourceManager proxy = customerProxies.checkOut(); @@ -671,13 +616,11 @@ public boolean reserveFlight(int id, int customerId, int flightNumber) { } else result = false; } - log("reserveFlight", id, start); return result; } public boolean reserveItinerary(int id, int customerId, Vector flightNumbers, String location, boolean car, boolean room) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -687,7 +630,6 @@ public boolean reserveItinerary(int id, int customerId, _lockManager.Lock(id, Customer.getKey(customerId), LockManager.WRITE); } catch (Exception e) { abort(id); - log("reserveItinerary", id, start); return false; } // If customer doesn't exist, bail now. @@ -709,7 +651,6 @@ public boolean reserveItinerary(int id, int customerId, } } catch (Exception e) { abort(id); - log("reserveItinerary", id, start); return false; } @@ -777,13 +718,11 @@ public boolean reserveItinerary(int id, int customerId, } } } - - log("reserveItinerary", id, start); + return result; } public boolean reserveRoom(int id, int customerId, String location) { - long start = System.nanoTime(); boolean result; if (!_transactionManager.hasValidId(id)) { Trace.info("ID is not valid."); @@ -794,7 +733,6 @@ public boolean reserveRoom(int id, int customerId, String location) { _lockManager.Lock(id, Customer.getKey(customerId), LockManager.WRITE); } catch (Exception e) { abort(id); - log("reserveRoom", id, start); return false; } ResourceManager proxy = customerProxies.checkOut(); @@ -811,32 +749,26 @@ public boolean reserveRoom(int id, int customerId, String location) { } else result = false; } - - log("reserveRoom", id, start); + return result; } public int start() { - long start = System.nanoTime(); int result = _transactionManager.start(); - log("start", result, start); return result; } public boolean checkCustomerExistence(int id, int customerId) { // Again, this method probably won't be called by the client. - long start = System.nanoTime(); try { _lockManager.Lock(id, Customer.getKey(customerId), LockManager.READ); } catch (Exception e) { abort(id); - log("checkCustomerExistence", id, start); return false; } ResourceManager proxy = customerProxies.checkOut(); boolean result = proxy.checkCustomerExistence(id, customerId); customerProxies.checkIn(proxy); - log("checkCustomerExistence", id, start); return result; } @@ -904,9 +836,4 @@ private ArrayList addBillTotal(ArrayList bill) { return bill; } - - private void log(String method, int transactionId, long start) { - long end = System.nanoTime(); - System.out.println("[PERF] " + method + " " + transactionId + ": " + (int) ((end - start) / 1000) + "ms"); - } } diff --git a/ws/src/middleware/mw_handler.xml b/ws/src/middleware/mw_handler.xml new file mode 100644 index 0000000..e2a0474 --- /dev/null +++ b/ws/src/middleware/mw_handler.xml @@ -0,0 +1,9 @@ + + + + + middleware.MwHandler + + + + \ No newline at end of file diff --git a/ws/src/server/PerfHandler.java b/ws/src/server/PerfHandler.java new file mode 100644 index 0000000..002cb7c --- /dev/null +++ b/ws/src/server/PerfHandler.java @@ -0,0 +1,100 @@ +package server; + +import java.util.Set; + +import javax.xml.namespace.QName; +import javax.xml.soap.SOAPElement; +import javax.xml.soap.SOAPMessage; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.soap.SOAPHandler; +import javax.xml.ws.handler.soap.SOAPMessageContext; + +/** + * Handler whose job is to output performance information on each method call. + */ +public class PerfHandler implements SOAPHandler { + + private static final String TIME_KEY = "perf_time"; + private static final String NAME_KEY = "method_name"; + private static final String TXN_ID_KEY = "txn_id"; + private static final Object DUMMY_TXN_ID = new Object(); + private static final Object NO_TXN_ID = new Object(); + + public boolean handleMessage(SOAPMessageContext mc) { + Boolean outbound = (Boolean) mc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); + + SOAPMessage msg = mc.getMessage(); + try { + SOAPElement req = (SOAPElement) msg.getSOAPBody().getFirstChild(); + if (!outbound) { + // Add some information to the message context for later retrieval + + mc.put(TIME_KEY, System.nanoTime()); // Current time + + if (!mc.containsKey(NAME_KEY)) + mc.put(NAME_KEY, getMethodName(req)); + + if (!mc.containsKey(TXN_ID_KEY)) + mc.put(TXN_ID_KEY, getTxnId((String) mc.get(NAME_KEY), req)); + } else { + long elapsedUs = (System.nanoTime() - (Long) mc.get(TIME_KEY)) / 1000; + + String method = mc.get(NAME_KEY).toString(); + String txnId; + Object idObj = mc.get(TXN_ID_KEY); + if (idObj == DUMMY_TXN_ID) { + //Dummy: the transaction ID is the returned value + txnId = ((SOAPElement) req.getFirstChild()).getValue(); + } else if (idObj == NO_TXN_ID) { + txnId = ""; + } else { + txnId = (String) idObj; + } + System.out.println("[PERF] " + method + " " + txnId + ": " + elapsedUs + "us"); + } + } catch (Exception e) { + e.printStackTrace(); + return false; + } + + return true; + } + + + protected String getMethodName(SOAPElement req) { + String nodeName = req.getNodeName(); + + // Name of method appears as nc2:xxxx in the XML + return nodeName.substring(nodeName.indexOf(':') + 1); + } + + protected Object getTxnId(String methodName, SOAPElement req) { + if (methodName.equals("start")) { + // The real txn id will appear at the output side + return DUMMY_TXN_ID; + } else if (methodName.equals("shutdown")) { + // No txn id for shutdown + return NO_TXN_ID; + } else { + // By convention, txn id is always the first parameter. + SOAPElement id = (SOAPElement) req.getFirstChild(); + return id.getValue(); + } + } + + + /* We don't really care about those methods over here */ + + public void close(MessageContext mc) { + + } + + public Set getHeaders() { + return null; + } + + public boolean handleFault(SOAPMessageContext mc) { + return true; + } + +} diff --git a/ws/src/server/ResourceManagerImpl.java b/ws/src/server/ResourceManagerImpl.java index df6c534..425ef6c 100644 --- a/ws/src/server/ResourceManagerImpl.java +++ b/ws/src/server/ResourceManagerImpl.java @@ -6,9 +6,12 @@ package server; import java.util.*; + +import javax.jws.HandlerChain; import javax.jws.WebService; @WebService(endpointInterface = "server.ws.ResourceManager") +@HandlerChain(file="rm_handler.xml") public class ResourceManagerImpl implements server.ws.ResourceManager { protected final Object bidon = new Object(); @@ -60,9 +63,7 @@ protected void removeData(int id, String key) { // Abort a transaction. public boolean abort(int id) { synchronized(bidon) { - long start = System.nanoTime(); _temporaryOperations.remove(id); - log("abort", id, start); return true; } } @@ -70,13 +71,11 @@ public boolean abort(int id) { // Commit a transaction. public boolean commit(int id) { synchronized(bidon) { - long start = System.nanoTime(); LinkedList operations = _temporaryOperations.get(id); if (operations == null) { Trace.info("No transactions were done: nothing to commit."); - log("commit", id, start); return true; } @@ -98,7 +97,6 @@ public boolean commit(int id) { } _temporaryOperations.remove(id); - log("commit", id, start); return true; } } @@ -217,7 +215,6 @@ protected boolean reserveItem(int id, int customerId, public boolean addFlight(int id, int flightNumber, int numSeats, int flightPrice) { - long start = System.nanoTime(); Trace.info("RM::addFlight(" + id + ", " + flightNumber + ", $" + flightPrice + ", " + numSeats + ") called."); @@ -248,32 +245,25 @@ public boolean addFlight(int id, int flightNumber, + "seats = " + curObj.getCount() + ", price = $" + flightPrice); } - log("addFlight", id, start); return(true); } public boolean deleteFlight(int id, int flightNumber) { - long start = System.nanoTime(); boolean isDeleted = deleteItem(id, Flight.getKey(flightNumber)); - log("deleteFlight", id, start); return isDeleted; } // Returns the number of empty seats on this flight. public int queryFlight(int id, int flightNumber) { - long start = System.nanoTime(); int emptySeats = queryNum(id, Flight.getKey(flightNumber)); - log("queryFlight", id, start); return emptySeats; } // Returns price of this flight. public int queryFlightPrice(int id, int flightNumber) { - long start = System.nanoTime(); int price = queryPrice(id, Flight.getKey(flightNumber)); - log("queryFlightPrice", id, start); return price; } @@ -321,7 +311,6 @@ public boolean freeFlightReservation(int id, int flightNumber) { // its current price. public boolean addCars(int id, String location, int numCars, int carPrice) { - long start = System.nanoTime(); Trace.info("RM::addCars(" + id + ", " + location + ", " + numCars + ", $" + carPrice + ") called."); Car curObj = (Car) readData(id, Car.getKey(location)); @@ -342,34 +331,27 @@ public boolean addCars(int id, String location, int numCars, int carPrice) { + numCars + ", $" + carPrice + ") OK: " + "cars = " + curObj.getCount() + ", price = $" + carPrice); } - log("addCars", id, start); return(true); } // Delete cars from a location. public boolean deleteCars(int id, String location) { - long start = System.nanoTime(); boolean isDeleted = deleteItem(id, Car.getKey(location)); - log("deleteCars", id, start); return isDeleted; } // Returns the number of cars available at a location. public int queryCars(int id, String location) { - long start = System.nanoTime(); int cars = queryNum(id, Car.getKey(location)); - log("queryCars", id, start); return cars; } // Returns price of cars at this location. public int queryCarsPrice(int id, String location) { - long start = System.nanoTime(); int price = queryPrice(id, Car.getKey(location)); - log("queryCarsPrice", id, start); return price; } @@ -381,7 +363,6 @@ public int queryCarsPrice(int id, String location) { // its current price. public boolean addRooms(int id, String location, int numRooms, int roomPrice) { - long start = System.nanoTime(); Trace.info("RM::addRooms(" + id + ", " + location + ", " + numRooms + ", $" + roomPrice + ") called."); Room curObj = (Room) readData(id, Room.getKey(location)); @@ -402,34 +383,27 @@ public boolean addRooms(int id, String location, int numRooms, int roomPrice) { + numRooms + ", $" + roomPrice + ") OK: " + "rooms = " + curObj.getCount() + ", price = $" + roomPrice); } - log("addRooms", id, start); return(true); } // Delete rooms from a location. public boolean deleteRooms(int id, String location) { - long start = System.nanoTime(); boolean isDeleted = deleteItem(id, Room.getKey(location)); - log("deleteRooms", id, start); return isDeleted; } // Returns the number of rooms available at a location. public int queryRooms(int id, String location) { - long start = System.nanoTime(); int rooms = queryNum(id, Room.getKey(location)); - log("queryRooms", id, start); return rooms; } // Returns room price at this location. public int queryRoomsPrice(int id, String location) { - long start = System.nanoTime(); int price = queryPrice(id, Room.getKey(location)); - log("queryRoomsPrice", id, start); return price; } @@ -438,7 +412,6 @@ public int queryRoomsPrice(int id, String location) { public int newCustomer(int id) { - long start = System.nanoTime(); Trace.info("INFO: RM::newCustomer(" + id + ") called."); // Generate a globally unique Id for the new customer. @@ -448,14 +421,12 @@ public int newCustomer(int id) { Customer cust = new Customer(customerId); writeData(id, cust.getKey(), cust); Trace.info("RM::newCustomer(" + id + ") OK: " + customerId); - log("newCustomer", id, start); return customerId; } // This method makes testing easier. public boolean newCustomerId(int id, int customerId) { - long start = System.nanoTime(); Trace.info("INFO: RM::newCustomer(" + id + ", " + customerId + ") called."); // There are no sync issues here. If there was no customer but one @@ -466,12 +437,10 @@ public boolean newCustomerId(int id, int customerId) { cust = new Customer(customerId); writeData(id, cust.getKey(), cust); Trace.info("INFO: RM::newCustomer(" + id + ", " + customerId + ") OK."); - log("newCustomerId", id, start); return true; } else { Trace.info("INFO: RM::newCustomer(" + id + ", " + customerId + ") failed: customer already exists."); - log("newCustomerId", id, start); return false; } } @@ -479,13 +448,11 @@ public boolean newCustomerId(int id, int customerId) { // Delete customer from the database. public boolean deleteCustomer(int id, int customerId) { - long start = System.nanoTime(); Trace.info("RM::deleteCustomer(" + id + ", " + customerId + ") called."); Customer cust = (Customer) readData(id, Customer.getKey(customerId)); if (cust == null) { Trace.warn("RM::deleteCustomer(" + id + ", " + customerId + ") failed: customer doesn't exist."); - log("deleteCustomer", id, start); return false; } else { // Increase the reserved numbers of all reservable items that @@ -509,7 +476,6 @@ public boolean deleteCustomer(int id, int customerId) { // Remove the customer from the storage. removeData(id, cust.getKey()); Trace.info("RM::deleteCustomer(" + id + ", " + customerId + ") OK."); - log("deleteCustomer", id, start); return true; } } @@ -518,18 +484,15 @@ public boolean deleteCustomer(int id, int customerId) { // Returns null if the customer doesn't exist. // Returns empty RMHashtable if customer exists but has no reservations. public RMHashtable getCustomerReservations(int id, int customerId) { - long start = System.nanoTime(); Trace.info("RM::getCustomerReservations(" + id + ", " + customerId + ") called."); Customer cust = (Customer) readData(id, Customer.getKey(customerId)); if (cust == null) { Trace.info("RM::getCustomerReservations(" + id + ", " + customerId + ") failed: customer doesn't exist."); - log("getCustomerReservations", id, start); return null; } else { RMHashtable reservations = cust.getReservations(); - log("getCustomerReservations", id, start); return reservations; } } @@ -537,20 +500,17 @@ public RMHashtable getCustomerReservations(int id, int customerId) { // Return a bill. public String queryCustomerInfo(int id, int customerId) { - long start = System.nanoTime(); Trace.info("RM::queryCustomerInfo(" + id + ", " + customerId + ") called."); Customer cust = (Customer) readData(id, Customer.getKey(customerId)); if (cust == null) { Trace.warn("RM::queryCustomerInfo(" + id + ", " + customerId + ") failed: customer doesn't exist."); // Returning an empty bill means that the customer doesn't exist. - log("queryCustomerInfo", id, start); return ""; } else { String s = cust.printBill(); Trace.info("RM::queryCustomerInfo(" + id + ", " + customerId + "): \n"); System.out.println(s); - log("queryCustomerInfo", id, start); return s; } } @@ -558,28 +518,22 @@ public String queryCustomerInfo(int id, int customerId) { // Add flight reservation to this customer. public boolean reserveFlight(int id, int customerId, int flightNumber) { - long start = System.nanoTime(); boolean isReserved = reserveItem(id, customerId, Flight.getKey(flightNumber), String.valueOf(flightNumber)); - log("reserveFlight", id, start); return isReserved; } // Add car reservation to this customer. public boolean reserveCar(int id, int customerId, String location) { - long start = System.nanoTime(); boolean isReserved = reserveItem(id, customerId, Car.getKey(location), location); - log("reserveCar", id, start); return isReserved; } // Add room reservation to this customer. public boolean reserveRoom(int id, int customerId, String location) { - long start = System.nanoTime(); boolean isReserved = reserveItem(id, customerId, Room.getKey(location), location); - log("reserveRoom", id, start); return isReserved; } @@ -588,8 +542,6 @@ public boolean reserveRoom(int id, int customerId, String location) { public boolean reserveItinerary(int id, int customerId, Vector flightNumbers, String location, boolean car, boolean room) { - long start = System.nanoTime(); - log("reserveItinerary", id, start); return false; } @@ -599,13 +551,10 @@ public int start() { } public boolean checkCustomerExistence(int id, int customerId) { - long start = System.nanoTime(); Trace.info("RM::checkCustomerExistence(" + id + ", " + customerId + ") called."); if (readData(id, Customer.getKey(customerId)) == null) { - log("checkCustomerExistence", id, start); return false; } - log("checkCustomerExistence", id, start); return true; } @@ -632,8 +581,4 @@ private void addTemporaryOperation(int id, String key, RMItem value, ClientOpera _temporaryOperations.put(id, operations); } - private void log(String method, int id, long start) { - long end = System.nanoTime(); - System.out.println("[PERF] " + method + " " + id + ": " + (int) ((end - start) / 1000) + "ms"); - } } diff --git a/ws/src/server/rm_handler.xml b/ws/src/server/rm_handler.xml new file mode 100644 index 0000000..e013a33 --- /dev/null +++ b/ws/src/server/rm_handler.xml @@ -0,0 +1,9 @@ + + + + + server.PerfHandler + + + + \ No newline at end of file