Hi everyone! I've just seen the topic of my semester's project from Operating Systems and I need your help:P What I have to do is write an disturbed file system in java (use some server like Glassfish )
So I'm asking anyone who have some kind of experience in operating systems for some advices how to start with this (maybe give me some links to interesting examples etc.). Any help would be useful.
You can follow some unix 'philosophy', i.e. you should be able to open( ... ) and close( ... ) a file and you should be able to read( ... ) and write( ... ) it; before you have a file you should be able to create( ... ) it and you should be able to remove( ... ) it. Optionally you could implement some ioctl( ... ) (IO control) functionality. Your functionality can 'lean' on any existing functionality offered by a 'real' file systyem.,
Originally Posted by kate88
thanks for reply!
Now I have problem how to do it on glassfish server. As far as I know Java EE does not allow using java.io .. Do you have any idea how to store data on such server?
It would surprise me if a server wouldn't allow any file I/O; it would be an ESS(tm) (Extemely Silly Server ;-) Remember that your code runs on a server side so it is part of a server. A client can't do any file I/O on a server without a sever wanting to do file I/O.
Originally Posted by kate88
and what do you think about using JNDI?
ByteArrayOutputStream b= new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(b);
new InitialContext().bind("path/to/myobject", baos.toByteArray());
Would it be effective?
If your server will expose a distributed file system, then necessarily there are multiple servers involved. Before you start thinking about writing code, you need to plan out how one portal is going to display links to files on other servers, and allow files on those servers to be copied, deleted, moved, and renamed, while presenting a consistent view to the user.
(you might also allow changing of permissions, restrictions based on user and group, a secure log in, etc.)
my teacher told that i can assume that there will be only one server but many users can read one file in the same time (and only one can write).He want me to nicely solve the problem of synchronization. FIles will be big (for example 2gb) and they will be divided into small parts. In addition every user will who read the file, will use another instance of file.
Ok, well, you might want to take a look at the java.nio.channels.FileChannel API, which is designed for this purpose. It allows you to lock an entire file, or just portions of a file, and also works with RandomAccessFile's, which is what you're going to want if you're dealling with very large files accessed by multiple users.
Is it possible with java.nio to create new instance of file for every reader? In my system I want every reader to have another instance of file (file is divided into blocks).. And I want to have only one writer who also get another instance. After writer finishes editing file the file is updated on server (while all readers are still reading their own instances). Can you tell me how to do this with java nio?
You keep saying that the file is divided into blocks. I'm not sure what the significance of that statement is. Does it imply something about how the file is permitted to be accessed?
I have to do something like this:
And I am looking for the best way to synchronize processes of readers and writer.
In the picture, it shows different users accessing different parts of the file, is that the conop, or is it expected they could access the same part of the file simultaneously?
yes, users can access the file simultaneously.
we can leave the idea of dividing file into parts (it's just one of the concepts of this filesystem.. files can be big like 3gb and that's why users read/write files in chunks)
What I don't know is how to synchronize everything in a nice way (create new instance of file for every reader and ensure that there will be only one writer per file).
Ok, so take a look at the java.nio.channels.FileChannel API. I think it already handles the details of locking portions of a file that someone is writing to.
Here's a pseudocode example of using it to lock a portion of a file for write:
If under the hood, you use FileChannels to handle the read and write access, the rest of your project involves developing the user API.
File file = new File(...);
FileOutputStream out = new FileOutputStream(file);
FileChannel fc = out.getChannel();
FileLock lock = fc.lock(position, size, false);
...write to the file...