Package megameklab.util
Class SingleInstanceService
java.lang.Object
megameklab.util.SingleInstanceService
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for message handling -
Constructor Summary
ConstructorsConstructorDescriptionSingleInstanceService(String applicationId) Creates a new single instance serviceSingleInstanceService(String applicationId, int port) Creates a new single instance service with specific port -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()Clean up resourcesbooleanCheck if the service is runningbooleanregister()Register this as the primary instancevoidsendMessage(String message) Send a message to the running instancevoidSets a handler for messages from other instances
-
Constructor Details
-
SingleInstanceService
Creates a new single instance service- Parameters:
applicationId- Unique identifier for this application
-
SingleInstanceService
Creates a new single instance service with specific port- Parameters:
applicationId- Unique identifier for this applicationport- Port to use for communication
-
-
Method Details
-
register
public boolean register()Register this as the primary instance- Returns:
- true if this is the first instance, false otherwise
-
sendMessage
Send a message to the running instance- Parameters:
message- Message to send
-
setMessageHandler
Sets a handler for messages from other instances- Parameters:
handler- Handler to process messages
-
cleanup
public void cleanup()Clean up resources -
isRunning
public boolean isRunning()Check if the service is running
-