Patrick Cobbett

Ranch Hand
+ Follow
since Jul 10, 2003
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Patrick Cobbett

Hello all,
I am trying to load class files within a jar file. The program extracts and iterates through all the ZipEntrys. For each ZipEntry i obtain the InputStream and read in the contents of each class file in to a byte array. I've made a ClassLoader which relaxes the access rights to the define method which take an array of bytes: Class defineClass(String name, byte[] data, int start, int end);
However only certain classes correctly return a Class objects. The majority of class files i try to read in this manner throws a ClassFormatException with one if the following messages:
Illegal constant pool type
Illegal UTF8 string in constant pool
Illegal constant pool index
Arguments can't fit into locals
any ideas?
16 years ago
This following URL points a jar file called bar.jar within the bar directory.
This URL points to a class with that jar file.
I thought that logically it should be possible to access a jar within a jar with:
Why do i get problems when trying to open a JarURLConnection to this url? I'm basically trying to create an executable jar which runs other executable jars which are contained within it. Any ideas people?
Here are different combinations of url i tryed:
error message: innerJar! not found
error message: FileNotFoundException
this works but the JarURLConnection points to the baz.jar file and not the innerJar.jar
Is is possible to access a jar with in a jar or do i need to first extract it?
thanks in advance
16 years ago
Any one have any ideas how to run an executable jar within a running java program? I am trying to avoid creating an external process, i.e. calling Runtime.exec(). Is there a way to invoke it without having to explicitly instantiating a new JVM?
thx in advance
16 years ago
Thanks guys, and yes i did have an especially large one for new years. Not sure how i forgot to mention your help Phillipe, as we also exchanged and debated a number of ideas. Have you completed your SCJD yet? I have now been preparing to take the IBM UML & OOAD certification. Fingers crossed!
16 years ago
I haven't posted anything on the ranch for some time now so i may well be a faint memory to those who helped me. A contract delayed my submission until recently so i've only just received my result.
A special thanks to Max who identified a critical flaw in my original rmi server design, and even more thanks to Andrew Monkhouse whose debates about a range of problems helped me to think through my design.
Thanks guys,
16 years ago
Hi, as Frank explained, Singleton is often misunderstood. He quites rightly makes a reference to GoF which states that the Singleton pattern could conceivably have more than instance. The important point to note is that the number of instances is controlled by the class. For example the singleton class could create up to a maximum number of instances and pool them internally.
Hi Andrew,
fair play. I think you're right, there's no clear cut answer here, hence the lack of a straight reply in your previous posts. Having looked again, there may be less inconsistency then i thought. The contract for close() in Data says:

This method closes the database, flushing any outstanding
writes at the same time. Any attempt to access the
database after this results in a IOException.

