...
Code Block | ||
---|---|---|
| ||
public boolean sendPage(Socket socket, String pageName) { // No synchronization Page targetPage = getPage(pageName); if (targetPage == null) return false; 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) { ObjectOutputStream out = null; 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 false return false; } finally { if (out != null) { try { out.flush(); out.close(); } catch (IOException e) { // If recovery is not possible return false return false; } } } return true; } |
Exceptions
EX1: Classes that provide an appropriate termination mechanism to callers are allowed to violate this guideline (see CON24-J. Ensure that threads and tasks performing blocking operations can be terminated).
...