com.notuvy.singleapp.SingleApp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of notuvysingleapp Show documentation
Show all versions of notuvysingleapp Show documentation
A simple Java framework for making applications singletons. The underlying mechanism uses interprocess communication to that at most one application process is active at a time. A new application invocation either displaces a previous invocation, or it defers to the previous and terminates itself.
/*
Copyright 2007-2009 Murali Krishnan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.notuvy.singleapp;
import java.io.Serializable;
/**
* An application that want to automatically be managed as a single
* invocation must implement this to be able to use SingleAppEnforcer.
*
* @author murali
*/
public interface SingleApp extends Runnable {
//------------------------------------------------------------
//- Class Variables
//------------------------------------------------------------
//- Class Interface Functions
/**
* Callback to handle the situation where another instance was running
* earlier, and this instance attempted to start but deferred to that.
* This method can contain any logic needed to handle handoff data
* between the two.
*
* @return A serializable object that communicates the handoff from the dying application to the surviving one.
*/
Serializable sendFromDeferred();
/**
* Callback to handle the situation where this instance is running, and
* a second instance attempted to start but deferred to this. This
* method can contain any logic needed to handle handoff data between
* the two.
*
* @param pObject A serializable object that communicates the handoff from the dying application to the surviving one.
*/
void recvFromDeferred(Object pObject);
/**
* Callback to handle the situation where this instance is running, and
* a second instance started and told this one to die.
* This method can contain any logic needed to handle handoff data
* between the two.
*
* @return A serializable object that communicates the handoff from the dying application to the surviving one.
*/
Serializable sendToPreemptor();
/**
* Callback to handle the situation where an earlier instance is running,
* and a this instance started and told it to die.
* This method can contain any logic needed to handle handoff data
* between the two.
*
* @param pObject A serializable object that communicates the handoff from the dying application to the surviving one.
*/
void recvFromPreempted(Object pObject);
/**
* The final hook allowing the preempted application to shutdown
* gracefully.
*/
void gracefulExitForPreempt();
}