Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Anthony Bull

+ Follow
since Nov 08, 2004
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anthony Bull

There is no need for your client to be calling lock or unlock. A call from the client to update a record should be atomic, not islocked->lock->update->unlock. Your server should be handling the details of locking. This is additionally good because it is way simpler to code.

Imagine it in the real world - you have a client that says - update this instance, and the server handles starting a transaction, locking the record, running the SQL then committing the transaction. You would never require your client program to know about transactions.

Its a pretty poor design to assume your client will handle locking/unlocking a record, because you can never guarantee that a client will implement it correctly. E.g. eBay would not rely on people writing third party clients to correctly handle locking their database!
I went with the same approach as you. An adapter should NOT be implementing business rules, as it is simply adapting your service/business model to be accessible over a network. Don't listen to your colleague, you are on the right track! Sounds like your colleague hasn't done the certification yet.
The assignment text clearly states the public interface should be completely javadoc'ed.

In the real world you wouldn't javadoc your private interface as it provides no value to someone using the code, so why do it here? Simple java comments are fine above a private method.
Hi, I am currently doing the UrlyBird developer project also, and have nearly completed it (user guide, choices, javadoc and unit testing to go). Here's some of my thoughts on your points.

Major Questions:

1. I have assumed the same thing, that automated tests get run against the Data class. From what I've read, these tests are run before your actual programs are even tried out. For this reason, the DBMain interface should be all thats implemented for the public interface of your Data class, nothing more. For your testing you should write similar unit test cases to exercise your (that are separate from your server code).

2. Only lock the db via the lock/unlock/isLocked methods. Putting locking inside the CRUD methods turns it from being an interface to the database to having business behaviour. The reasoning behind this is that the javadoc for these CRUD methods does not mention locking, and it doesnt allow people using the code to choose the locking strategy/isolation levels to use for a database.

3. No, the client app only allows changing the owner field of a row. Creation and deletion is not required through the client. Creation and Deletion need to be only implemented in the Data class. I assume that the marker will use an automated program to populate the database with data to use when they are testing your client, using the methods in your Data class.

4. For RMIRegistry it is easier to just get your startup code for the server to look for a registry and start one up if none is running. Then check that a URLyBird server is not in the registry, and if so bind your server instance to the registry. This is only a few lines of code to do. It is best to make things as easy as possible for the marker - think of them as a customer using your app - it should be simple to run.

5. Yes. I've used these as identifiers for a room in the database, as they are unique. Its probably up to you whether you use them or not. I assumed that there could be more than one room at the same hotel available through the application, so there was no other way of uniquely identifying a record.

6. Not sure what you mean about reserved records. In my implementation, the only deleted records are ones specifically marked as deleted. All data is in the past in my DB, but they are still valid records in the database. They can still be searched for by my client. They just cannot be booked by the client due to the 48 hour rule. In a full, real-world server implementation there would be a background job that deletes these records as they expire.

Minor Questions:

1. I didn't make it a singleton. I have a business model class (BusinessServiceModel) that implements the business rules of the server and talks to the Data class. The Remote service (RMI) impl has an instance of this BusinessServiceModel to service any calls from clients. As there is only ever one instance of a remote server in the registry, there will only ever be one Data instance and one BusinesServiceModel instance, making it a singleton without needing code. The Data instance is kept for the lifetime of the BusinessServiceModel instance. Also to programatically make it a singleton means having extra public methods that aren't on the DBMain interface which isnt a good idea.

2. This is one I struggled on. I originally got it to read the structure and then use those indexes to find what column was what. This required either (a) my Data class to know about the structure of the database rows or (b) my Data class to have extra methods on it for extracting the schema so my BusinessServiceModel could learn the structure. Both these options seemed wrong, especially (a), as it is a database impl, and should never care about what data it is storing. (b) seemed wrong too, as the interface they had provided in DBMain does not allow for this. So the solution is to document this in my choices file, and to hard code my BusinessServiceModel to know that when it gets a String[] record, that index x gives me column x from a row.

Ok, thats about it. Hope it helped - if you have other ideas let me know, I am always keen to alter my design if it makes it better.
I am developing a web-server that allows a client app to download files from the server. I have this working correctly using ServletOutputStream to write the files back to the client.

When using our Java Test Harness and various web-browsers to download the files the performance for a 1.4 meg file is around 2 seconds. However the .NET client (witten by another software company) to do the same thing takes ages to download the file.

I have tracked the performance issue down to the ServletOutputStream.write() method calls - where I am writing 8kb blocks in each time. My question is - how does the ServletOutputStream work? - if the .NET client takes ages to process a given block of bytes, will the ServletOutputStream.write() method call not return (or block), until the bytes have been acknowledged?

Once I know for sure about this, I can then confidentally raise it with the Project Manager as being an issue with the other vendor's .NET code, and not our fault.

Additionally, I am using buffered readers for input, and am writing the entire buffer (8kb) with one write to the ServletOutputStream. 8kb is also the size of the write buffer on the HttpServletResponse. The file is being read using a buffered input reader.
15 years ago
I am using two Jakarta Commons libraries to do this very thing, except I am uploading binary files.

Use the HttpClient library to send HttpServletRequests containing files or whatever, and on your servlet use the FileUpload library to grab the results and save the file to disk.
15 years ago

Originally posted by Lasse Koskela:
No, you can't do that with the <junit> task unless you write your own TestRunner implementation that contacts your application running on Tomcat and sends it a list of class names to execute as JUnit tests.

Effectively, you'd be reinventing Cactus...

Ok, I know how to get my build script to kick my unit testing off on the TomCat server - all I need to know is - can I somehow log the results of the unit tests and then get my build script to generate a report based on those? And also fail or email a failure message based on the results?
15 years ago
Hi, I have a bunch of j-unit tests I have written, half of which have to be run from my TomCat server (integration style tests). In my build script I am deploying my WAR to the TomCat server.

My question is, is it possible to get Ant to run these j-unit tests on the running TomCat server using the <junit> task? I don't want to go down the route of Cactus or something, as the tests that require TomCat running are designed to be full integration tests where the environment is setup as a production environment.


15 years ago