next time I'm in Brussels I will invite you to some beers
Vlad, we are 3 already ! Let's say that when we are 20 we pay the flight ticket Sydney-Brussels and back for Andrew to get those beers with us.
Is FILE_NAME a constant in your application?
How do you set FILE_NAME?
I didn't understand your idea:
You call DataSchema.getInstance(), and after that you start reading a header?
"I'm not back." - Bill Harding, Twister
[Ulrich] in Data-Class I haven't synchronized RandomAccessFile, I haven't it also in DataSchema, because i'm afraid of dead-lock, the synchronization is reduced to the mutex, which is a static private HashMap in Data-Class. But because the RAF action will be done from the same thread which is responsable for the elaborating of the Data-Class (I will have one Data-instance per client through Connection Factory), I think I'm Fine, or I'am not right?
[Philippe] Vlad, we are 3 already ! Let's say that when we are 20 we pay the flight ticket Sydney-Brussels and back for Andrew to get those beers with us.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I think I understand what Vlad is getting at. In my mind, the DataSchema class could verify the cookie and read the schema information. So when an instance of the Data class connects, that work is already done.
public DBConnectionFactoryImpl(String fileName)
throws IOException, RemoteException {
super();
//create Data object
db = new DBAdapterLocal(fileName);
logger.log(Level.FINER, "Remote connection factory has been started.");
}
...
public DBAdapterRemote create()
throws IOException, RemoteException {
// create Remote Data object.
// All remote Data objects contain a shared instance
// of Data.
DBAdapterRemoteImpl dbRemote = new DBAdapterRemoteImpl(db);
return dbRemote;
}
Oh, sure. And leave me stranded here in Arizona. See if I help you guys any more
I would suggest you to come next carneval to Cologne
I leave in F/M. So it is about 190km from Cologne. My wife is about 1,5 year in Colognya in the CRM projects. She want me every year to come there and make fun together with her colleges, but I don't have much clue about Siebel and CRM (and they have not much respect for Java) and I was afraid to there are But now I can take a challenge !
Oh, sure. And leave me stranded here in Arizona. See if I help you guys any more.
I think I understand what Vlad is getting at. In my mind, the DataSchema class could verify the cookie and read the schema information. So when an instance of the Data class connects, that work is already done.
In this DataSchema has to have (to my opinion) not getInstance(), but
getInstance(String fileName); The whole header will be read in DataSchema.
That is the way Jim has dne (not a singletone, but reading header inside DataSchema.
It would allow me to have many DataAdapter instances of the server. The thing what I extremely don't like in a Singletone is that only lazy singletone initialization is possible in my design. It means that if any problem occury while connection to the file at first time, we will be able to see the problem while the first client connects to the server.
SCJP (1.4), SCWCD, SCJD
So Andrew's suggest would consist in reading the MagicCookie only once, while Vlad suggests to check the MagicC. each time a client connects to DataSchema by passing the FileName as argument. Thus the work will be done by DataSchema.
Am I right?
I had problems concerning catching IOExceptions, I can avoid them by creating a static{}-block catching IOException and throwing RuntimeException.
But in your case, the problem is that you don't want to have direct access from Data to the File but only get the Filename through arguments. is that right? If yes, why don't you want to have direct access from Data-Class?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP (1.4), SCWCD, SCJD
But why wait till then?
You could have a method that just verifies the data file (checks the magic cookie, reads the schema, and checks that the file length is correct based on the schema). Have the server call this method as soon as it knows the file name.
In the remote server case i am not sure if the client has to check/do anything about the magic cookie again?
In the remote server case, do you use any of the data schema information on the clinet side? Like number of columns, name of the columns, length of each column
I�m just wondering why you are synchronizing on reservedRecords. Is it because you do not lock the record before you read it i.e. you use the above mechanism rather that a �lock � read � unlock� mechanism? Also, if you don�t lock the record do you not check that the record is not in reservedRecords (another thread may be updating it)?
quote:
--------------------------------------------------------------------------------
In the remote server case, do you use any of the data schema information on the clinet side? Like number of columns, name of the columns, length of each column
--------------------------------------------------------------------------------
Yeap. I use all the information described by on the client to make changes in database structure transparent for the client.
I don't understand why you don't have direct access from your Server to DataSchema.
Do you mean I could directly call invoke:
return DataSchema.getInstance(fileName) inside DBAdapter?
You could have a method that just verifies the data file (checks the magic cookie, reads the schema, and checks that the file length is correct based on the schema).
there won't be a problem to make a call from your Adapter-Class to DataSchema, don't you think so?
my server (DBConnectionFactory) shound't actually work with Data instance, since I have DBAdapter class, the Adapter class must be entry point to the database for the Factory
[to Andrew] Is it what you mean?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I think this the direction what Andrew means with:
"and checks that the file length is correct based on the schema", or am I mistaken?
Here my questions:
1. Concerning the expression: "allRecLen % getRecordLength()) != 0", I suppose you Gurus will critize it because it isn't very elegant, or?
2. "throw new IOException("the db-file might be corrupted")"
When the length of that part of the file which is reserved for storing the Records can't be divided through the number of Records, I have to suppose that the db-file is corrupted and in that case the IOException is the appropriate Exception.
And here my second question:
1. Do you think the IllegalArgumentException is appropriate?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I just want to check that the adapter class is only necessary for the factory / server. Or, to put it another way, the Data class does provide all the functionality required by the interface Sun provided.
Personally I would have the invariant() method do a little more than just check the cookie
1 + 1 + 1 + 1 = 2 ?
we can't get all perfectly
I still have only one shared instance Data and thefore DataSchema for all connections (Mutition).
I will do Data a lazy singletone (Data.getInstance(String fileName);
And will create an instance of DBAdapter in C-tor of factory to be able to see problems at the start of the server.
Sorry, I regret my stupid comment
What is the difference between Mutition and Singleton?
Because you have only one instance of Data, you have accordingly only one instance of DataSchema?
Does it mean that now you will create one DBAdapter anyway at the start-up of the server? So through the constructor of DBAdapter the Data-Singleton will be created also, the integrity of the db-file can now be checked.
Have you also changed the create-method you have posted above?
I mean, have you created a second no-arg constructor?
"I'm not back." - Bill Harding, Twister
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|