Skip to main content



      Home
Home » Archived » Eclipse Communications Framework (ECF) » Re: Detect if RCP application is already running
Re: Detect if RCP application is already running [message #619769] Thu, 25 October 2007 09:57 Go to next message
Eclipse UserFriend
I thought I'd copy the ECF group on this one -

I was wondering if the ECF already provides anything to solve this problem? Basically what I'm
looking for is - I have an association set in the Windows registry between a file extension and my
RCP application, so that when a user double clicks on a file in the Windows file system it will
launch my RCP application and open the file within it. But what i need is if the RCP application is
already running that the double-clicked file would then be opened in that already running instance.


Peter Centgraf posted this in the meantime as a solution:
> Personally, I would take a slightly different approach, using a single executable.
>
> 1. Pass in files to open as options on the command line. I assume you're doing this already,
since I don't think there's any other way in Windows or Unix.
>
> 2. In your IApplication startup code, check for an open TCP port on localhost. You must define
this custom port # somewhere.
>
> 3a. If nothing is listening on the port, this instance of the app is the only one. Spawn a
background thread to listen on that port here, then continue starting your app. Handle the file
arguments as appropriate.
>
> 3b. From the background thread you've just created, listen for new files and open them as
appropriate.
>
> 4. If something is listening on the port, it's another instance of your app. Send it the file
arguments and exit.
>
> Since you're getting the file paths as command-line arguments, they are just Strings. This is
about the easiest TCP code possible. Plus, the TCP API handles concurrency and warns you if
delivery fails. The file messaging mechanism has no feedback channel and difficult locking issues.
>
> Be aware that Mac OS X has a built-in mechanism for telling a running application about files to
open. Once upon a time, I tried to write the Carbon API code to make this work in SWT, but I never
finished it. You'll need to do some digging to find a solution for the Mac. For example, Azureus
uses a native Cocoa app (running in the background) to get the event, and forwards the filenames to
the Java app via TCP.
>
> --
> Peter


Conor O'Mahony wrote:
> Thanks for that Tom, I will have a look at the ECF stuff.
>
> Just so I understand what you're saying, instead of associating my
> .project file with my RCP application executable in the Windows
> registry, I would associate it with a utility program that checks the
> running processes to see if the RCP executable is already running? If I
> used your simplest case described below where there is a file that both
> applications can read/write to, how would I determine from my RCP app
> that the file has changed? Would i have to "listen" to the file from
> within my RCP app in some way, and then if the utility program changes
> it by for example writing in the filename of the double clicked project,
> i could then open that project within my RCP application?
>
> Tom Schindl wrote:
>> Hi,
>>
>> I would solve this with 2 applications:
>> - The Standard RCP - Application
>> - A Small Utitilty Programm used inform the Standard RCP to open a
>> speficied file (it checks infront of if the RCP is running)
>>
>> The only thing you have to solve then is to communication between
>> these 2 programms. In the simplest case you use a File both
>> applications have read/write access to (you need to flock those
>> naturally :-) or a TCP-Port opened on your application the utility
>> connects to.
>>
>> Maybe the ECF-Project already provides something you can reuse here?
>>
>> Tom
>>
>> Conor O'Mahony schrieb:
>>> Thanks for the reply Tom.
>>>
>>> Do you know if it is possible to access the application that is
>>> previously running? Like if I can detect that there is already an
>>> instance running by checking for the lock file, can i then access
>>> that instance? It would be for the purpose of opening a double
>>> clicked project file in an application that is already running
>>> instead of creating a new application.
>>>
>>> Tom Schindl wrote:
>>>> Eclipse writes a .lock-File in the %workspace%/.metadata, you can
>>>> check for it in IApplication#start(IApplicationContext).
>>>>
>>>> Tom
>>>>
>>>> Conor O'Mahony schrieb:
>>>>> Hi,
>>>>>
>>>>> Apologies for cross posting but I meant to include the
>>>>> eclipse.platform group on the original posting. Does anyone know if
>>>>> there is any mechanism for the below in eclipse?
>>>>>
>>>>> Many thanks,
>>>>>
>>>>> Conor O'Mahony wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I have an RCP application that edits and saves project files to
>>>>>> the file system. There is also a file association in the Windows
>>>>>> Registry between the project file on the file system and the RCP
>>>>>> executable so that whenever I click on a project file in Windows
>>>>>> Explorer, it launches my RCP application. My question is, when i
>>>>>> double click on a project file in the file system to open it, how
>>>>>> can i detect from within my RCP application if there is an
>>>>>> instance of the application already running (and therefore open
>>>>>> the project file within that instance)???
>>>>>>
>>>>>> Many thanks,
>>>>>> Conor
>>>>
>>>>
>>
>>
Re: Detect if RCP application is already running [message #619778 is a reply to message #619769] Sun, 28 October 2007 22:04 Go to previous message
Eclipse UserFriend
Hi Conor,

ECF does have an IContainerManager, which is a process-wide manager for
all ECF IContainer instances since org.eclipse.ecf bundle (where
IContainerManager service lives) is a singleton bundle.

Unfortunately, this doesn't get you to the point of starting/reopening
an existing RCP process.

Scott

Conor O'Mahony wrote:
> I thought I'd copy the ECF group on this one -
>
> I was wondering if the ECF already provides anything to solve this
> problem? Basically what I'm looking for is - I have an association set
> in the Windows registry between a file extension and my RCP application,
> so that when a user double clicks on a file in the Windows file system
> it will launch my RCP application and open the file within it. But what
> i need is if the RCP application is already running that the
> double-clicked file would then be opened in that already running instance.
>
>
> Peter Centgraf posted this in the meantime as a solution:
> > Personally, I would take a slightly different approach, using a
> single executable.
> >
> > 1. Pass in files to open as options on the command line. I assume
> you're doing this already, since I don't think there's any other way in
> Windows or Unix.
> >
> > 2. In your IApplication startup code, check for an open TCP port on
> localhost. You must define this custom port # somewhere.
> >
> > 3a. If nothing is listening on the port, this instance of the app is
> the only one. Spawn a background thread to listen on that port here,
> then continue starting your app. Handle the file arguments as appropriate.
> >
> > 3b. From the background thread you've just created, listen for new
> files and open them as appropriate.
> >
> > 4. If something is listening on the port, it's another instance of
> your app. Send it the file arguments and exit.
> >
> > Since you're getting the file paths as command-line arguments, they
> are just Strings. This is about the easiest TCP code possible. Plus,
> the TCP API handles concurrency and warns you if delivery fails. The
> file messaging mechanism has no feedback channel and difficult locking
> issues.
> >
> > Be aware that Mac OS X has a built-in mechanism for telling a running
> application about files to open. Once upon a time, I tried to write the
> Carbon API code to make this work in SWT, but I never finished it.
> You'll need to do some digging to find a solution for the Mac. For
> example, Azureus uses a native Cocoa app (running in the background) to
> get the event, and forwards the filenames to the Java app via TCP.
> >
> > --
> > Peter
>
>
> Conor O'Mahony wrote:
>> Thanks for that Tom, I will have a look at the ECF stuff.
>>
>> Just so I understand what you're saying, instead of associating my
>> .project file with my RCP application executable in the Windows
>> registry, I would associate it with a utility program that checks the
>> running processes to see if the RCP executable is already running? If
>> I used your simplest case described below where there is a file that
>> both applications can read/write to, how would I determine from my RCP
>> app that the file has changed? Would i have to "listen" to the file
>> from within my RCP app in some way, and then if the utility program
>> changes it by for example writing in the filename of the double
>> clicked project, i could then open that project within my RCP
>> application?
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> I would solve this with 2 applications:
>>> - The Standard RCP - Application
>>> - A Small Utitilty Programm used inform the Standard RCP to open a
>>> speficied file (it checks infront of if the RCP is running)
>>>
>>> The only thing you have to solve then is to communication between
>>> these 2 programms. In the simplest case you use a File both
>>> applications have read/write access to (you need to flock those
>>> naturally :-) or a TCP-Port opened on your application the utility
>>> connects to.
>>>
>>> Maybe the ECF-Project already provides something you can reuse here?
>>>
>>> Tom
>>>
>>> Conor O'Mahony schrieb:
>>>> Thanks for the reply Tom.
>>>>
>>>> Do you know if it is possible to access the application that is
>>>> previously running? Like if I can detect that there is already an
>>>> instance running by checking for the lock file, can i then access
>>>> that instance? It would be for the purpose of opening a double
>>>> clicked project file in an application that is already running
>>>> instead of creating a new application.
>>>>
>>>> Tom Schindl wrote:
>>>>> Eclipse writes a .lock-File in the %workspace%/.metadata, you can
>>>>> check for it in IApplication#start(IApplicationContext).
>>>>>
>>>>> Tom
>>>>>
>>>>> Conor O'Mahony schrieb:
>>>>>> Hi,
>>>>>>
>>>>>> Apologies for cross posting but I meant to include the
>>>>>> eclipse.platform group on the original posting. Does anyone know
>>>>>> if there is any mechanism for the below in eclipse?
>>>>>>
>>>>>> Many thanks,
>>>>>>
>>>>>> Conor O'Mahony wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have an RCP application that edits and saves project files to
>>>>>>> the file system. There is also a file association in the Windows
>>>>>>> Registry between the project file on the file system and the RCP
>>>>>>> executable so that whenever I click on a project file in Windows
>>>>>>> Explorer, it launches my RCP application. My question is, when i
>>>>>>> double click on a project file in the file system to open it, how
>>>>>>> can i detect from within my RCP application if there is an
>>>>>>> instance of the application already running (and therefore open
>>>>>>> the project file within that instance)???
>>>>>>>
>>>>>>> Many thanks,
>>>>>>> Conor
>>>>>
>>>>>
>>>
>>>
Previous Topic:opening the 2.0 floodgates
Next Topic:ECF beginners question (use cases, security, performance, documentation)
Goto Forum:
  


Current Time: Wed May 14 18:15:30 EDT 2025

Powered by FUDForum. Page generated in 0.02919 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top