Perhaps it's not fair to say that methods such as add(DataInfo) actually access the database. Rather it call methods which access the database. The fact that add() catches any thrown IOExceptions and throws a DatabaseException is it's own business. If i check for null every time before the file pointer is used and throw an IOException, then i can let that method deal with it as it would had the IOException been thrown by another method in the try-catch block. In i think all cases they catch it and throw a DatabaseException.
I feel that methods which do not operate on the file pointer should not throw exceptions. The contract for close() above doesn't even say it should.. only methods which access the database should throw them. The method getFieldInfo[] doesn't throw IOException or DatabaseExceptions because it caches the field data. Should this be considered something encapsulated, and so as far as the client is concerned it is accessing the database and so SHOULD throw an exception of some sort.. perhaps Runtime?
Although, do you accept that we are changing existing code which is supposed to be complete? This is certainly something which should be documented.
Do you disagree with anything i have said? No doubt there's many ways of argueing this and you will tell me to just argue my view as fully as possible. However do you think i have a strong enough case to defend my ground?
Hi Andrew,
I get the feeling your trying to get me to think about his one! Sorry if i'm i'm asking u to spell it out for me . I have thought about it but let me explain where i'm stuck in my mental thread. You quite rightly say that it's only the methods which use the file pointer which will not operate. The close() method in Data calls close() on the file pointer. So any attempt to use the file pointer will result in an IOException being thrown.. or if it's caught a DatabaseException. That is what i thought was the case. But looking again i'm a little confused. Unless I inadvertantly changed the code, Data also sets the file pointer to null after closing it. So it seems that it would throw NullPointer exceptions after all? Are we expected to change the code in Data so that it does agree with the contract specified? I thought the code should already be complete and functional.. with the exceptions explictly stated in the requirements.
If all this is necessary then the best way of doing it would be to check for null at the beginning of each method which accesses the database, and throw IOExceptions. However, the criteriaFind() method is only able to throw a DatabaseException.. (or did i delete the IOException:eek so this would already be an inconsitency. Or is it fair to add an IOException since it is accessing the database?
Am i supposed to satisfy the contract imposed by Data in Connection even though Data doesn't satisfy it!? There's a sense of inconsistency. Or are we supposed to satisfy the contract for close() in Data ourselves? Once again, i thought that exisiting method were supposed to be complete.
For me, the cleanest way of doing this in terms of code would be to remove the code which sets db to null. Then accesses to the database would throw an IOException, although i appreciate that Data should unreference it's resources when closed.
Hi Andrew,
thanks for your as always quick and thorough response to my problems! This unreferenced issue is the last little snag on my mind before i finally submit my project.
I don't think my implementation has any of the issues described, but i'm just asking for some final reassurance. My RemoteConnection implementation implements Unreferenced. A RemoteConnection instance is created for each client, and they are not pooled for other clients. Also, the server, or more specifically the Connection factory maintains no references to Connections it's issues to clients.
Can you see any reason for concern? Unreferenced should only be called once per client, am i right? And am i right in thinking there's no reason why unreferenced wouldn't be called?
I hope i can get away with subtley deviating a little to get some more of your insightful wisdom with this next related question.
So, i take it unreferenced simply calls close(). What does close() do? For starters it should unlock all records owned by that connection, perhaps by calling unlock(-1). But what else should it do? In another post (which i now can't find!) it was discussed that the specification for close() on Connection should agree with that of Data. Meaning that once close() is called the Connection can no longer be used. Certainly close() could set it's reference to data to null, but that will cause NullPointerExceptions to be thrown rather than an IOException. It would be a bit much to trap the NullPointerException for each method to throw an IOException. Similiarly it seems a bit much to have a boolean flag indicating whether the connection is closed as each method would have to check for it before it executes.
Both my ideas seem like over-kill, i know there's a simpler solution. Care to enlighten me?
One last thing. Some posts discuss problems people have been having with unreferenced, but i haven't experienced them.
All i gotta do is implement unreferenced() in my remote implementation and that's it right? Maybe i haven't tested under all possible outcomes, so let me know if i've missed something. Are there any special circumstances that i need to look out for?
I read that unreferenced() could be called more than once for a given object. Is that right and what is that dependant on?
Hi all,
Unreferenced is called when there are no longer any client references to a given remote object right?
A source on the web says this:

If a client does not refresh the connection to the remote object before the lease term expires, the reference is considered to be dead and the remote object may be garbage collected.

In order to 'refresh the connection', does the client have to invoke methods on the remote object? How is the connection refreshed? Let me explain my concern. I considered using a small leaseValue so that a crashed client would not hold locked records for long. But am i right in thinking that if the client didn't invoke any methods on the remote object during that time that unreferenced would also be called? What is the result of unreferenced being called? Can a client no longer invoke methods on it?
What is a reasonable leaseValue? Is the default value appropriate or have most overriden it?
thanks in advance
Hi Andrew,
How come you only have one executable jar? Didn't you use one for the client and one for the server, or are they distinguished at the command line?
The requirements for FBNS that you quoted was describing environmental setup.

If any environmental setup is required, do not just say what needs to be done; provide instructions on how to perform the setup.

I'm not sure if describing how to use the JAR tool goes under environmental setup. Won't hurt though to include it, i may well do so myself.
Also you say that if there is only one jar file then it doesn't need to be added to the class path. The instructions say that the program should run what ever directory it is installed in. If the jar file is located anywhere but the class path then the class path will need to point to it. Also, why does it make a difference whether there is one or two jar files?
For FBNS, do we have to support execution with the class files aswell as executable jar files?
My last question is this. Bearing in mind that i am setting the class path.. in windows 98 the class path can be set with:
set classpath=%classpath%;NEW_DIR
But i'm using a different computer now to when i started, and in windows 2000 i understand it's set differently. Any one know how this is done? I thought i could avoid this by documenting (as was explicitly required) that i was using Windows 98. However, no one seems to be taking any chances so i don't think i will either!
Also, Andy, how long ago did you submit? You expecting your results soon?
good luck
I'm putting the finishing touches on my userguide.html file. In my instalation section I need to cover how to install the server and the client. Now, there are two ways of doing this, running it directly from the jar executable and extracting all the files and then running rom where you put it. In either case some use of the jar tool is required. To what extent do I need to document how to use the jar tool to get the files or execute the application?
Hi Mike, i would be curious to hear what other people have to say but this is my opinion. Seeing as the submission is packaged as a JAR file, we can safely the assume that the user should know how to extract files. Giving instructions on how to extract files from a JAR file in the readme.txt isn't much help if they can't even unjar the submission to get to readme.txt!
Certainly, you should explain how to set the classpath to point to your jar files. Also, you should provide command line instructions to execute the jar files, for example:
c:\INSTALLATION_DIR\java -jar server [port]
You should also include instructions for running the RMI registry if required.
I know it's tough deciding how much information to provide. No doubt the marker will know how to do most of the instructions we supply anyway. But the instructions should be sufficiently complete for any one to run and use it. How stupid we are supposed to assume that most people are, i'm not sure.
hope this helps
S Bala,

If we do use a LockManager, is it better to use it as a private inner class to the data class, so that only Data class has access to it. This way the locks will be secure.
Any comments?

Sure, you could do this. Although making it a private member of Data has the same effect. It is better to use static member classes if possible rather than member class's. Your LockManager should not need to access any of Data's method or Data. Let me know which assignment you are doing as where the lock manager should resides depends on the requirements in the assignment.
Hi Andrew, i had a look at your table of contents for your design decision document that you referred me to. I notice that you did actually implement a deadlock prevention mechanism. I'm curious as to how you implemented this seeing as you didn't make use of a LockManager. In one post i discussed that in my view the only advantage of a LockManager was to localise the mapping of connections to locks, enabling dead-lock prevention. Since i decided to forget deadlock prevention (on the grounds that many people did well without implementing it and being lazy), there was no need for the LockManager as each Connection can itself ensure that it does not unlock records it has not locked.
For deadlock prevention you'd need a centralized class which knows who owns what locks. Unless you've used a static data structure in a Connection implementation, or indeed a LockManager, i can't think how you've implemented it.
come on spill the beans