-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
366 additions
and
331 deletions.
There are no files selected for viewing
This file contains 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
74 changes: 74 additions & 0 deletions
74
...ntstore/management/shuttering/observers/CommandHandlerQueueDrainedShutteringExecutor.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package uk.gov.justice.services.eventstore.management.shuttering.observers; | ||
|
||
import static java.lang.String.format; | ||
import static uk.gov.justice.services.management.shuttering.api.ShutteringResult.shutteringFailed; | ||
import static uk.gov.justice.services.management.shuttering.api.ShutteringResult.shutteringSucceeded; | ||
|
||
import uk.gov.justice.services.eventsourcing.util.jee.timer.StopWatchFactory; | ||
import uk.gov.justice.services.eventstore.management.shuttering.process.CommandHandlerQueueInterrogator; | ||
import uk.gov.justice.services.jmx.api.command.SystemCommand; | ||
import uk.gov.justice.services.management.shuttering.api.ShutteringExecutor; | ||
import uk.gov.justice.services.management.shuttering.api.ShutteringResult; | ||
|
||
import java.util.UUID; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.commons.lang3.time.StopWatch; | ||
import org.slf4j.Logger; | ||
|
||
public class CommandHandlerQueueDrainedShutteringExecutor implements ShutteringExecutor { | ||
|
||
@Inject | ||
private CommandHandlerQueueInterrogator commandHandlerQueueInterrogator; | ||
|
||
@Inject | ||
private StopWatchFactory stopWatchFactory; | ||
|
||
@Inject | ||
private Logger logger; | ||
|
||
@Override | ||
public boolean shouldShutter() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ShutteringResult shutter(final UUID commandId, final SystemCommand systemCommand) { | ||
|
||
logger.info("Shuttering Command Handler. Waiting for queue to drain"); | ||
|
||
final StopWatch stopWatch = stopWatchFactory.createStartedStopWatch(); | ||
|
||
try { | ||
final boolean queueEmpty = commandHandlerQueueInterrogator.pollUntilEmptyHandlerQueue(); | ||
|
||
if (queueEmpty) { | ||
|
||
final String message = "Command Handler Queue drained successfully"; | ||
logger.info(message); | ||
|
||
return shutteringSucceeded( | ||
getName(), | ||
commandId, | ||
message, | ||
systemCommand | ||
); | ||
} | ||
|
||
stopWatch.stop(); | ||
|
||
final String message = format("Failed to drain command handler queue in %d milliseconds", stopWatch.getTime()); | ||
logger.error(message); | ||
|
||
return shutteringFailed( | ||
getName(), | ||
commandId, | ||
message, | ||
systemCommand | ||
); | ||
} finally { | ||
stopWatch.stop(); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...ces/eventstore/management/shuttering/observers/PublishQueueDrainedShutteringExecutor.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package uk.gov.justice.services.eventstore.management.shuttering.observers; | ||
|
||
import static java.lang.String.format; | ||
import static uk.gov.justice.services.management.shuttering.api.ShutteringResult.shutteringFailed; | ||
import static uk.gov.justice.services.management.shuttering.api.ShutteringResult.shutteringSucceeded; | ||
|
||
import uk.gov.justice.services.eventsourcing.util.jee.timer.StopWatchFactory; | ||
import uk.gov.justice.services.eventstore.management.shuttering.process.PublishQueueInterrogator; | ||
import uk.gov.justice.services.jmx.api.command.SystemCommand; | ||
import uk.gov.justice.services.management.shuttering.api.ShutteringExecutor; | ||
import uk.gov.justice.services.management.shuttering.api.ShutteringResult; | ||
|
||
import java.util.UUID; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.commons.lang3.time.StopWatch; | ||
import org.slf4j.Logger; | ||
|
||
public class PublishQueueDrainedShutteringExecutor implements ShutteringExecutor { | ||
|
||
@Inject | ||
private PublishQueueInterrogator publishQueueInterrogator; | ||
|
||
@Inject | ||
private StopWatchFactory stopWatchFactory; | ||
|
||
@Inject | ||
private Logger logger; | ||
|
||
@Override | ||
public boolean shouldShutter() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ShutteringResult shutter(final UUID commandId, final SystemCommand systemCommand) { | ||
|
||
logger.info("Waiting for Publish Queue to empty"); | ||
final StopWatch stopWatch = stopWatchFactory.createStartedStopWatch(); | ||
|
||
try { | ||
final boolean queueEmpty = publishQueueInterrogator.pollUntilPublishQueueEmpty(); | ||
|
||
if (queueEmpty) { | ||
final String message = "Publish Queue drained successfully"; | ||
logger.info(message); | ||
|
||
return shutteringSucceeded( | ||
getName(), | ||
commandId, | ||
message, | ||
systemCommand | ||
); | ||
} | ||
|
||
stopWatch.stop(); | ||
|
||
final String message = format("PublishQueue failed to drain after %d milliseconds", stopWatch.getTime()); | ||
|
||
logger.error(message); | ||
|
||
return shutteringFailed( | ||
getName(), | ||
commandId, | ||
message, | ||
systemCommand | ||
); | ||
|
||
} finally { | ||
stopWatch.stop(); | ||
} | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
...ces/eventstore/management/shuttering/observers/PublishQueueDrainedShutteringObserver.java
This file was deleted.
Oops, something went wrong.
60 changes: 0 additions & 60 deletions
60
...ce/services/eventstore/management/shuttering/observers/ShutterCommandHandlerObserver.java
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.