• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

magic cookie / lock cookie

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo

I prepare my self for the SCJD (some M.Habibi, some coding , brief trough java ranch articles) and in some documetaion I find the "magic cookie/lock cookie" notion.What is a magic cookie / lock cookie ? As far I understand it is some sort of pointer(it is used to calculate the access point in to a data base file).
 
Anton Golovin
Ranch Hand
Posts: 530
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mihai Radulescu:
Hallo

I prepare my self for the SCJD (some M.Habibi, some coding , brief trough java ranch articles) and in some documetaion I find the "magic cookie/lock cookie" notion.What is a magic cookie / lock cookie ? As far I understand it is some sort of pointer(it is used to calculate the access point in to a data base file).


It's best described as an ID a client uses to lock/unlock a record. What number you use is secondary. Because each record on the database level has a unique number (offset bytes), that is one of the options. But after some thinking, I will use another way.
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anton Golovin:
It's best described as an ID a client uses to lock/unlock a record. What number you use is secondary. Because each record on the database level has a unique number (offset bytes), that is one of the options. But after some thinking, I will use another way.


The "magic cookie" and "lock cookie" are different things. The lock cookie is as you described, its a way to represent a locked record, it could be a record number or offset into the file or something more complex. The magic cookie identifies the file as a data file.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for answers ,that helps at least I think I know what is a look cookie but I still have problems with the magic cookie.
Peter wrote :
"The magic cookie identifies the file as a data file" , that means I read olny the file header in to a "cookie" and through this I can identify my data file ?
Can you help me with an example ?
Or better with some documantation ?
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mihai
> Thanks for answers
you're welcome.

> that means I read olny the file header in to a "cookie" and through this I
> can identify my data file ?
> Can you help me with an example ?
> Or better with some documantation ?

It's vaguely documented in your "Data File Format". The first four bytes of the file are an integer that "identifies this as a data file". I read that as meaning that if the value you read from a file isn't the same as what is in the file you were given with your project then it's not valid. I base that assumption on the fact that the java class files have a very similar format. In their case the "magic" is 0XCAFEBABE. see Java VM Spec, The class File Format.

Using this means that if I point my server at something that isn't a data file I can throw an exception instead of trying to use it.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok now I have a clear picture.Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic