You just pack the ID of the library you want
the name for, and then unpack the name by taking all characters in it, except for the first:
def self.get_library_name(id)
tid = @@current_trans_id += 1
Connection.send(tid.to_s, OP_GET_LIBRARY_NAME + pack_int(id))
msg = sleep_until(tid)
Transactions.delete(tid)
msg[1..-1]
end
Adding a new book description takes some more code, but not much. Your helper
methods easily handle the complication of sending an array of strings:
def self.add_book_description(desc)
tid = @@current_trans_id += 1
Connection.send(tid.to_s, OP_ADD_BOOK_DESC +
s(desc.name) + a_s(desc.authors) + s(desc.isbn))
msg = sleep_until(tid)
Transactions.delete(tid)
unpack_int msg
end
Removing a book description looks like removing a library, and you should probably
refactor them into each other later on:
def self.remove_book_description(id)
tid = @@current_trans_id += 1
Connection.send(tid.to_s, OP_REM_BOOK_DESC + pack_int(id))
end
Here??™s how to add a new instance of a book:
def self.add_book_instance(libid, descid)
tid = @@current_trans_id += 1
Connection.send(tid.to_s, OP_ADD_BOOK_INST +
pack_int(libid) + pack_int(descid))
msg = sleep_until(tid)
Transactions.delete(tid)
unpack_int msg
end
CHAPTER 13 ?– JRUBY AND MESSAGE-ORIENTED SYSTEMS 244
Removing, lending, and returning an instance are all the same:
def self.remove_book_instance(id)
tid = @@current_trans_id += 1
Connection.send(tid.to_s, OP_REM_BOOK_INST + pack_int(id))
end
def self.
Pages:
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366