Ubuntu - Run single instance listener

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Ubuntu - Run single instance listener

Ghislain BUGNICOURT-2
Dear all,

Sorry for asking again, but it seems that my previous message (13th of
april) was ignored because somebody answered by asking another question...

I'm trying to correct a strange behavior of imagej on Ubuntu : when
opening several images at the same time while ImageJ isn't started, the
single instance listener (if checked in misc. options) doesn't work and
one instance is started for each image.
If ImageJ is already open, it works well (with imageJ 1.45e)

I can't repeat this on MacOSX, that's why I try to correct the bug. :)

I learned how to compile ImageJ, so I can test any idea of yours, if you
tell me what to modify in the source code !

Ghislain
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

Gluender-4
Ghislain,

in a post to this list dated 12. April 2011 Johannes Schindelin wrote
in response to your request:

"
>  [...] Nevertheless,
>  multiple instances of ImageJ are still launched when i try to open several
>  images at the same time (while ImageJ isn't open yet).
>  Normal or strange behavior ?

Expected. Java needs to start up, then ImageJ, and only then can the
single-instance listener start up. Before that, the other ImageJ instances
have no chance to realize that there is another instance running.

Work-around: start one instance of ImageJ early.

Hth,
Johannes
"


>Dear all,
>
>Sorry for asking again, but it seems that my previous message (13th
>of april) was ignored because somebody answered by asking another
>question...
>
>I'm trying to correct a strange behavior of imagej on Ubuntu : when
>opening several images at the same time while ImageJ isn't started,
>the single instance listener (if checked in misc. options) doesn't
>work and one instance is started for each image.
>If ImageJ is already open, it works well (with imageJ 1.45e)
>
>I can't repeat this on MacOSX, that's why I try to correct the bug. :)
>
>I learned how to compile ImageJ, so I can test any idea of yours, if
>you tell me what to modify in the source code !
>
>Ghislain

HTH
--

                   Herbie

          ------------------------
          <http://www.gluender.de>
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

dscho
In reply to this post by Ghislain BUGNICOURT-2
Dear Ghislain,

On Thu, 28 Apr 2011, Ghislain Bugnicourt wrote:

> Sorry for asking again, but it seems that my previous message (13th of
> april) was ignored because somebody answered by asking another
> question...

Yep, sorry, I also planned to answer, but got side-tracked by the day-job
:-)

> I'm trying to correct a strange behavior of imagej on Ubuntu : when
> opening several images at the same time while ImageJ isn't started, the
> single instance listener (if checked in misc. options) doesn't work and
> one instance is started for each image. If ImageJ is already open, it
> works well (with imageJ 1.45e)
>
> I can't repeat this on MacOSX, that's why I try to correct the bug. :)
>
> I learned how to compile ImageJ, so I can test any idea of yours, if you
> tell me what to modify in the source code !

The first thing would be to find out in which sequence the code is called
that is supposed to check for an existing instance and the code that then
starts listening to the socket.

The code that checks whether there is already a running instance is here:

http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/ImageJ.java;h=a446cac76eaf97f10c1adc01b1e32da3e4fb0c77;hb=imagej#l626

The code to start the socket listener is here:

http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/SocketListener.java;h=f6475b6f3602548dd382823c1ab7e86fc43ce563;hb=imagej#l29

I typically insert some code like IJ.log("Checkpoint 1"); with a running
number so I can identify the places passed. You might also want to turn on
the debug mode by passing ImageJ the -debug option...

Please also note that IJ.log() outputs to the standard error (i.e. the
command-line window you started ImageJ in) as long as there is no instance
of ImageJ itself (i.e. the main window).

Sorry for the delay,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

Ghislain BUGNICOURT-2
Le 28/04/2011 11:29, Johannes Schindelin a écrit :

