Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added exception

...

Code Block
bgColor#ccccff
public boolean sendPage(Socket socket, String pageName) { // No synchronization
  Page targetPage = getPage(pageName); 

  if(targetPage == null)
    return FAILURE;

  return deliverPage(socket, targetPage);
}

private synchronized Page getPage(String pageName) { // Requires synchronization
  Page targetPage = null;

  for(Page p : pageBuff) {
    if(p.getName().equals(pageName)) {
      targetPage = p;
    }
  }
  return targetPage;
}

public boolean deliverPage(Socket socket, Page page){
  try{
    // Get the output stream to write the Page to
    ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());

    // Send the Page to the client
    out.writeObject(page);

  } catch(IOException io){
    // If recovery is not possible return FAILURE
    return FAILURE;    
  } finally {
    out.flush();
    out.close();
  }  
  return SUCCESS;
}

Exceptions

EX1: Classes that are compliant with the guideline CON24-J. Ensure that threads and tasks performing blocking operations can be terminated in that they provide an appropriate termination mechanism to callers, are allowed to violate this guideline.

EX2CON20:EX1: A method that requires multiple locks may hold several locks while waiting for the remaining locks to be available. This constitutes a valid exception, though care must be taken to avoid deadlock. See CON12-J. Avoid deadlock by requesting and releasing locks in the same order for more information.

...