Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Yudiman Kwanmas

+ Follow
since Feb 01, 2009
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 Yudiman Kwanmas

I see, I think now I understand what you mean.

Thanks a lot Kevin.


Thanks Kevin, it becomes clearer now.

But now I am confused with the SecurityException. The spec says that security exception is thrown if the record is locked with a cookie other than lock cookie. It means that in the process method, lock cookie must be compared with a value type long, and both must have same value.

My question is from where the process method can get that value ?

And if I came out with this theoretical approach:

Would the concurrency still work fine? This is my 2nd question.

To Anne Crace
Yes, that's what I did. I created a static hashmap<recNum, cookie>.

To Kevin Florish
I've been trying to digest your answer, but I'm still confused. My main question is how do I associate the cookie to a particular client, if other client is trying to access a particular record number that has already been exist in the static hashmap (means it has been locked)?

By the way of illustration,

1) Client A wants to update record number 1.
2) Client A checks the static hashmap, and apparently record number 1 doesn't exist in the hashmap. It means recNum 1 is free.
3) Client A calls lock method to lock the record. It will add recNum 1 to the hashmap, together with the generated cookie. The lock method also returns the lock cookie as its output.
4) the returned lock cookie will be passed to the method as specified by this method declaration:

Question 1 : Now why do we have to pass the lock cookie into the update method? How the update method should handle the lock cookie inside its method definition?

5) Meanwhile, Client B wants to update record number 1 as well.
6) Client B checks the static hashmap, and find out that the record number is mapped . It means the record number is locked. (At this point, we don't need the lock cookie yet, since we can use hashmap.containsKey(Object key)).
7) Then client B has to determine which client is locking the record with recNum 1. Because if it's client B which is locking the record, then Client B will not need to wait until the record is unlocked. However if other client is locking the record, then I believe the lock cookie comes into use.

Question 2 : How client B knows that the lock cookie belongs to a Client others that Client B (in this case Client A). Based on my illustration, Client B hasn't generated a lock cookie yet. Even if it had,
then how client B store the cookie in its member so it can be compared with the cookie in the hashmap?

ps: using this approach means that in the unlock method, the entry with the associated record number must be removed from the static hashmap to indicate the record is now free.

ps2: from my illustration, I assume that a lock cookie is associated to a particular client. So if there are 5 clients trying to update a record, then 5 cookie values will be generated. Is my assumption correct?
I have been trying to figure out how to use lock cookie to identify a client.

The interface for my project is as following:

From the lock method's definition, I believe that the returned lock cookie is to be used to identify the client that is trying to access the record.

I reckon from the previous posts that some people come out with a hashmap <Long, Long>; , with key = recNum, value = cookie.
This is useful to check whether a record (identified by the record number) is locked or not by checking if the record number is in the hashmap, but it won't tell the record is locked by which client, since the client doesn't has a way to store the lock cookie in its class member (remember! we are not allowed to modify the given interface).

One solution that I know is by implementing a connection factory, so every generated client (in networked mode, it doesn't really matter in stand alone mode) is unique.
However, this will render the lock cookie useless, since I can just create a hashmap <Long, DB>; where the key is the record number & the value is the client itself.

Any ideas people?
I see, then I will do both methods, and but won't provide the gui implementation.
Ok, thanks for the confirmation.
I'm bit confused with the existence of method create & delete. I was wondering why it is defined in the supplied interface.

My spec states that the UI for this assignment must satisfy the following criteria:

* Must use Swing.
* Allow user to search the data of all records. (Therefore, I know the purpose of defining the find & read method in the interface.)
* Must present search result in a JTable.
* Must allow user to book a selected record, updating database accordingly. (update method)

Well, that's it. The spec doesn't mention about, for example, creating a functionality where users can add a new record into the database or deleting an existing record.

The spec, does mention that the UI "should be designed w/ the expectation of future functionality enhancements...".
So, I assume that in the end, I still have to create the implementation for the create and delete method.
However, I think It would look weird if these chunk of codes just laying dormant when the application is running, or maybe I just simply miss the reason why
those methods should be defined.

Any clarifications?
Ups, yep you right. It must be DB2 db = new Data();

Well what I meant by satisfying the spec's requirement is because the spec says "Your data access class must be called "", must be in package called "suncertify.db", and must implement the following interface: public interface DB {...} "

If my class Data only implements DB2, then I'm afraid I would break the requirement because class Data doesn't implement interface DB, even though interface DB2 extends interface DB.
I do aware that my code would look a bit "less elegant" if I used this approach. Also, there is a risk that this might confuse some "junior programmers", but I'll just explain everything in my technical documentation.

Anyway, thanks a lot for the correction.

I see, I almost made a fatal mistake because my app breaks one of the fundamental OOP.

Then, what if I did something like below:

1) I created an interface that extends the DB interface. Let's call it DB2. So "interface DB2 extends DB {...}".

