rmi

Java RMI - Client Timeout

◇◆丶佛笑我妖孽 提交于 2019-11-26 11:07:27
问题 I\'m building a Distributed System using Java RMI and it must support a server loss. If my client is connected to a Server using RMI, if this server goes down (cable problems for example), my client should get an exception so it can connect to other server. But when the server goes down, nothing happens to my client, he keeps waiting for the reply. How can I set a timeout for that? 回答1: For socket read timeout, you can set your own factory like this, RMISocketFactory.setSocketFactory( new

java RMI 远程调用

和自甴很熟 提交于 2019-11-26 10:35:15
1.背景 在学习代理模式的过程中接触到了远程调用,jdk有自己的RMI实现,所以这边自己实现了RMI远程调用,并记录下心得. 感受最深的是RMI和现在的微服务有点相似,都是通过"注册中心"来获取数据,比如spring cloud 中通过feign来获取数据,这个就可以看作一个代理模式,我们通过feigh获取数据其实是通过别的服务器上的代码来获取数据的,而RMI中是通过rmiRegistry注册中心来注册,并且通过 Naming.lookup("rmi://127.0.0.1/RemoteHello") 这个方法来获取数据. 其实本质都差不多,spring cloud 数据传输格式主要是 json, 而 RMI主要是二进制,因为要传输的对象都实现了Serializable接口. 可能RMI在分布式这边用的多一些吧,但是我没有接触过,还不清楚. 2.代码实现 这边有点坑,因为一直用eclipse编译代码,都忘记了cmd命令行怎么编译了,结果被包名给搞糊涂了,这边记录总结下,希望有人碰到这个问题不要在纠结太久. 我们先定义自己的远程接口MyRemote package state.remote; import java.rmi.Remote; import java.rmi.RemoteException; public interface MyRemote extends Remote

NullPointerException in invokeLater while running through Java Webstart

和自甴很熟 提交于 2019-11-26 09:42:47
问题 After upgraded from JRE 1.7.0_21 to 1.7.0_25-b15 my application started to throw NullPointerException in SwingUtilities.invokeLater(...) when it is run from Java WebStart. Surprisingly when it is executed as a standalone application (outside JWS), it works great. Here is the top of the stack: Exception in thread \"AWT-EventQueue-2\" java.lang.NullPointerException at sun.awt.SunToolkit.getSystemEventQueueImplPP(SunToolkit.java:1011) at sun.awt.SunToolkit.getSystemEventQueueImplPP(SunToolkit

What port is used by Java RMI connection?

别来无恙 提交于 2019-11-26 09:37:48
问题 May I know what port is used by Java RMI connection? If I want to connect a Java client application to a Java server application using RMI connection, what port I need to open at the server machine so that the client application can connect to it? I want to set up a firewall in the server machine but I don\'t know which port I should open. 回答1: RMI generally won't work over a firewall, since it uses unpredictable ports (it starts off on 1099, and then runs off with a random port after that).

java.rmi.NoSuchObjectException: no such object in table

梦想的初衷 提交于 2019-11-26 09:26:07
问题 I am writing a very simple RMI server, and I am seeing intermittent java.rmi.NoSuchObjectExceptions in the unit tests. I have a string of remote method calls on the same object, and while the first few go through, the later ones will sometimes fail. I am not doing anything to unregister the server object in between. These error do not appear always, and if I put in breakpoints they tend to not appear. Are those Heisenbugs, whose race conditions dissolve when looking at them through the slowed

How a server can make a session with a client in RMI

心不动则不痛 提交于 2019-11-26 08:31:08
问题 I want someone to tell me where to search for how to make a session between the client(s) and the server in RMI, i.e what is the name of that concept for searching purposes? 回答1: I named this the Remote Session pattern in my 2001 book. The idea is to have a singleton RMI object, bound in the Registry, with nothing but a login() method. That method, if successful, returns a new RemoteSession object for every call, that contains the API you need for the session. RemoteSession is another remote

Why Java opens 3 ports when JMX is configured?

孤街浪徒 提交于 2019-11-26 07:25:16
问题 I run my Java program with JDK7 on Centos6. I enable JMX using the following options: JAVA_OPTS=\"${JAVA_OPTS} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9123 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=true\" When I check what ports are opened I discover 2 additional random ports: netstat -plunt | grep java tcp 0 0 :::9123 :::* LISTEN 13295/java tcp 0 0 :::59927 :::* LISTEN 13295

running rmi server, classnotfound [duplicate]

こ雲淡風輕ζ 提交于 2019-11-26 02:38:06
问题 This question already has an answer here: java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException) 4 answers Hi I\'m trying to run a java application that binds a class to the naming server, but i constantly get a ClassNotFoundException First I start the registry: rmiregistry then from eclipse I try to execute the server but get this error java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException:

java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException)

a 夏天 提交于 2019-11-26 00:29:19
问题 The following method : private void startServer() { // snippet that starts the server on the local machine try { RemoteMethodImpl impl = new RemoteMethodImpl(); Naming.rebind( \"Illusive-Server\" , impl ); }catch(Exception exc) { JOptionPane.showMessageDialog(this, \"Problem starting the server\", \"Error\", JOptionPane.ERROR_MESSAGE); System.out.println(exc); } } throws this exception : java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi