• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

nx:All of URLy Bird1.1.3 about record lock

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a new memeber of this forum.And I come frome china.I known this forum from friends.I am a teacher in a information center of shcool.I love java language as if she is my wife.From 1997 I see it the first time,I always study it.And i move through this forum about 2 months.I know Andrew,Bharata,
Phil,and Mark are the expert and they are very very very good.
From this day,i will ask you some questions about URLy Bird1.1.3. I can keep the question clear and simple.
[ February 14, 2004: Message edited by: liqun chang ]
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From this forum.I understand the file lock and the record lock,the rmi and the singleton.I say thanks for all of you.Either singleton Data instance or
multiple instance can result in right solution.The key dependency on our design.
In the end of my design,I have questions about the instruction.

The operating mode is selected using the single command line argument that is permitted. Architecturally, this mode must use the database and GUI from the networked form, but must not use the network server code at all.


1.what is "this mode" and what is "networked form"?
2.please give me detail description please?
thanks.
 
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,
First, welcome to this forum.
Second, it might be useful to quote the entire section that your quotation comes from. We don't have the same assignment, but the following section may be the same for your assignment.


Non-Networked Mode
The program must be able to work in a non-networked mode. In this mode, the database and GUI must run in the same VM and must perform no networking, must not use loopback networking, and must not involve the serialization of any objects when communicating between the GUI and database elements.
The operating mode is selected using the single command line argument that is permitted. Architecturally, this mode must use the database and GUI from the networked form, but must not use the network server code at all.


From the context of the above quotation I think it's possible to state with some certainty that "this mode" is referring to the non-networked mode, sometimes also referred to as standalone mode. In standalone mode, there is no network necessary and there is no need to have a database server. In standalone mode the application directly access the database file that exists on the same machine. You will sometimes hear people refer to this as local mode, in which the application accesses a local database. This is in contrast to remote mode, in which the application accesses a database on a different machine via a network connection and makes use of a database server.
The networked form refers to the situation wherein there are two instances of your application running at the same time. One application is running on one machine (the database server) in server mode. The other application is running on another machine (the client machine) in network client mode. The user can request a search while using the GUI on the network client. This request is passed over the network to the database server. The database server actually performs the database search operation against the database file on the server machine and the database server returns a set of records that match the users request back over the network to the client machine.
Now to get to the heart of your question, what does the following mean?

Architecturally, this mode must use the database and GUI from the networked form, but must not use the network server code at all.


I think you can draw two inferences from this statement:
1) Regardless of whether the application is operating in networked or non-networked (that is, standalone) mode, the application must use the same database code (at least at the lowest level, the level that accesses the database file). You may further infer that these database operations must be the ones that are defined in the Sun-supplied interface.
2) The client GUI must be written in such a way that it does not care whether it is dealing with a local database (as it would be in standalone mode) or whether it is dealing with a remote database (as it would be in networked mode). For example, you might decide to implement booking by doing the following:

With this code one can't tell whether you are booking a record from a local database (as you would if you were in standalone mode), or whether you are booking a record from a remote database (as you would if you were in networked mode). This characteristic could be called transparency. That is, the operating mode is transparent to how the client makes database operation calls on the database. In other words, there isn't one book method that works for local database access and another one that works for remote access. If you were to have two different book methods, then I think you would be violating the spirit of the assignment instructions.
So how do you achieve this transparency? That is the subject of many threads on this forum and I leave it to you to discover them yourself.
Hope this helps,
George
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George thanks you very very much.You are the first friend from i come to this forum.If you come to china, i will invite you for chinese meal and tea.
Certainly i will invite Andrew and Mark and other experts.
From your answers,i will keep the question clear and simple.
1. I have two applications which is either Server or Client.For Server i will provide location of datafile and provide business method(book and search) and port. For Client,i will provide two selections(one is local mode or be called standalone mode,another is the network client).
2. When i running the application,either server mode or client(alone mode)use the same business methods,also the Sever and the Client that running in alone mode all use the same database system for access datafile.
3. When i use this command line:java -jar path_and_filename <server> then the Server running.When the Dialog of Server appear,i specify the location of datafile and prot.
When i use the command line :java -jar path_and_filename <alone> then the Client running.When the GUI of Client appear,i can specify either location of datafile or host and port of Sever.
Am i right? wait for you reply.
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi every expert.
another questin:

The mode flag must be either "server", indicating the server program must run, "alone", indicating standalone mode, or left out entirely, in which case the network client and gui must run.


1. Is the situation of"left out entirely" is the samething to"standalone mode",also java -jar filename <alone> is the samething to java -jar filename <empty> ,or any other means.
2. Whether The means of"in which case" represent in the case of standalone mode.
Because i am a chinese.for exact english logic i am a little poor.
Hi George and other expert. please help me.
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,
You're welcome.

Originally posted by liqun chang:
1. I have two applications which is either Server or Client.For Server i will provide location of datafile and provide business method(book and search) and port. For Client,i will provide two selections(one is local mode or be called standalone mode,another is the network client).


I think you can accomplish everything you need with a single application. The application can operate in three modes: standalone, server, and network client. When the application is operating in standalone mode it will need to know where the database file is located. When the application is operating in server mode it will (as you stated) need to know where the database file is located and the port over which it will access the network. When the application is operating in network client mode it will need to know the location of the database server (the machine where the application is running in server mode) and the port over which it will access the network.
In the networked configuration you will have your application running on the server machine (in server mode) and another instance of your application running on the client machine (in network client mode). In non-networked configuration you will have your application running on a single machine (in standalone mode).


2. When i running the application,either server mode or client(alone mode)use the same business methods,also the Sever and the Client that running in alone mode all use the same database system for access datafile.


Sounds right.


3. When i use this command line:java -jar path_and_filename <server> then the Server running.When the Dialog of Server appear,i specify the location of datafile and prot.
When i use the command line :java -jar path_and_filename <alone> then the Client running.When the GUI of Client appear,i can specify either location of datafile or host and port of Sever.


There are three cases:
1) java -jar runme.jar server (needs datafile and port)
2) java -jar runme.jar (needs database server host and port)
3) java -jar rumme.jar alone (needs datafile)
Hope this helps,
George
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,


The mode flag must be either "server", indicating the server program must run, "alone", indicating standalone mode, or left out entirely, in which case the network client and gui must run.


The above quotation from the assignment instructions can be paraphrased as follows:


The mode flag, if it is present, will be either "server" or "alone." If the mode flag is "server," it indicates that the application must run in server mode. If the mode flag is "alone," it indicates that the application must run in standalone mode. If the mode flag is not present, it indicates that the application must run in network client mode.


Originally posted by liqun chang:
1. Is the situation of"left out entirely" is the samething to"standalone mode",also java -jar filename <alone> is the samething to java -jar filename <empty> ,or any other means.
2. Whether The means of"in which case" represent in the case of standalone mode.


1. No, in this case "left out entirely" corresponds to the network client operating mode. "java -jar filename alone" is not the same thing as "java -jar filename." "java -jar filename alone" corresponds to the standalone operating mode, and "java -jar filename" corresponds to the network client operating mode.
2. The phrase "in which case" refers to the case in which the mode argument has been left out entirely, and that case corresponds to the network client operating mode. So, it does not refer to standalone mode, but rather it refers to the network client operating mode.
In English (like all natural languages) there's always plenty of room for ambiguity.
Hope this helps,
George
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George,thanks for your clear and logical answer. From now,i will ask some questions about design of the URLy Bird 1.1.3 from general to specification.If go to logical branch i will use b1 or b2 for denotation.
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. For alone mode.I will create Data class that implements DB interface specified by Sun.In this situation,Data class which is singleton or multiton is not problem(within network,i will mention it).I have a Services interface that has two business method(book and search),both of methods in Services interface can throws IOException and(not or)RecordNotFoundException.In the Services interface,there is also a getServices() method that return Services type instance dependenting on the implementation.I will create a implementation class ServicesImpl that implements the Services interface.
From mention above,i implements three tiers client/server design. first the Data that is accessing from datafile,second the
ServicesImpl that is used for business methods,the third client or server access to business layer.The advantage is if you want to change business logic,the client will be affected little.
Am i right? If it has some mistakes.please give me comments with the special phrases from my sentences.
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From network(either server mode or network client),
1: I will create RemoteServices interface that implenments Remote and
Services.This is possible because the class that throws IOException can also throws RemoteException.There is not body in
RemoteServices interface. I don't know the follow code whether is suitable.

public interface RemoteServices implements Services{}
public interface RemoteServices extends Remote
{
//no body because all of methods inherit Services interface
}


I also create RemoteServicesImpl that implements RemoteServices interface and extends UnicastRemoteObject.All of methods that within RemoteServices interface will be called from network clients through it's reference.When network clients invokes the
methods within RemoteServicesImpl class ,in fact the users call the methods on the ServicesImpl class.Only getServices()method is different.In ServicesImpl it return ServicesImpl type in fact,in RemoteServicesImpl it return the RemoteServices type.
Am i right? if there some mistakes please give me some comments on the special phrases.(because in ood i forget whether interface can implements interface.)

2: The simple method. I will create RemoteServices that extends Remote(only two methods in this interface,book() and search()),and i also create RemoteServicesImpl class that implemets RemoteServices extends UnicastRemoteObject and wrap the
methods of ServicesImpl(except getServices()) in it.When the network clients invokes the business methods within the RemoteServices interface, in fact it delegate the RemoteServices invokes the methods within the ServicesImpl class.
Am i right.if not please give me some comments about this.

3: In general,i create a RemoteDBFactory interface which is a remote interface.And there is a getConnection() method in it
for returning the RemoteServices reference.I also create a RemoteDBFactoryImpl that implements RemoteDBFactory remote interface.The advantage of this situation is that can reduce the remote objects that registry to rmiregistry.In all of these three
questions,i don't mention the concurrent access and thread safe and singleton and multiton.I will mention these sections in next topic.
Am i right?or mistake please give some comments.
[ February 09, 2004: Message edited by: liqun chang ]
[ February 10, 2004: Message edited by: liqun chang ]
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Geroge and Andrew,Mark,Phil please help me.
Myself design part 1)
1: I create Data class implements DB interface that specified by Sun.In this class,i also create another method(isValidate()to verify whether the recNo is validated). For all of IOExceptions are wrapped in DataAccessException(the sub class of RuntimeException).The advantage of this trick is more natural than in RecordNotFoundException and need not to be thrown or caught.According to the specification,i impelments the DuplicationKeyException class,but it is not be declared in any code
wihtin Data class because the specification is not clear.perhaps it is useful future extending(when use relational-database system).
The Data class is not singleton(but multiton).
Am i right? please give me comments for it.

2: I create Services interface that have only two methods(book and search).I also create ServicesImpl class that implements
the Services interface.These interface and class is for business tier. This business tier is useful for client alone or
server to invoke. Also either standalone client or server can use it. The ServicesImpl class is not singleton(but multiton).
Am i right? please to comments.

3: I create the remote interface RemoteServices that has the same methods to Services(book and search), and i also create
the remote object class RemoteServicesImpl that impelments RemoteServices.I also create RemoteDBFactory interface that has
getConnection() that return the new RemoteServicesImpl remote object.
I also create the implementation RemoteServicesImpl that impelents the
RemoteServices interface.
For each network client has a RemoteServicesImpl
instance.In each RemoteServicesImpl object has a new ServicesImpl instance. In each ServicesImpl object has a new Data instance.
Also a new Data instance per ServicesImpl object,a new ServicesImpl instance per RemoteServicesImpl object. a new
RemoteServicesImpl instance per network client.
Certainly the remote object class must extends UnicastRemoteObject class.
Is this is suitable?
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,
I think you're on the right track. I think I agree with everything you've written so far with some exceptions noted below.