2) DB2 contains the declaration for method "getAllRecords()", and methods already declared in interface DB.

3) Class Data implements both DB and DB2, therefore class Data must implement methods from both interfaces.

4) Then, it would be DB2 db = new DB2();

Would it be acceptable from either the OOP & the spec's point of view?
For me, at least it doesn't break the rule that class Data must implement interface DB.

Thanks a lot for correcting my mistake & Thanks in advance for your help
Hmm...point taken for the search method, but well in my case, this will be "Data db = new Data();" if we run my app using the non-networked mode.

Because the spec only describes that the class Data has to implement the DB interface. But it doesn't mention that we have to use DB to instantiate the class Data.
Regarding Kumaraguru's suggestion, I think the sole purpose of method "public int[] find(String[] criteria) throws RecordNotFoundException" is to implement the search functionality of our application (invoked after the search button in our UI is clicked).

In my case, I decided to create a public method in class Data which implements DB (DBMain in Karnani's project). This method returns a list type "Record" (the value/transfer object in my app).
Well, the drawback is this method is not defined in the DB/DBMain as we are not allowed to change the supplied interface.
Thanks for the reply and the welcome message K. Tsang.

As for your suggestion, It is not necessary for us to explicitly serialize the remote object. The reason is because the remote object, by default implement serializable. So, as long as your remote class
extends either java.rmi.Activable or java.rmi.UniCastRemoteObject, then the return values of all methods declared in the remote class will be serialized when it travels across the wire.
However, my value object does implement Serializable.

For now, I'll dig further to find out whats wrong with my program.

And for your endeavor to finish the RMI implementation, I hope you won't experience the same problem like the one I'm facing at the moment.
Hello everyone,

I have been doing the RMI part for my SCJD certification, and now I realize how challenging the task to implement RMI is

Before I go on telling the problem that I have encountered, I will provide a brief explanation about the structure of my code:

1. My source code contains 2 interfaces, the first one is the DB interface (located in suncertify.db package), and the other one is called DBRemote interface (which is located in suncertify.rmi package).
The DB interface is the supplied interface given as part of the SCJD material, whereas the DBRemote interface is an interface created specifically for implementing the RMI.

If we refer to the sample code from Monkhouse SCJD guide, the DBRemote should extend the java.rmi.Remote & the interface DB. However, in my code, the DBRemote only extends Remote.
Thats because the methods declared in the supplied interface throw neither IOException nor RemoteException, which is required from implementing RMI. Therefore my DBRemote interface throws RemoteException
for every method declared in it & is independent from the DB interface. The DBRemote interface also declare a very important method that the DB interface doesn't declare. This method reads the records stored in the db file
and returns the records in form of a list type Record (defined in For additional information, this method also declared and defined in the class Data in that implements the DB interface.

2. The class DataRemoteImpl in represents the remote object for my app. It implements the DBRemote interface. Obviously, the important method that is defined in the DBRemote, is also declared in the

Now the stage is all set, all I need to do is to make a remote connection request as shown in the code below:

There was no problem when running the server for the app. But, when running the client in network mode, the null pointer exception showed up on the client's command line window.

From line 24 & 35, I concluded that the request for the arraylist which contains the "Records" was performed successfully (partially successfull ) through localhost connection.
But the each element in the arraylist itself was null as indicated by the exception & by the getter methods for each element in a Record as it was called to extract the value to be displayed on the JTable.

I have ensured that the very important method that I mentioned earlier; which is declared in both & returns a correct list of records from the db file. So, I assume
something wrong must have happened when the list is being transfered from the server to the client through localhost.

Now this problem has been robbing my previous time , and I'd like to receive assistance from fellow SCJD-ers.