Created
June 8, 2013 12:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.lang.Validate; | |
public class Restarter { | |
private final IMessagingClient messagingClient; | |
private Status status; | |
public Restarter(IMessagingClient client) { | |
Validate.notNull(client, "Messaging client must be specified"); | |
this.messagingClient = client; | |
} | |
public void restart(Status newStatus) { | |
if (isTransistionFromFailureToStarted(newStatus)) { | |
messagingClient.stop(); | |
messagingClient.start(); | |
} | |
} | |
private boolean isTransistionFromFailureToStarted(Status newStatus) { | |
if (null == status) { | |
status = newStatus; | |
return false; | |
} | |
if (Status.FAILED == newStatus) { | |
status = newStatus; | |
} | |
boolean isTransitionFromFailure = (Status.FAILED == status) && (Status.STARTED == newStatus); | |
if (isTransitionFromFailure) { | |
status = newStatus; | |
} | |
return isTransitionFromFailure; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment