This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #546 from sonatype/NXCM-4643-shutdown-helper
Add ShutdownHelper so we can delegate std-java or jsw implementations to...
- Loading branch information
Showing
7 changed files
with
113 additions
and
6 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
66 changes: 66 additions & 0 deletions
66
nexus/nexus-bootstrap/src/main/java/org/sonatype/nexus/bootstrap/ShutdownHelper.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,66 @@ | ||
/** | ||
* Sonatype Nexus (TM) Open Source Version | ||
* Copyright (c) 2007-2012 Sonatype, Inc. | ||
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, | ||
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. | ||
* | ||
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks | ||
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the | ||
* Eclipse Foundation. All other trademarks are the property of their respective owners. | ||
*/ | ||
package org.sonatype.nexus.bootstrap; | ||
|
||
/** | ||
* Helper to cope with different mechanisms to shtudown. | ||
* | ||
* @since 2.2 | ||
*/ | ||
public class ShutdownHelper | ||
{ | ||
public static interface ShutdownDelegate | ||
{ | ||
void doExit(int code); | ||
|
||
void doHalt(int code); | ||
} | ||
|
||
public static class JavaShutdownDelegate | ||
implements ShutdownDelegate | ||
{ | ||
@Override | ||
public void doExit(final int code) { | ||
System.exit(code); | ||
} | ||
|
||
@Override | ||
public void doHalt(final int code) { | ||
Runtime.getRuntime().halt(code); | ||
} | ||
} | ||
|
||
private static ShutdownDelegate delegate = new JavaShutdownDelegate(); | ||
|
||
public static ShutdownDelegate getDelegate() { | ||
if (delegate == null) { | ||
throw new IllegalStateException(); | ||
} | ||
return delegate; | ||
} | ||
|
||
public static void setDelegate(final ShutdownDelegate delegate) { | ||
if (delegate == null) { | ||
throw new NullPointerException(); | ||
} | ||
ShutdownHelper.delegate = delegate; | ||
} | ||
|
||
public static void exit(final int code) { | ||
getDelegate().doExit(code); | ||
} | ||
|
||
public static void halt(final int code) { | ||
getDelegate().doHalt(code); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...s/nexus-bootstrap/src/main/java/org/sonatype/nexus/bootstrap/jsw/JswShutdownDelegate.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,36 @@ | ||
/** | ||
* Sonatype Nexus (TM) Open Source Version | ||
* Copyright (c) 2007-2012 Sonatype, Inc. | ||
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, | ||
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. | ||
* | ||
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks | ||
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the | ||
* Eclipse Foundation. All other trademarks are the property of their respective owners. | ||
*/ | ||
|
||
package org.sonatype.nexus.bootstrap.jsw; | ||
|
||
import org.sonatype.nexus.bootstrap.ShutdownHelper.ShutdownDelegate; | ||
import org.tanukisoftware.wrapper.WrapperManager; | ||
|
||
/** | ||
* JSW {@link ShutdownDelegate}. | ||
* | ||
* @since 2.2 | ||
*/ | ||
public class JswShutdownDelegate | ||
implements ShutdownDelegate | ||
{ | ||
@Override | ||
public void doExit(final int code) { | ||
WrapperManager.stop(code); | ||
} | ||
|
||
@Override | ||
public void doHalt(final int code) { | ||
WrapperManager.stopImmediate(code); | ||
} | ||
} |
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
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
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