Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Kalyan Mudumbai

Greenhorn
+ Follow
since Apr 30, 2004
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 Kalyan Mudumbai

Hi,

Is there an aliasing concept in JNDI? For example:

If I have a hashtable and I bind it to the context in the following way:


ctx.bind("oldName",hashTable);

And if I want to refer to the same hashTable with another name, may be: newName, then, can I do something like:


ctx.setAlias("oldName","newName");

so that I can later do a


Hashtable myTable = (Hashtable)ctx.lookup("newName");

and get the same old hashtable that has been bound to the JNDI tree.

Thanks,
Kalyan.
Thanks James,

Yes, that fine. What I'm asking is, what are the difficulties in maintaining them programatically? Why should some one admin them? What does the admin do?

Besides the above, I have another Question:
What makes anyone use multiple Sessions in one Connection, instead of using a Single Session to send messages? Why is there a Concept of a Session? Can't it just be Connection?

Regards,
Kalyan.
Why are "ConnectionFactory" and "Destination" administered objects?
What does the spec mean by saying that they are administered objects?
What are the advantages of having them as administered objects? (and not any other objects in the spec)?

Can someone throw light on this?

Thanks,
Kalyan.
Let's take your own example: RMIExample.

The communication ideally has to happen this way:

[talks to]
RMIClient ----------------> RMIExample (instance of RMIExampleImpl)

This might happens across the wire and across the JVM. So, some one has to send them from your client to the server. For this there might be a great deal of work like, connecting to the server, lookup the object, etc. etc. This work is common for most of such scenarios. Hence, the stubs and skeletons contain the common code that is required to obtain a reference to the remote object, serialize and deserialize arguments, etc. Stub acts like the messaging agent from the Client side and the Skeleton acts like the messaging agent from the Server side. So, when the client makes a call, it actually makes a call on the stub, which then sends the request to the skeleton on the server side, which in turn invokes the required method on the Server side object. So, now the above figure becomes:

RMIClient ----> RMIClientStub -----------> RMIServerSkeleton ---> RMIExample

The stub, skeleton and the RMIExample interface all will the have the same methods declared (read the disclaimer below). For example:

class RMIClientStub
{
public String getMessage()
{
//1. connect to the server
//2. look up the object (it's skeleton)
//3a. serialize the method arguments
//3b. invoke the method on the skeleton
skeleton.getMessage();
//4. deserialize the returned result
//5. return back to the client
}
}

And the skeleton looks like:

class RMIServerSkeleton
{
public String getMessage()
{
//1. listen for any stub requests
//2. deserialize any arguments
//3. invoke the method on the actual serverside object
serversideObject.getMessage();
//4. serialize the results
//5. send them back to the stub
}
}

class RMIExampleImpl implements RMIExample
{
public String getMessage()
{
//....
}
}

Disclaimer: The above implementation which I have given is just for your understanding. The actual implementation of the stubs and skeletons might be different (using reflection).

Hope this helps.

Thanks,
Kalyan.
16 years ago
Thanks people, for your inputs.
Tony, you have mentioned:
"Since most GUI type applications have a lot (italicised to denote that it is a vague measurement) of listeners attached, there can be a significant performance penalty if anonymous classes are used since the class loader must load a lot of classes that it would not have had to do otherwise."
Could you please elaborate on this? Why would the class loader load the anonymous classes even if they are not required? Please throw some light on this.
Thanks,
Kalyan.
16 years ago
Hi,
I have recently joined a team which has successfully implemented a high performing,robust 3-tier system, using Swing as a front-end, EJB as the middle-tier and Sybase as the data-tier.
The architecture uses XML as the data transfer mechanism between the presentation tier and the business tier. I always thought that it's better to use java objects to pass on the data from the 1st tier to the 2nd tier, because serialization of java objects is much quicker than serialization and deserialization of XML.
Experienced people, could you please put in your thoughts on this one?
Thanks,
Kalyan.
Hi,
so far I've been thinking that anonymous classes are easy and better to use for implementing any listener interfaces. But, I have recently read in an article that:
"...The example code above uses anonymous classes for simplicity in understanding but practically anonymous classes should not be used for listeners."
What are the side-effects of using any anonymous class?
Thanks,
Kalyan.
16 years ago
Hi All,
though it's legal for a Session bean to implement it's component interface (the interface that exposes the business methods), I never got to see anyone doing this. Why is it so? Is it because the EJBObject's methods are also exposed to the client (which are anyway exposed to the client through the stub returned by Home)?
Thanks,
Kalyan.
Can't you use a SessionFacade to combine the two transactions into one single transaction? Something like:
class SessionFacade
{
methodX()
{
if(!methodA())
{
rollbackA();
}

if(!methodB())
{
rollbackA();
rollbackB();
}
}
}
I'm not sure if I really understood your problem. Just a suggestion.
Thanks,
Kalyan.
A Business Delegate is something which wouldn't let you (if you are a client) bother about how complex it is to handle the request. For example, we use it in the following manner:
....
IComponentMaker componentMaker = ComponentMaker.makeComponentMaker();
IJobManager jobManager = (IJobManager)componentMaker.makeComponent("IJobManager");
//create a JobDTO and save it
jobManager.saveJob(jobDTO);
....
Now it's really the 'saveJob's responsibility to interact with the EJB stuff (which is behind the scenes). You, as a client of the BD, wouldn't bother much how all the work is going on behind the scenes. And you, as a provider of BD, will have to take all the pains to get a remote ejbobject, and talk to it (or whatever it takes to save the job).
HTH,
Kalyan.
What's the application server which you are using? Minimum things which you need to know before calling a client are:
1. The JNDI name of the ejb/home
2. The hostname/port of the server
These things are not seen in your code. The hostname/port depends on server to server.
For example:
for weblogic, following code would work:
public class Client
{
private static final String JNDI_NAME = "ejb20-greetingsBean-GreetingsHome";
private String url;
private GreetingsHome home;
public Client(String url) throws NamingException {
this.url = url;
home = lookupHome();
}
public static void main(String[] args) throws Exception {
log("\nBeginning greetingsBean.Client...\n");
String url = "t3://localhost:7001";
Client client = null;
// Parse the argument list
if (args.length != 1) {
log("Usage: java examples.ejb20.basic.greetingsBean.Client t3://hostname ort");
return;
} else {
url = args[0];
}
try {
client = new Client(url);
client.example();
} catch (NamingException ne) {
log("Unable to look up the beans home: " + ne.getMessage());
throw ne;
} catch (Exception e) {
log("There was an exception while creating and using the Greetings.");
log("This indicates that there was a problem communicating with the server: "+e);
throw e;
}
log("\nEnd greetingsBean.Client...\n");
}
public void example()
throws CreateException, RemoteException, RemoveException
{
log("Creating the Greetings");
Greetings greetings = (Greetings) narrow(home.create(), Greetings.class);
System.out.println(greetings.getMessage());

log("Removing the greetings");
greetings.remove();
}
private Object narrow(Object ref, Class c) {
return PortableRemoteObject.narrow(ref, c);
}
private GreetingsHome lookupHome() throws NamingException {
// Lookup the beans home using JNDI
Context ctx = getInitialContext();
try {
Object home = ctx.lookup(JNDI_NAME);
return (GreetingsHome) narrow(home, GreetingsHome.class);
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
log("that you have deployed the ejb with the JNDI name "+
JNDI_NAME+" on the WebLogic server at "+url);
throw ne;
}
}
private Context getInitialContext() throws NamingException {

try {
// Get an InitialContext
Hashtable h = new Hashtable();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
return new InitialContext(h);
} catch (NamingException ne) {
log("We were unable to get a connection to the WebLogic server at "+url);
log("Please make sure that the server is running.");
throw ne;
}
}
private static void log(String s) { System.out.println(s); }

}
HTH,
Kalyan
"Head First EJB" is really a nice book to start with. It really makes you think about what you have read in the previous pages. I've also gone through "Mastering EJB". It's a fantastic resource, but, I still recomment "HFE" to a beginner