jQuery in Action, 2nd edition*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Really need help with this one!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Really need help with this one!!!" Watch "Really need help with this one!!!" New topic
Author

Really need help with this one!!!

Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
Using RMI the Data class fails when performing a seek for a record given a record number via getRecord(). My setup is this: created an interface - DataInterface which has all public methods for the Data class. Implement DataInterface in Data class. Created stub on Data class. Stub resides in client and server directories. Initial connection is fine and I even get the initial record description (field names). but when I attempt to retrieve record n via getRecord (or any other data retrieval function) the process fails. It appears that the RandomAccess file pointer ==null at that point. Why? I assume its because RandomAccessFile is not Serialized. How can I get around this? I'm sooo close to completion and have tried this several different ways. The local connection is fine. Please help!
[ January 16, 2002: Message edited by: Gregory Garrison ]
[ January 16, 2002: Message edited by: Gregory Garrison ]
[ January 16, 2002: Message edited by: Gregory Garrison ]
[ January 16, 2002: Message edited by: Gregory Garrison ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

getRecordNumber is a method in the DataInfo class which is given to you as Serializable.
I think you might mean the getRecord method of the Data Class.
So a call to getRecordNumber would not be an RMI call, if you call getRecord with a record Number as the parameter, it should return a DataInfo class to your client, which is Serialized, and then you can call getRecordNumber on that class, but that wouldn't happen because you would need to know the record number beforehand.
Hope that helps, or maybe to help clarify to you what your question is.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
Thanks for pointing that out. I've fixed the question. The problem is that I cannot get the data to return a DataInfo object. The process returns an exception because the seek method cannot perform a seek because the RandomAccessFile pointer is null. To clarify, the server returns a Data object to the client (with data) when first created. This new Data object is then used the same way as if it was the local Data object connection. so, a subsequent call to this networked Data object fails because the RandomAccessFile becomes null for some reason. It really is quite a simple configuration but I don't quite understand what's wrong. Is my setup correct, eg. creating a common interface in order to use either local or networked Data.class? Should I be looking at another approach?
I really appreaciate your response.
[ January 16, 2002: Message edited by: Gregory Garrison ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

No the setup seems fine. But are you sure you are passing the db.db file to the constructor of the Data class? using the Data(String dbName) constructor and not the Date(String dbName, FieldInfo[] fields) constructor. And you also fixed the deprecated methods?
I can't really figure it out.
Mark
Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
No. I don't pass the path. I added a default constructor, create an object with this, utilize a connect(path) function to connect to the db.db. I tried your suggestion, passing a path to the constructor of Data upon startup of the server but I recieve and error message stating that RandomAccessFile is not serialized, when passing back from the server to client. If I create a Data object using a path from within the rmi server how can I get around the serialized problem?
much thanks.
Enrico Mannarino
Ranch Hand

Joined: Dec 14, 2001
Posts: 133
Hi Gregory,
I also use an interface like you describe and it works fine with me with RMI. How do create your Data object in the server? Are you're sure that it is the RandomAccessFile that becomes null and not you're Data object?
Just a thought, want you to look in other direction. Because if it work's in local mode (single instance) it can be a multi instance problem.
Enrico Mannarino
Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
As stated above, I would like to instantiate the Data object with a path but I recieve the "RandomAccessFile not serialized" error message and it fails. How did you handle this?
Thanks again. This is just a real barrier for me. As a side note, I'm building on SunOS 8. don't know if this means anything. What OS are you building on?
I have also tried an approach where the Data object is a variable within the server and I call public server variables which coincide with the public methods of the Data class. Then call the Data object variable from these methods. This get's around having to pass the Data object to the client and avoids the "RandomAccessFile not serialized" error but had problems with RandomAccessFile not releasing db.db from within rmi server. So I would like to take the correct and direct approach of accessing a Data object directly.
[ January 16, 2002: Message edited by: Gregory Garrison ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

OK, now it's getting closer. I had the same thing when I started out. The problem is your are trying to pass the File back to the client through the wire. You don't need to do this. That object needs to stay on the server.
It is through your interface that you will call methods that get passed up to the server to make the calls on the data for you.
Mark
Enrico Mannarino
Ranch Hand

Joined: Dec 14, 2001
Posts: 133
Hi Gregory,
Really strange! I'm building on Win2000. No problem.
I've just started this assignment, downloaded it Tuesday. For the moment I've only one Server file which start the server and implements the DataInterface.
In my Server constructor I create a new instance of Data. I have a member attribute that keep the reference. And every method just pass the incoming request to the Data reference Ex:
public void lock(int record) throws IOException, RemoteException{
data.lock(record);
}
public DataInfo getRecord(int recNum) throws DatabaseException, RemoteException{
return data.getRecord(recNum);
}
It's really simple server but I works fine (for the moment).
Enrico Mannrino
Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
Mark - you're the greatest. You're right. I will name my first child after you (better hope it's a boy!). Stupid mistake on my part. Didn't have a clear head. I also needed the import java.rmi.* and java.rmi.server.* in my client for this to work.
And thank you too Enrico.
One other question I would like to bother you guys with is your approach to switching between server and local. Right now the above approach works by starting the server and registering the db with an actual path. But during user interaction the user will be switching between local and remote and should be allowed to enter the path for - each? My basic question here is how do you provide switching to a db.db in a different location on the server side?
Thanks Greg.
[ January 16, 2002: Message edited by: Gregory Garrison ]
[ January 16, 2002: Message edited by: Gregory Garrison ]
Enrico Mannarino
Ranch Hand

Joined: Dec 14, 2001
Posts: 133
Hi Gregory,
Great news. I'm glad that Mark found the problem, because who wants a son named Enrico?
I'll come back to you tomorrow about your last question. It's quite late in Europe.
Enrico Mannrino
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

What I did, but not necessarily the way you have to go, and alot of people did it other ways. First the client is the only place you say local and remote. I also did not allow the client to switch back and forth. When you started the client you could pass an ip address of the server. The client would see if there is anything in the main(args[]) arg[] array. If there was I knew that they passes an IP address, which meant they wanted to be in Remote mode. If nothing is passed then it is local. Remember in local mode there is no server running. It just creates an instance of the LocalData class inside the client code.
I actually had a DataAccessFactory, that would pass the args[] array to the factory, and it would return a DataAccessFacade. Inside the Facade would be a reference to the LocalDataAccess or RemoteDataAccess class based on the ars[] value.
Mark
Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
Thanks again. What I did was bootstrap the engine into the rmiregistry. This means, upon starting the engine it registers itself with the registry. Within the engine object is a connect and disconnect method which allows me to register a Data object by passing the appropriate path. So, after obtaining the registered engine object I can use connect/disconnect to register a Data object. This works quite well as I can move between local and remote and between different db.db's in each. Now I just need to lock/unlock and I'm there. Appreciate all your support. Hail JavaRanch!
Any suggestions on the essay. Is it technical or will they ask questions on just how you built the app?
[ January 16, 2002: Message edited by: Gregory Garrison ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Don't even think or worry about the essay. It is nothing, a piece of cake that takes 30 minutes at most. Just a way to prove that you did your work. If you did, then it will be just like posting at Javaranch.
Mark
p.s. I'd just make sure you can name 3 advantages and disadvantages between RMI and Object Serialization. You will find many posts here with those answers.
Gregory Garrison
Ranch Hand

Joined: Oct 05, 2001
Posts: 107
Thanks Mark.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Really need help with this one!!!