JAVA RMI register problem

M

Marzena

Hi
Im making aplication with Java RMI ... everything was working till
yesterday. Today i started to run server and i cant make it :( (once
per 20 times it works)

The way i registering serwer is (im doing this from the folder where i
have my server class and java files + stub ):

start rmiregistry
java -Djava.security.policy=test.policy serwer

Sometimes it works ,sometimes not,espescially when i m starting to run
second diffrent process(serwer)
i got this error:


D:\workspace\serwer2>rmiregistry
java.rmi.server.ExportException: Port already in use: 1099; nested
exception is:

java.net.BindException: Address already in use: JVM_Bind
at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:
310)
at
sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:218
)
at
sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:393)
at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:129)
at
sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:19
0)
at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:92)
at sun.rmi.registry.RegistryImpl.<init>(RegistryImpl.java:78)
at sun.rmi.registry.RegistryImpl.main(RegistryImpl.java:322)
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:97)
at
sun.rmi.transport.proxy.RMIDirectSocketFactory.createServerSocket(RMI
DirectSocketFactory.java:27)
at
sun.rmi.transport.proxy.RMIMasterSocketFactory.createServerSocket(RMI
MasterSocketFactory.java:333)
at
sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:64
9)
at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:
299)
... 7 more

D:\workspace\serwer2>java -Djava.security.policy=test2.policy server
Liczba aktywnych watkow: 1
nazwa watku: main
Usluga druga niezarejestrowana: RemoteException occurred in server
thread; neste
d exception is:
java.rmi.UnmarshalException: error unmarshalling arguments;
nested excep
tion is:
java.lang.ClassNotFoundException: server_Stub

I didnt change anything in my source code...nothing...it just started
doing like this. Lately i was able to run two server process...and
everything was ok.... i was looking for a tip in google...but nothing
help...anybody knows how to fix it?

Tnx .
 
R

Roedy Green

Port already in use: 1099

maybe some other app is also using that port. Seems to me there is a
way to configure a different RMI port, or see if you can see what
other app is using 1099 and move it.
 
E

EJP

Marzena said:
D:\workspace\serwer2>rmiregistry
java.rmi.server.ExportException: Port already in use: 1099; nested
exception is:

java.net.BindException: Address already in use: JVM_Bind

Most probably the registry is already running. netstat will tell you.
 
M

Marzena

No other app is using the same port as rmiregistry... i checked it...

i mean when i want to register one object its working

i run rmiregistry (start rmiregistry)
and run the serwer (java -Djava.security.policy=test.policy serwer)

then i open next command line and doing the same with second object
start rmiregistry
java -Djava.security.policy=test2.policy server

rmiregistry gave me the error that i pasted before
and mine second method (server) doesnt register :|

im confused cause it was working before ...and stopped...i didnt
change the code...
the code which i use in the app server & serwer is :

if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
try {
serwer obj = new serwer();
Naming.rebind("pomiar", obj);
System.out.println("Usluga zarejestrowana");

} catch (Exception e) {
System.out.println("Usluga niezarejestrowana: " +
e.getMessage());
}

I would be greatfull for any tip :(
 
E

EJP

Marzena said:
No other app is using the same port as rmiregistry... i checked it...

On the contrary. *Something* is using it. When you get an error saying
'Port already in use: 1099', it means that port 1099 is already in use.

So how did you check it? Run netstat -an and you'll see that TCP port
1099 is already listening.

As I said before, I suspect you already have the RMI Registry running
and you are trying to start another one. In which case you don't really
have a problem, just ignore the error on the second one.
 
M

Marzena

Ok i fixed the problem... every server RMI need to be bound in rmi
registry running at diffrent port
it is working when i changed it... but i still dont know how did it
work before,when i was doing everything
in one rmiregistry port...anyway thanks for answer :))
 
E

EJP

Marzena said:
Ok i fixed the problem... every server RMI need to be bound in rmi
registry running at diffrent port

Why? Why can't you have one RMI Registry for the entire application?
it is working when i changed it... but i still dont know how did it
work before,when i was doing everything
in one rmiregistry port...anyway thanks for answer :))

Why shouldn't that work?

Your problem seems to be that you want to start a new RMI Registry per
server. You don't have to do that. You only need one per server host.
 
N

Nigel Wade

Marzena said:
Ok i fixed the problem... every server RMI need to be bound in rmi
registry running at diffrent port

Hmm, no it doesn't. The only reason you would require more than one port is if
you have more than one RMI registry. Every RMI server needs to be bound to a
RMI registry, but that registry does not need a different port for each RMI
server. In fact that would defeat the entire purpose of the RMI registry.

The RMI registry is a "global" repository for multiple servers. The point is
that a client only has to make a request to one RMI registry for any particular
service. There really should be only one rmiregistry on each host, unless there
are exceptional circumstances.
 
M

Marzena

I thought the same... but look at my code. Im checking if there is any
rmiregistry if yes i wanna use it...but it doesnt work,i got exception
that smth is already using the port and i cant connect...it was
working before,right now no :( so i used 3 ports to every
application :/


if (System.getSecurityManager() == null)
System.setSecurityManager(
new java.rmi.RMISecurityManager());

java.rmi.registry.Registry reg = null;
try {
reg = java.rmi.registry.LocateRegistry.createRegistry(1099);
System.out.println("Utworzone nowe registry na porcie 1099.");
} catch (Exception e) {
System.out.println("Nie powiodlo sie utworzenie registry.");
System.out.println("Skorzystam z istniejacego.");
}
if (reg == null) {
try {
reg = java.rmi.registry.LocateRegistry.getRegistry();
System.out.println("Skorzystalam z zarejestrowanego registry");
} catch (Exception e) {
System.out.println("Nie moge skorzystac z istniejacego
registry.");
System.exit(0);
}
}
try {
serwer obj = new serwer();
reg.rebind("pomiar", obj);
System.out.println("Us³uga zarejestrowana.");
}
catch (Exception e) {
e.printStackTrace();
}
 
N

Nigel Wade

Marzena said:
I thought the same... but look at my code. Im checking if there is any
rmiregistry if yes i wanna use it...

You attempt to create a registry first. That will always fail on the second and
subsequent attempts because there is already another registry running on that
port.

You should attempt locate a registry first, and if that fails because there is
none, then create one.
but it doesnt work,i got exception
that smth is already using the port and i cant connect...

Your error messages are not in English, so I've no idea what exception you are
actually throwing. You also catch the blanket Exception and don't ever report
what the actual Exception is, or the message it returns, so how can you say
that it reports that something is already using the port? That may be what
*you* are writing to System.out, but it may not bear any relation to the actual
situation. What you need to do is output the actual Exception message and see
what's really going on.
 
E

EJP

Nigel said:
You should attempt locate a registry first, and if that fails because there is
none, then create one.

I agree with everything you said except that. It opens a timing window.
You should try to create it first. If that fails, it must be running, so
you can do the getRegistry(). (In fact you can do the getRegistry()
anyway, and maybe you should). This is a general principle for resource
detection, not just for Registries.

But also in the case of the Registry, LocateRegistry.getRegistry()
doesn't tell you whether the Registry is actually running, it just
synthesizes a stub to that Registrty assuming it exists, which will only
fail when you go to use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top