Kaushik Sathupadi

Greenhorn
+ Follow
since Jun 23, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kaushik Sathupadi

Suppose, a class 'package1.Class1' is loaded using a new classloader, it by default cannot access another classes in "package1" having "default" access. Is there anyway to grant this permission.

Note 1: package1.Class1 will not access othere class in package1 using reflection. It will access them directly. like for eg.,
package1.A = new package1.A() [ where class 'A' has default access ]


Note 2: I've even tried giving ALLPERMISSION in .java.policy file. however it always throws a java.lang.IllegalAccessError: tried to access class <cls1> from class 'package1.Class1'. Why does this happen?
17 years ago
Hey paul,
I was just trying to give an example. In the actual scenario, I have many super class methods, all of which are overriden,(either in this class or in one of the sub classes). and i need to invoke one of the super class methods based on a input parameter to the method "test". consider this:

class Child extends Base{
public void test(String methodToCall){
if("test1".equals(methodToCall){
super.test1();
}
else if("test2".equals(methodToCall)){
super.test2();
}
..
..
..
else if("test100".equals(methodToCall)){
super.test100();
}
}
}

It would be a lot more easier if i can replace this redundant code with reflection.
17 years ago
Hey thanks for answering prabhu. But my problem is that the methods are overriden in the sub class and i want to invoke the super class method. consider this example
Class Base{
public void test(){
System.out.println("test of base");
}
}

class Child extends Base{
public void test(){ //overriding super class method
super.test();// <- (1)
}
}
How do i replace line (1) using reflection, so that "test of base" is printed? (without creating a new instance of Base, ie., should be invoked on current instance)
17 years ago
Assume that a Super class 'A' has, say, 20 methods. All of these are overriden in sub class 'B'. Now in a method in sub class 'B' i want to call one of the super class methods based on a parameter to this method. i don't want to put 20 if conditions to do this. Is there a way by which i can invoke the super class method using reflection. Note that this invocation should not call the overridern method in the sub class. Quite simply, is there a way to do "super.abcd()" using reflection.
If not, just out of curiosity, can i do this using JNI.
17 years ago

We'd prefer that you keep the conversation here.


- Sure we can. But I don't see a watch of this thread link anywhere, that would mail me automatically if any updations are made to this thread. Anyway, pls update this thread if any idea strikes you regarding this. (Am I right now?)
17 years ago

I think in that case you're out of luck. Have you looked at just getting a better app server?


-- I don't have that option. Iam sorry that I cannot really tell you why for official reasons, but just that even if there was a better app server for our purpose, I cannot make the decision of changing it.

Anyway thaks for your precious help. And anytime, if any Idea strikes you regarding this, please mail me at kaushik.sathupadi@gmail.com.

P.S: Now that I think of it, I could use my time that is required for bouncing the server, to check my mail, chatting etc. Just trying to be optimistic. But pls don't let that drift you, any body reading this post, pls mail me if you have an Idea. There are dozens of developers here bouncing the sever each time they make a change like a tennis ball. And if a solution is found, could save a lot of developer time. Which means a lot of money saved for the company.
17 years ago

you change a JSP, Jasper regenerates the servlet code, the servlet gets compiled, and then gets loaded


.. Not only that, as I mentioned, to the same application server(that runs remotely), i can connect through JPDA with a locally running version of jdeveloper and redefine the classes. But the problem is to make the connection it takes around 20-30 mts. But the redefining part itself is fast. and i can redefine a servlet.. a EJB .. or anything else.

The main servlet would delegate all of its work to other classes that it loaded itself through its own ClassLoader. When it needed to reload the classes, it could simply create a new ClassLoader and do so.


I don't understand this. Would it be possible that once the servlet has redefined the class files, the next access to that classes from anywhere will get the newly loaded class? (Pls. don't ask me to re-structre the entrie application for this. The designers would kill me.)

If that's possible, I am ready to do the home work. Where should I start reading. Ben, like you said, I could go through the Tomcat class loader API, but It's going to take a lot of time. Are there other articles that I could help me get started, especially for redefining files on an application server.
17 years ago
oh no . I'll tell you my exact problem, pls tell me if there is any better solution than what iam thinking. The problem for me is that my application server HAS to run in a remote location. this is because the database server is in the remote location and the business components make a lot of talking to the db. Thus, It's never possible to have the application server locally running. I've tried to run it locally and the application is slow as hell.
So we have a application server (oc4j) , that is running remotely, in the same network as the db , with a web interface to start, stop and put classes in a prepend path. So each time I change something, like putting a log message, I have to put the classes in the prepend path and then bounce the server. Bouncing the server takes anywhere between 10 to 15 mts, since there is a lot of initalization going on. This is really cutting off my productivity. Is there a better way. Am I missing something?
17 years ago
Thanks. Please tell me if the construction of such a servlet is possible if I include the following constraints.

1. I don't have to redefine all the class but only a set of them
2. The first thing I will do after starting the application server is run this servlet.
3. Let this servlet load all the class files, using a new class loader.
4. Each time, when I need to redefine these classes, I will again upload all of them. Now let the servlet drop the class loader and create a new classloader with these new classes.

would that be feasible?
If it is not possible then how does JPDA work? I've seen that when I connect to a remote oc4j server through remote debugging option in JDeveloper, and compile a class it automatically gets redefined in the server. But the problem with this approach is that it takes too much time for connecting to remote server. I just want the redefining part of it.

PS: please tell me it's possible
17 years ago
Thanks, I got it. There is one more question related to this.
In what situations is the redefining possible?
Is redefining possible if I add a method in the class? what if the method is private?
17 years ago
Hi,
We all know that one of the major problems in using application servers is that we need to restart it each time we make a change to a class file, for it to get reloaded. I know that in some application servers we could reload a class if we put a modified version of the class file in some place. But what if the application server is remote? or my application server does not support this feature.
So I want to know if it's possible to write a servlet that will let me upload any class file from the local machine and reload it in it's current JVM. Since the servlet runs in the same JVM as the application server the change should get reflected in the application server.
17 years ago
Thanks Bill. Good to meet you!

Are you sure you are not making things unecessarily complicated?


- Am I? I was only trying to make things simple!

All I wanted to do was to put all the code in one place so that
1) I can see the whole logic written in a single block of code.
2) When developing and testing(in an intranet environment) the developer may test the code from his local system without having to code session beans. And while deploying(to the internet environment) his code will be transparently taken to sssion beans and executed there.

I would consider writing the code in a scripting language


-- I don't know anything about scripting language. Are they used to write code on the fly. Can you please show me how the client code would look like if I used one of the scripting languages.

returning the results as an XML document rather than a serialized object


- While returning the results I don't see any problem. It works perfectly. Sending the "code" is the problem.
17 years ago
This is going to be a little long. pls bear with me. My application consissts of two parts- the server-side code and the client side code. Client is a thick client written as a java applet. The server code is written in EJB and the server runs in the same network as the database server. So all the database code has to be in the server code. Right?

Now, the problem is that whenever I want to write simple functions in the client code that required to execute multiple sql statements, i have to put only those statements in the server coding and the rest(the UI related things) in the client code. This means that the logic in the function gets devided in two parts that makes it difficult to maintain.

So I want code something like this
------------------------------------------------------------------------
in the client...
------------------
public void methodInClient(){
final String text = <textfield>.getText();
Transferable t = new Transferable(){
public Vector execute(){
String query = //construct quries based on the value of text
super.executeQuery(query);//Transferrable abstract class has
//methods like execute query.
// run multiple queries
//put the result in a vector
// return the vector.
}
};
Vector result = Transferer.transferData(t);
//do something with the result vector, say dispaly a message box to the user
}

.. And in the server code
---------------------------
public Vector executeAnySqlCodeFromClient(Transferable t){
Connection con = getDBConnection();
t.setConnection(con);
Vector res = t.execute();
return res;
}
------------------------------------------------------------------------
... In the code above Iam not trying to transfer the data in the transferable object, but the code of the newly created class itself that could be polymorphically taken by the Transferrable abstract class is the server code.
But serialization would'nt allow me to do that. This is because it requires the exact class that is serialized to be present while deserializing it. How do I Proceed?

Thanks for reading this far.....
17 years ago
Thanks Campbell,
then is there any specific reason why java allows to access static variables through references to the classes? It could have easily been a compiler error!

could it be like this? When the class name is very big, we can create a reference to it with a shorter name and access the static variable through it?
17 years ago
Here is a update to my previous message. Please validate the following:

One of my friends suggested that we should actually prefer to use
reference.staticMethod()

instead of
className.staticMethod()

.. since if in the future we move the static method to some other class then we can just change the reference to point to a new class, instead of chaniging the class name everywhere.
17 years ago