dmdealmeida / matlabcontrol

Automatically exported from code.google.com/p/matlabcontrol
0 stars 0 forks source link

Multiple matlab-control applications on a single machine share the same RMI Registry #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What version of matlabcontrol are you using?
4.1.0

What version of MATLAB are you using?
2009a (7.8.0.347)

What operating system are you using?
Windows 7 / Centos 6.4

Are you using matlabcontrol from inside MATLAB or outside MATLAB?
outside

What steps will reproduce the problem?
1. Run the following program. Call this R1.
2. Whilst R1 is still running, launch R1 again. Call this R2.
3. Allow R2 to run once.
4. Kill R1.
5. Subsequent attempts to launch matlabcontrol in R2 will fail with an rmi 
ConnectException.

public class MatlabControlExample {

    public static void main(String[] args) {
        final MatlabProxyFactory matlabProxyFactory = new MatlabProxyFactory();

        final String command = "disp('hello world!')";
        Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("Invoking " + command);
                MatlabProxy proxy = null;
                try {
                    proxy = matlabProxyFactory.getProxy();
                    proxy.eval(command);
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    System.exit(-1);
                } finally {
                    try {
                        if (proxy != null) {
                            proxy.exit();
                        }
                    } catch (MatlabInvocationException e) {
                        e.printStackTrace(System.out);
                        System.exit(-1);
                    }
                }
            }
        }, 0L, 1L, TimeUnit.MINUTES);
    }
}

What did you expect to happen? What happened instead?
I expected R2 to continue running successfully (i.e. that no dependency existed 
between independently running VMs).

If there was a stack trace, please copy it here.
matlabcontrol.MatlabConnectionException: Could not bind proxy receiver to the 
RMI registry
    at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:104)
    at matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:144)
    at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
    at gsa.playpen.MatlabControlExample$1.run(MatlabControlExample.java:30)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.rmi.ConnectException: Connection refused to host: localhost; 
nested exception is: 
    java.net.ConnectException: Connection refused
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
    at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:99)
    ... 12 more
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.connect(Socket.java:478)
    at java.net.Socket.<init>(Socket.java:375)
    at java.net.Socket.<init>(Socket.java:218)
    at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:212)
    at matlabcontrol.LocalHostRMIHelper$LocalHostRMISocketFactory.createSocket(LocalHostRMIHelper.java:71)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
    ... 17 more

Please provide any additional information below.
This can be avoided by altering the port used when the RMI registry is created, 
so as to ensure the port is unique to the running process.

Original issue reported on code.google.com by rakeshka...@gmail.com on 10 Jun 2013 at 2:19

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Could not bind proxy receiver to the RMI registry 
  -> i get the same problem. solved this by: unbind if error occured und bind new one :) this work fine for me :)

Original comment by Aleksej.Turko@googlemail.com on 15 Jan 2015 at 10:25

GoogleCodeExporter commented 9 years ago
Hi Aleksej,
I get the same problem by trying to establish a connection for the second time.
What exactly do you mean by unbind? (So which code would you enter?)
Thank you very much for your help,
Robin

Original comment by robin.fa...@googlemail.com on 4 Feb 2015 at 6:21

GoogleCodeExporter commented 9 years ago
Hey ,
I am getting same error when a matlab function is invoked from java.
Could you please tell me how to unbind and bind again.

Original comment by sonam.fg...@gmail.com on 2 Jul 2015 at 11:38