(because in ood i forget whether interface can implements interface.)


No, an interface cannot implement another interface. But that's not really what you're doing in the getServices method anyway. You're simply returning an object that implements the interface, which is OK.
My major concern is the Data class and its relationship to the database file. If the Data class is really a multiton, then how are you protecting the database file from simultaneous access? If each client has their own instance of the Data class and each Data instance contains a handle to the database file, what is preventing simultaneous access to the database file?
Hope this helps,
George
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George:
Because your clear and logical answer,i already regard you as my best friend.
before i come to Data class,i hope finish this discussion about your reply.
you say

No, an interface cannot implement another interface. But that's not really what you're doing in the getServices method anyway. You're simply returning an object that implements the interface, which is OK.


1: From the bold fonts,i guess whether you suggest that simply returning an
ServicesImpl object that implements the Services interface ?
please you give me comment on this section.

Then i will change my idea a little more.
2: For business tier,i create Services interface that has three method(book,search and getServices()),i also create ServicesImpl class that implements Services interface.Both Services interface and ServicesImpl class is used for Server mode and alone mode.
3: For network,i create RemoteServices interface that has two method(book and search),i also create RemoteServicesImpl class that implements RemoteServices and extends UnicastRemoteObject.
4: In the RemoteServicesImpl,i will invoke ServicesImpl.getServices() static method and return a ServiceImpl object.When i invoke book method on
RemoteServices,i invoke really book method on ServicesImpl object.When i invoke search method on RemoteService,i invoke really search method on
ServicesImpl object.
Because i am a strict teach and don't hope to have any mistake.
Hi George please you give me a detail comments.
In the next section,i will discussion my design of the Data class,the concurrent access and the lock,singleton and the multiton,the single mutex or the multiple mutexes,synchronized methods or synchronized blocks.
Please you give me more help,certainly if you have time.
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Myself design part 2)
For thread safe and concurrent access.the instruction is as below.

Your server must be capable of handling multiple concurrent requests, and as part of this capability, must provide locking
functionality as specified in the interface provided above. You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server. Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU,
consuming no CPU cycles until the desired resource becomes available.



From mention above.I must be think about the most important portion of design(file access lock and record lock).
About the record lock:I will create a WeakHashMap static variable(be shared by all Data instances)which is used for locked recNo with a unique Long(cookie).The cookie is created by random creator.When Thread1 want to lock the record,it see if the current record is locked by other thread.if yes it give up cpu and wait for notifying.if not ,it put the Integer(recNo) and Long(cookie) in the WeakHashMap as key/value.In fact,the cookie is the unique identity of the network clients,so each network connection object(RemoteServicesImpl object) has a Data instance.

1: the code of lock method as below:


public long lock(int recNo) throws RecordNotFoundException
{
//verify the recNo validity,if recNo isn't valid then throw RecordNotFoundException,
//if recNo is valid then go on.
isValidated(recNo);
//wrap recNo in Integer
//create a local variable cookie come from random creator
//wrap cookie in Long
synchronized(lockedMap)
{
while(lockMap.contain(lrecNo)
{
try
{
lockMap.wait();
}
catch(InterruptedExcption ie)
{
throw new DataAccessException("DataAccessException",ie);
}
}
lockMap.put(lrecNo,lockCookie);
lockMap.notifyAll();
}
return cookie;
}


Is this method right? If i have some mistake please give me comments.

2: The code of unlock method as follow:


public void unlock(int recNo, long cookie) throws RecordNotFoundException, SecurityException
{
//verify the recNo validity if not throw RecordNotFoundException
//if yes then go on
//wrap recNo in Integer
//wrap cookie in Long
//check if the cookie is same to lockMap.getValue()
//if not throw SecurityException;
//if yes then remove the lock and notify all waiting threads
}


Is this approach is right? Could you give me some comments.

3: The isValidated(recNO) method as below:


public void isValidated(int recNo) throws RecordNotFoundException
{
//read head information of the database file.
//read all of the records to byte[].
//check whether recNo in the scope of the record numbers or is marked as valid
//if not throw RecordNotFoundException
//else do nothing
}


As you see,because isValidated(recNo) method relates to the file read/write
,so i use descriptive processing.About the file read/write lock,i will mention in the next section.
Because Andrew and other experts don't hope the whole code,so i write only
the key part,i think that you should be understand because you have a clear and logical thinking.
Please you give me comments about the whole comment and each step comments.
I tell you i am a new member of this forum,after i see the articles about two months,i open this thread.
[ February 11, 2004: Message edited by: liqun chang ]
[Andrew: reduced unlock method to psuedocode]
[ February 12, 2004: Message edited by: Andrew Monkhouse ]see All of URLy Bird 1.1.3 about read/write lock
[ February 12, 2004: Message edited by: liqun chang ]
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,
As you can see, I reduced your unlock method to psuedocode - it makes very little difference to the discussions, but it is more in line with our commitment to not allowing complete solutions to be posted to sections of code.
Sorry I havent looked at your earlier posts - I am away from home at the moment, and on a very slow internet connection. When I get back home I may have more time.
One question I do have though, is why do you have a call to notifyAll() in your lock method? Personally I don't think it is necessary, but I would like to hear your reasoning for having it first.
I think you would be better to open new topics for each new question, and have the subject line reflect the topic you are asking about. This post is already reaching the size where some people may not bother to read it, expecially with a very vague description.
Regards, Andrew
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,according to you suggesting,i will open the new thread and hope
you give help.

2. nx:All of URLy Bird 1.1.3 about read/write lock
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,

Originally posted by liqun chang:
1: From the bold fonts,i guess whether you suggest that simply returning an
ServicesImpl object that implements the Services interface ?
please you give me comment on this section.
Then i will change my idea a little more.
2: For business tier,i create Services interface that has three method(book,search and getServices()),i also create ServicesImpl class that implements Services interface.Both Services interface and ServicesImpl class is used for Server mode and alone mode.
3: For network,i create RemoteServices interface that has two method(book and search),i also create RemoteServicesImpl class that implements RemoteServices and extends UnicastRemoteObject.
4: In the RemoteServicesImpl,i will invoke ServicesImpl.getServices() static method and return a ServiceImpl object.When i invoke book method on
RemoteServices,i invoke really book method on ServicesImpl object.When i invoke search method on RemoteService,i invoke really search method on
ServicesImpl object.


1. I just meant that it's not possible for an interface to implement another interface, that's all. I didn't have a problem with your code, because I don't think the code is trying to implement an interface. If this still doesn't make any sense to you don't worry about it, it's not important. Just remember that an interface can't implement anything (including another interface). Only a class can implement an interface. Again, I don't have a problem with your code, only your comment.
2 - 4. Sounds like you're on the right track. I don't see anything with which I disagree.
Hope this helps,
George
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,

Originally posted by liqun chang:
Myself design part 2)


I think the approach is fine.
I have a concern about the pseudocode in the isValidated method, however. If I understand correctly, isValidated is called whenever lock is called (in other words, it's called more than one time). The pseudocode indicates that the header information is read from the database file and then all the records are read. This is a lot of work to do each time the isValidated method is called (which is each time the lock method is called). My suggestion is that the header information in the database file should be read only once (perhaps when the Data class is instantiated). The isValidated need only seek to the correct location for the recNo and read the validity flag to determine: 1) whether the record physically exists in the database file, and 2) whether the record has been marked for deletion or not.
Hope this helps,
George
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic