Java Reference
In-Depth Information
/**
* Constructor takes in a hostname of the server to connect.
*
* @param hostname The hostname to connect to.
* @throws NumberFormatException if portNumber is not valid.
*/
public DvdSocketClient(String hostname, String portNumber)
throws UnknownHostException, IOException {
ip = hostname;
this.port = Integer.parseInt(portNumber);
this.initialize();
}
/**
* Adds a DVD to the database or inventory.
*
* @param dvd The DVD item to add to inventory.
* @return A boolean value that indicates the success/failure of the
* add operation.
* @throws IOException Indicates there is a problem accessing the data.
*/
public boolean addDVD(DVD dvd) throws IOException {
DvdCommand cmdObj = new DvdCommand(SocketCommand.ADD, dvd);
return getResultFor(cmdObj).getBoolean();
}
/**
* Gets a <code>DVD</code> from the system using a UPC.
*
* @param upc The UPC of the DVD you want to view.
* @return A DVD that matches the supplied UPC.
*
* @throws IOException Indicates there is a problem accessing the data.
*/
public DVD getDVD(String upc) throws IOException {
DVD dvd = new DVD();
dvd.setUPC(upc);
DvdCommand cmdObj = new DvdCommand(SocketCommand.GET_DVD, dvd);
return getResultFor(cmdObj).getDVD();
}
/**
* Attempts to rent the DVD matching the provided UPC.
*
* @param upc is the UPC of the DVD you want to rent.
* @return true if the DVD was rented. false if it cannot be rented.
Search WWH ::




Custom Search