> Dear Ghislain,
>
> On Thu, 28 Apr 2011, Ghislain Bugnicourt wrote:
>
>> Sorry for asking again, but it seems that my previous message (13th of
>> april) was ignored because somebody answered by asking another
>> question...
> Yep, sorry, I also planned to answer, but got side-tracked by the day-job
> :-)
>
>> I'm trying to correct a strange behavior of imagej on Ubuntu : when
>> opening several images at the same time while ImageJ isn't started, the
>> single instance listener (if checked in misc. options) doesn't work and
>> one instance is started for each image. If ImageJ is already open, it
>> works well (with imageJ 1.45e)
>>
>> I can't repeat this on MacOSX, that's why I try to correct the bug. :)
>>
>> I learned how to compile ImageJ, so I can test any idea of yours, if you
>> tell me what to modify in the source code !
> The first thing would be to find out in which sequence the code is called
> that is supposed to check for an existing instance and the code that then
> starts listening to the socket.
>
> The code that checks whether there is already a running instance is here:
>
> http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/ImageJ.java;h=a446cac76eaf97f10c1adc01b1e32da3e4fb0c77;hb=imagej#l626
>
> The code to start the socket listener is here:
>
> http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/SocketListener.java;h=f6475b6f3602548dd382823c1ab7e86fc43ce563;hb=imagej#l29
>
> I typically insert some code like IJ.log("Checkpoint 1"); with a running
> number so I can identify the places passed. You might also want to turn on
> the debug mode by passing ImageJ the -debug option...
>
> Please also note that IJ.log() outputs to the standard error (i.e. the
> command-line window you started ImageJ in) as long as there is no instance
> of ImageJ itself (i.e. the main window).
>
> Sorry for the delay,
> Johannes

Hi !

Gluender,
Thanks for your response, but I should have given more details.
Johannes and I exchanged several mails (12th of April), and after a few
kind advices he told me I should learn how to compile ImageJ, and then
ask the list again for hints to find the bug.
This is why I sent my message (13th of April), although at the moment I
use the workaround of course !

Johannes,
Thanks for your detailed hints but I'm facing a few problems due to my
lack of confidence with command-line use :
  - I'm not sure about the command to use in a terminal, if I want to
mimic what happens when I select two images and press enter. Is it
{imagej -p 1 ./image1.tif & imagej -p 1 ./image2.tif &} ?
More details : with {imagej image1.tif image2.tif}, only one instance of
imagej opens even if the instance listener isn't checked in the options.
On the contrary, if I open the two images consecutively by the command
line, {imagej ./image1.tif &} and then {imagej ./image2.tif &}, two
instances open ! Except if I use the {-p 1} option of course.
  - I didn't figure out how to pass the {-debug} option to ImageJ from
the terminal. It isn't listed in the {man imagej} page. When I check the
debug option and then close-reopen ImageJ, the debug mode is lost. Normal ?

Regards,
Ghislain
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

dscho
Hi,

On Thu, 28 Apr 2011, Ghislain Bugnicourt wrote:

>  - I'm not sure about the command to use in a terminal, if I want to
>    mimic what happens when I select two images and press enter. Is it
>    {imagej -p 1 ./image1.tif & imagej -p 1 ./image2.tif &} ?

If you add -debug to the -p 1, then you turn on the debug mode. But make
sure that the executable "imagej" really picks up on your recompiled
ij.jar instead of starting the old one.

> When I check the debug option and then close-reopen ImageJ, the debug
> mode is lost. Normal ?

Yes. The debug mode is very verbose. You do not want to switch it on all
the time.

Ciao,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

Ghislain BUGNICOURT-2
Le 28/04/2011 14:20, Johannes Schindelin a écrit :

> Hi,
>
> On Thu, 28 Apr 2011, Ghislain Bugnicourt wrote:
>
>>   - I'm not sure about the command to use in a terminal, if I want to
>>     mimic what happens when I select two images and press enter. Is it
>>     {imagej -p 1 ./image1.tif&  imagej -p 1 ./image2.tif&} ?
> If you add -debug to the -p 1, then you turn on the debug mode. But make
> sure that the executable "imagej" really picks up on your recompiled
> ij.jar instead of starting the old one.
>
>> When I check the debug option and then close-reopen ImageJ, the debug
>> mode is lost. Normal ?
> Yes. The debug mode is very verbose. You do not want to switch it on all
> the time.
>
> Ciao,
> Johannes
>

