|
java-gnome version 4.0.19 | ||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Objectorg.freedesktop.bindings.Pointer
org.freedesktop.bindings.Proxy
org.gnome.glib.Object
org.gnome.unique.Application
public class Application
Facilities for ensuring that only one unique instance of an application is running.
The basic algorithm is to create an Application instance with the unique name corresponding to your prgram, and then check to see if there is another already running. If so, then there is no need for this instance and it should terminate.
app = new Application("com.example.Program", null); if (app.isRunning()) { System.exit(1); }
There is a message-passing facility built into LibUnique which allows you to send basic commands to the other running instance before you terminate this one.
app.sendMessage(Command.ACTIVATE, null);
Keep in mind that this is not really meant as a generic all-powerful n to m interprocess communication mechanism. In fact, the entire LibUnique library is mostly about ensuring you only have one master copy of an application running. But once you've established that, the messaging subsystem can be used to convey simple requests to of that unique instance.
Nested Class Summary | |
---|---|
static interface |
Application.MessageReceived
The signal emitted when another instance sends a message to the unique instance. |
Constructor Summary | |
---|---|
Application(String name,
String id)
Construct an Application object for the specified unique service. |
Method Summary | |
---|---|
void |
connect(Application.MessageReceived handler)
Hookup a Application.MessageReceived handler. |
String |
getName()
Get the application name that was used when this Application was constructed. |
boolean |
isRunning()
Is some other instance of this program (ie the application with this name) already running? |
Response |
sendMessage(Command cmd,
MessageData data)
Send a message to the other instance (assuming there is one). |
Methods inherited from class org.freedesktop.bindings.Pointer |
---|
toString |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Application(String name, String id)
By convention, the name chosen to identify a unique application should follow the application naming conventions used by DBus (these are similar to the domain name -esque conventions used in Java package space). Some examples are:
"org.gnome.Nautilus"
"org.gnome.Vino.Preferences"
"com.operationaldynamics.Slashtime"
Method Detail |
---|
public void connect(Application.MessageReceived handler)
Application.MessageReceived
handler.
public String getName()
public boolean isRunning()
If so, then really you probably want to be terminating this program. If not, then carry on with your normal application initialization and start-up.
public Response sendMessage(Command cmd, MessageData data)
This method blocks.
If you have specific information to convey to the other instance, you can create a MessageData object and set its payload accordingly. You can also create custom Commands through subclassing, although that's rarely necessary.
You can get a number of reponses back from the other instance. You
should reasonably expect OK
. Indeed, if it's not ok
there isn't much you can do about it.
|
![]() java-gnome |
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |