{"id":850,"date":"2010-04-08T11:36:28","date_gmt":"2010-04-08T10:36:28","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=850"},"modified":"2010-04-08T11:36:28","modified_gmt":"2010-04-08T10:36:28","slug":"rmi-implementation-of-the-library-book","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/04\/08\/rmi-implementation-of-the-library-book\/","title":{"rendered":"RMI &#8211; implementation of the library book"},"content":{"rendered":"<p>As from previous post, the <a href=\"http:\/\/www.codingfriends.com\/index.php\/2010\/04\/08\/rmi-interface\/\">Borrowable interface<\/a>, for the RMI (Remote Method Invocation), this is the part of the Book class, this is what is called from the Library as such to see if a book has been taken out or not.<\/p>\n<pre lang=\"java\">\r\nimport java.util.*;\r\nimport java.rmi.*;\r\nimport java.rmi.server.*;\r\n\r\n\/\/ UnicaseRemoteObject = remote object classes need to implement the related\r\n\/\/ remote interface\r\npublic class Book extends UnicastRemoteObject implements Borrowable {\r\n\tprivate Date borrowDate;\r\n\tprivate Date returnDate;\r\n\tprivate String borrowerID;\r\n\tprivate String title;\r\n\tprivate boolean checkedOut = false;\r\n\t\r\n\t\/\/ create book.\r\n\tpublic Book (String bookName) throws RemoteException\r\n\t{\r\n\t\ttitle = bookName;\r\n\t}\r\n\t\r\n\t\/\/ is the book already checked out ?\r\n\tpublic boolean isCheckedOut() throws RemoteException\r\n\t{\r\n\t\treturn checkedOut;\r\n\t}\r\n\t\r\n\t\/\/ if the book is checked out, return the library card number + date it was taken out on\r\n\tpublic String checkedOutCardNumber() throws RemoteException\r\n\t{\r\n\t\tString returnID = null;\r\n\t\tif (isCheckedOut())\r\n\t\t{\r\n\t\t\treturnID = borrowerID + \" Date taken out on \"+ borrowDate.toString();\r\n\t\t}\r\n\t\treturn returnID;\r\n\t}\r\n\t\r\n\tpublic boolean checkOut(String cardNumber, Date d ) throws RemoteException\r\n\t{\r\n\t\t\/\/ do not check out the book if already checked out!\r\n\t\tif (isCheckedOut())\r\n\t\t\treturn false;\r\n\t\tborrowerID = cardNumber;\r\n\t\tborrowDate = d;\r\n\t\tcheckedOut = true;\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic boolean checkIn(String cardNumber, Date d) throws RemoteException\r\n\t{\r\n\t\t\/\/ if it is checked out, check the book in.\r\n\t\tif (isCheckedOut())\r\n\t\t{\r\n\t\t\tborrowerID = cardNumber;\r\n\t\t\treturnDate = d;\r\n\t\t\tcheckedOut = false;\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n}\r\n<\/pre>\n<p>if you save that as Book.java, next comes the fun part the actual Library server as such.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As from previous post, the Borrowable interface, for the RMI (Remote Method Invocation), this is the part of the Book class, this is what is called from the Library as such to see if a book has been taken out or not. import java.util.*; import java.rmi.*; import java.rmi.server.*; \/\/ UnicaseRemoteObject = remote object classes need &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/04\/08\/rmi-implementation-of-the-library-book\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">RMI &#8211; implementation of the library book<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[173,172],"class_list":["post-850","post","type-post","status-publish","format-standard","hentry","category-java","tag-book","tag-rmi"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/850","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=850"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/850\/revisions"}],"predecessor-version":[{"id":851,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/850\/revisions\/851"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}