Thanks Johannes, but I still don't find the way to use the -debug option :
{imagej -debug} tells me the 'd' option isn't allowed and lists other
possible options :

    imagej [options] image [ image2 ... image3 ]
         -h        print help and more options
         -o        open images in an open ImageJ panel
         -p <N>    open images in ImageJ panel number <N>
         -x <MB>   set available memory (default=1500 max=)

I replaced ij.jar by the recompiled one, at least I had no problem with
that. ;)
Ghislain
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

dscho
Hi,

On Thu, 28 Apr 2011, Ghislain Bugnicourt wrote:

> {imagej -debug} tells me the 'd' option isn't allowed and lists other
> possible options :
>
>    imagej [options] image [ image2 ... image3 ]
>         -h        print help and more options
>         -o        open images in an open ImageJ panel
>         -p <N>    open images in ImageJ panel number <N>
>         -x <MB>   set available memory (default=1500 max=)

I am afraid that this means that the imagej executable does not hand
ImageJ options to ImageJ properly. So you need to call ImageJ thusly:

        java -jar ij.jar -debug -port1 <image-file>

Ciao,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

Ghislain BUGNICOURT-2
Le 29/04/2011 10:31, Johannes Schindelin a écrit :
> I am afraid that this means that the imagej executable does not hand
> ImageJ options to ImageJ properly. So you need to call ImageJ thusly:
>
> java -jar ij.jar -debug -port1<image-file>
>
> Ciao,
> Johannes

Hi !

I'm still looking for a way to make the instance listener work with Ubuntu.

I realized that the error obviously stands in the "isRunning(args)"
method in the file ImageJ.java .
Actually, at this line,
     sendArgument("user.dir "+System.getProperty("user.dir"));
an exception is generated. It says :
     java.net.ConnectException: Connection refused
As a result, isRunning always returns "false", with or without arguments
(images or options if I understood well).

It's probably normal, but imagej won't even start if I comment the line.
Changing "user.dir " to "user.dir" has no effect either.
It's all I could try !

What should I do now ?

Regards,
Ghislain
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

dscho
Hi,

On Wed, 4 May 2011, Ghislain Bugnicourt wrote:

> [...] at this line,
>     sendArgument("user.dir "+System.getProperty("user.dir"));
> an exception is generated. It says :
>     java.net.ConnectException: Connection refused

You could try the following:

        try {
                sendArgument("user.dir "+System.getProperty("user.dir"));
        } catch (java.net.ConnectException e) {
                ij.IJ.wait(1000); // wait a sec!
                sendArgument("user.dir "+System.getProperty("user.dir"));
        }

and see whether a delay fixes the problem.

Ciao,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Ubuntu - Run single instance listener

Ghislain BUGNICOURT-2
Le 05/05/2011 10:03, Johannes Schindelin a écrit :

> Hi,
>
> On Wed, 4 May 2011, Ghislain Bugnicourt wrote:
>
>> [...] at this line,
>>      sendArgument("user.dir "+System.getProperty("user.dir"));
>> an exception is generated. It says :
>>      java.net.ConnectException: Connection refused
> You could try the following:
>
> try {
> sendArgument("user.dir "+System.getProperty("user.dir"));
> } catch (java.net.ConnectException e) {
> ij.IJ.wait(1000); // wait a sec!
> sendArgument("user.dir "+System.getProperty("user.dir"));
> }
>
> and see whether a delay fixes the problem.
>
> Ciao,
> Johannes

Hi !
Still doesn't work :(
Just to be sure :
  - I had to replace your "java.net.ConnectException e" by "IOException
e", unless it told be the exception wasn't caught.
  - I tried catching an exception the second time, after the delay, and
it is generated again.
  - I changed the delay up to 4 sec.

I'm dowloading the source code to start again because I already made
many ineffective changes in Imagej.java.

Other ideas ?
Thks for your help !

PS : I am now on Ubuntu 11.04, no difference