aspose file tools*
The moose likes Distributed Java and the fly likes java.rmi.ServerException etc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "java.rmi.ServerException etc" Watch "java.rmi.ServerException etc" New topic
Author

java.rmi.ServerException etc

chetan raj
Ranch Hand

Joined: Jul 18, 2006
Posts: 34
I have an application say app1 which interact with app2,app3,app4 etc using rmi technology.
Know i am intergrating some code in my app1 such that it interacting with
my application say app5 using jini Technology. My requirement is that app2,app3,app4 etc interact with my app1 using rmi. And my app5 should interact with my app1 using jini. App1 acts as a server for all other applicatins.
when i am trying to call some method from app1 to app5 using jini i am getting the fallowing errors.
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: invalid method hash
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
at com.mantragroup.rmi.CauserieToProtocolImpl_Stub.connect(Unknown Source)
at com.mantragroup.rmi.CauserieRMIHandler.connect(CauserieRMIHandler.java:379)
at com.mantragroup.rmi.RMIProtocol.connect(RMIProtocol.java:88)
at com.mantragroup.session.Session$1.run(Session.java:282)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.rmi.UnmarshalException: invalid method hash
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: invalid method hash
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
at com.mantragroup.rmi.CauserieToProtocolImpl_Stub.connect(Unknown Source)
at com.mantragroup.rmi.CauserieRMIHandler.connect(CauserieRMIHandler.java:379)
at com.mantragroup.rmi.RMIProtocol.connect(RMIProtocol.java:88)
at com.mantragroup.session.Session$1.run(Session.java:282)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.rmi.UnmarshalException: invalid method hash
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Do the reciever and sender have different versions of the class? Looks like one is calling the "connect" method on another and for some reason that method doesn't "exist" where it is being called.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
chetan raj
Ranch Hand

Joined: Jul 18, 2006
Posts: 34
Thanks Nathan for your suggestion . Yes the method in interace and implementation where having different parameter so i was getting that exception and i could correct it from your suggestions.
I need a jini working example where i can bind objects to a known lookup
service using unicast discovery. I have one example but the problem is that
it it not holding object in the lookup service for more than 5 minitues or so.
Can you please send me a link to such example or tutorial.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Could this be because the lease is expiring?
chetan raj
Ranch Hand

Joined: Jul 18, 2006
Posts: 34
Thanks Nathan i understand that it is because of leasing that i am getting
that error.
My requirement is that i want to bind some remote objects on the lookup
service running on my server using unicastint(since i know the address of
the lookup service) For that i have returned a simple thread that does renewal
but even it is not able to bind object in the lookup service for a longer.
I want nonlocal object to bind to my server for ever. what is the best way to
achieve my objective. This is the sample example i am running please point where i am doing mistakes.

public class ProtocolRMIServer implements DiscoveryListener, Runnable
{

/**
* ServerConfig Properties File Name
*/

private Hashtable leases = new Hashtable();
private ServiceItem item; // Item to be registered with lookup
private static final long ltime = Lease.FOREVER;
private static final int mtime = 60*1000*5; // 5 minutes // (minimum renewal)

// The discovery object
private LookupLocatorDiscovery discover=null;
private ServiceRegistration ret;
private LookupLocator[] locators = null;



public ProtocolRMIServer( )throws Exception
{
Entry[] attributes = new Entry[1];
attributes[0] = new Name("MantraGroup");
CauserieToProtocol _ctp =
(CauserieToProtocolImpl)new CauserieToProtocolImpl();
item = new ServiceItem(null, _ctp, attributes);
try {
locators = new LookupLocator[] {new LookupLocator("jini://localhost")};
} catch(MalformedURLException e)
{
e.printStackTrace();
System.exit(1);
}
try {
discover = new LookupLocatorDiscovery(locators);
} catch(Exception e) {
System.err.println(e.toString());
e.printStackTrace();
System.exit(1);
}



discover.addDiscoveryListener(this);
new Thread(this).start();

}
public synchronized void discovered(DiscoveryEvent evt)
{

ServiceRegistrar[] lookup = evt.getRegistrars();
for(int i=0;i<lookup.length;i++)
{
if (leases.containsKey(lookup[i]) == false)
{
//ServiceRegistration ret =lookup[i].register(item, ltime);
try{
ret = lookup[i].register(item, ltime);
if (item.serviceID == null) {
item.serviceID = ret.getServiceID();
System.out.println("the service id is:" + item.serviceID);
//System.out.println("found a service locator:"+i);
}
leases.put(lookup[i], ret);
notify();
}catch(RemoteException re){re.printStackTrace();}
}
}
}


// Automatically called when lookup service(s)
// are no longer available
public synchronized void discarded(DiscoveryEvent dev) {
ServiceRegistrar[] lookup = dev.getRegistrars();
for (int i = 0; i < lookup.length; i++) {
if (leases.containsKey(lookup[i]) == true) {
// Remove the registration. If the lookup service comes
// back later, we'll re-register at that time.
leases.remove(lookup[i]);
}
}
}

public synchronized void run()
{
while (true)
{
long nextRenewal = Long.MAX_VALUE;
long now = System.currentTimeMillis();
Enumeration e = leases.keys();
// Loop to renew all leases that are about to expire
// and also to find the time when the next lease will
// expire so we know when to run the loop again.
while (e.hasMoreElements())
{
ServiceRegistrar lookup=(ServiceRegistrar) e.nextElement();
ServiceRegistration sr =(ServiceRegistration) leases.get(lookup);
Lease l = sr.getLease();
long expire = l.getExpiration();
// See if the current lease has the minimum time.
// If we can't renew it, discard that lookup service.
// That will generate an event to the discarded()
// method, which will actually remove the lease from
// our list.
try {
if (expire <= now + mtime) {
l.renew(ltime);
System.out.println("renew called:");
expire = l.getExpiration();
}
if (nextRenewal > expire - mtime) {
nextRenewal = expire - mtime;
}
} catch (LeaseDeniedException lex) {lex.printStackTrace();
} catch (UnknownLeaseException lex) {
discover.discard(lookup);
} catch (RemoteException ex) {
discover.discard(lookup);
}
}
try {
// Wait until the next renewal time. A new lease
// will notify us in case the new
// lease has a smaller time until it must be renewed
wait(nextRenewal - now);
} catch (InterruptedException ex) {ex.printStackTrace();};
}
}

Is it possble to use LeaseRenewalManager to renew lease for us for ever.
can it be used with unicast discovery. If possible give please give some sample example for unicasting which binds object for ever.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.rmi.ServerException etc