Skip to content

Commit

Permalink
provide a callback if the DB process crashes (MariaDB4j#63)
Browse files Browse the repository at this point in the history
Merge neelesh work and update CONTRIBUTORS.md

Co-authored-by: Neelesh Shastry <neelesh@marketo.com>
Co-authored-by: William Dutton <will.dutt@gmail.com>
  • Loading branch information
2 people authored and vorburger committed Aug 28, 2018
1 parent cb62994 commit d310215
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ MariaDB4j CONTRIBUTORS
- Josef Andersson @hanklank <josef.andersson@svt.se>, July 2016; for http://www.svt.se
- Leora Pearson @lpearson05 <Leora.Pearson@bazaarvoice.com>, Aug 2016 (http://www.bazaarvoice.com/)
- Carlos Ortiz [@cortiz](http://github.com/cortiz/) <carlos.ortiz@craftersoftware.com>, Jun 2017 [CrafterCMS](http://craftercms.org)
.com/)
- Jai Deep Mulchandani [@jai-deep](https://github.com/jai-deep) <Jaideep.Mulchandani@walmart.com> Jan 2018; for http://walmartlabs.com
- Lukasz Degus [@lde-avaleo] <lde@avaleo.net>, Jan 2018
- Andrew Groot [@thesquaregroot](https://github.com/thesquaregroot) <groot@softwareverde.com>, June 2018; for https://softwareverde.com
- Yftach Zur [@yiftizur](https://github.com/yiftizur), June 2018; for MariaDB4jRule for easy integration with JUnit
- William Dutton [@duttonw](https://github.com/duttonw)<will.dutt@gmail.com>, June 2018; for mariaDB4j-maven-plugin integration testing of micro services under services.qld.gov.au
- William Dutton [@duttonw](https://github.com/duttonw) <will.dutt@gmail.com>, June 2018; for mariaDB4j-maven-plugin integration testing of micro services under services.qld.gov.au
- Mike Chaberski [@mike10004](https://github.com/mike10004), May 2017; initial [mariadb4j-maven-plugin](https://github.com/mike10004/mariadb4j-maven-plugin) incorporated to improve mariaDB4j-maven-plugin
- Yuexiang Gao [@kbyyd24](https://github.com/kbyyd24) <melo@gaoyuexiang.cn> (http://blog.gaoyuexiang.cn), August 2018; for mariaDB4j-springboot auto-configure with spring boot
- Neelesh Shastry [@neeleshs](https://github.com/neeleshs), Dec 2017 Provide a callback if the DB process crashes
- also see https://github.com/vorburger/MariaDB4j/graphs/contributors

Contributions, patches, forks more than welcome - hack it, and add your name here! ;-)
4 changes: 4 additions & 0 deletions mariaDB4j-core/src/main/java/ch/vorburger/mariadb4j/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ protected void run(String logInfoText, InputStream fromIS, String username, Stri
addSocketOrPortArgument(builder);
if (fromIS != null)
builder.setInputStream(fromIS);
if (this.configuration.getProcessListener() != null) {
builder.setProcessListener(this.configuration.getProcessListener());
}

ManagedProcess process = builder.build();
process.start();
process.waitForExit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package ch.vorburger.mariadb4j;

import ch.vorburger.exec.ManagedProcessListener;

import java.util.List;
import java.util.function.Function;

Expand Down Expand Up @@ -64,6 +66,12 @@ public interface DBConfiguration {

String getOSLibraryEnvironmentVarName();

/**
*
* @return Process callback when DB process is killed or is completed
*/
ManagedProcessListener getProcessListener();

/** Whether to to "--skip-grant-tables". */
boolean isSecurityDisabled();

Expand All @@ -81,12 +89,13 @@ static class Impl implements DBConfiguration {
private final boolean isWindows;
private final List<String> args;
private final String osLibraryEnvironmentVarName;
private final ManagedProcessListener listener;
private final boolean isSecurityDisabled;
private final Function<String, String> getURL;

Impl(int port, String socket, String binariesClassPathLocation, String baseDir, String libDir, String dataDir,
boolean isWindows, List<String> args, String osLibraryEnvironmentVarName, boolean isSecurityDisabled,
boolean isDeletingTemporaryBaseAndDataDirsOnShutdown, Function<String, String> getURL) {
boolean isDeletingTemporaryBaseAndDataDirsOnShutdown, Function<String, String> getURL, ManagedProcessListener listener) {
super();
this.port = port;
this.socket = socket;
Expand All @@ -100,6 +109,7 @@ static class Impl implements DBConfiguration {
this.osLibraryEnvironmentVarName = osLibraryEnvironmentVarName;
this.isSecurityDisabled = isSecurityDisabled;
this.getURL = getURL;
this.listener = listener;
}

@Override
Expand Down Expand Up @@ -161,6 +171,11 @@ public boolean isSecurityDisabled() {
public String getURL(String dbName) {
return getURL.apply(dbName);
}

@Override
public ManagedProcessListener getProcessListener() {
return listener;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.List;

import ch.vorburger.exec.ManagedProcessListener;
import org.apache.commons.lang3.SystemUtils;

/**
Expand Down Expand Up @@ -54,6 +55,7 @@ public class DBConfigurationBuilder {
private boolean isSecurityDisabled = true;

private boolean frozen = false;
private ManagedProcessListener listener;

public static DBConfigurationBuilder newBuilder() {
return new DBConfigurationBuilder();
Expand Down Expand Up @@ -115,6 +117,16 @@ public DBConfigurationBuilder setPort(int port) {
return this;
}

/**
* Set a custom process listener to listen to DB start/shutdown events
* @param listener custom listener
* @return this
*/
public DBConfigurationBuilder setProcessListener(ManagedProcessListener listener) {
this.listener = listener;
return this;
}

public boolean isDeletingTemporaryBaseAndDataDirsOnShutdown() {
return isDeletingTemporaryBaseAndDataDirsOnShutdown;
}
Expand Down Expand Up @@ -157,8 +169,8 @@ public DBConfigurationBuilder setSocket(String socket) {
public DBConfiguration build() {
frozen = true;
return new DBConfiguration.Impl(_getPort(), _getSocket(), _getBinariesClassPathLocation(), getBaseDir(), getLibDir(), _getDataDir(),
WIN32.equals(getOS()), _getArgs(), _getOSLibraryEnvironmentVarName(), isSecurityDisabled(),
isDeletingTemporaryBaseAndDataDirsOnShutdown(), this::getURL);
WIN32.equals(getOS()), _getArgs(), _getOSLibraryEnvironmentVarName(), isSecurityDisabled(),
isDeletingTemporaryBaseAndDataDirsOnShutdown(), this::getURL, _getManagedProcessListener());
}

/**
Expand Down Expand Up @@ -270,6 +282,11 @@ protected String _getBinariesClassPathLocation() {
return null; // see ch.vorburger.mariadb4j.DB.unpackEmbeddedDb()
}

protected ManagedProcessListener _getManagedProcessListener() {
return listener;
}


public boolean isUnpackingFromClasspath() {
return isUnpackingFromClasspath;
}
Expand Down

0 comments on commit d310215

Please sign in to comment.