Hi,
I am currently working on a UserTransaction
for standalone clients.
JTA says that such beast must be
Referenceable and Serializable, so I do that.
Relevant parts of code in package
org.jboss.tm.usertx below:
UserTransaction class used in server and client:
public class ClientUserTransaction
implements UserTransaction,
TransactionPropagationContextFactory,
Referenceable,
java.io.Serializable
{
public Reference getReference()
throws NamingException
{
Reference ref = new Reference(this.getClass().getName(),
"org.jboss.tm.usertx.ClientUserTransactionService",
null);
return ref;
}
...
}
Service class used in server:
public class ClientUserTransactionService
extends ServiceMBeanSupport
implements ClientUserTransactionServiceMBean, ObjectFactory
{
public static String JNDI_NAME = "UserTransaction";
protected void startService()
throws Exception
{
new InitialContext().bind(JNDI_NAME, new ClientUserTransaction(null));
}
public Object getObjectInstance(Object obj, Name name,
Context nameCtx, Hashtable environment)
throws Exception
{
Reference ref = (Reference)obj;
ClientUserTransaction ut = null;
if (ref.getClassName().equals(this.getClass().getName())) {
// create the UserTransaction object
ut = new ClientUserTransaction(new RMIUserTransactionImpl());
}
return ut;
}
...
}
What happens is:
During startService, an instance is bound.
This makes JNP call getReference() on it
and binds this reference.
When the client does ctx.lookup("UserTransaction"),
the object factory is *not* called. (In fact, it
is *never* called.)
Instead of delivering a ClientUserTransaction
instance to the client, JNDI returns a Reference
with the same data as the Reference returned by
the ClientUserTransaction.getReference() call.
Changing the JNDI name to "jnp:/UserTransaction"
does not help.
I am pretty new to JNDI, so I may have
misunderstood something.
If anyone who knows about this can tell
me what I am doing wrong...
Best Regards,
Ole Husgaard.