Skip to content

Instantly share code, notes, and snippets.

@MWhyte
Last active October 14, 2015 18:22
Show Gist options
  • Save MWhyte/4969b259c061aa72cc96 to your computer and use it in GitHub Desktop.
Save MWhyte/4969b259c061aa72cc96 to your computer and use it in GitHub Desktop.
Potential reconnect methods
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7533 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 14.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA 14.app/Contents/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/michaelwhyte/Dropbox/Development/Code/GitHub/MobileServerPOC/ServerPOC/target/test-classes:/Users/michaelwhyte/Dropbox/Development/Code/GitHub/MobileServerPOC/ServerPOC/target/classes:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-configuration-processor/1.2.5.RELEASE/spring-boot-configuration-processor-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/json/json/20140107/json-20140107.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-core/4.1.7.RELEASE/spring-core-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.2.5.RELEASE/spring-boot-starter-web-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter/1.2.5.RELEASE/spring-boot-starter-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot/1.2.5.RELEASE/spring-boot-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.2.5.RELEASE/spring-boot-autoconfigure-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.2.5.RELEASE/spring-boot-starter-logging-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/slf4j/jul-to-slf4j/1.7.12/jul-to-slf4j-1.7.12.jar:/Users/michaelwhyte/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.12/log4j-over-slf4j-1.7.12.jar:/Users/michaelwhyte/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar:/Users/michaelwhyte/.m2/repository/ch/qos/logback/logback-core/1.1.3/logback-core-1.1.3.jar:/Users/michaelwhyte/.m2/repository/org/yaml/snakeyaml/1.14/snakeyaml-1.14.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.2.5.RELEASE/spring-boot-starter-tomcat-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.0.23/tomcat-embed-core-8.0.23.jar:/Users/michaelwhyte/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/8.0.23/tomcat-embed-el-8.0.23.jar:/Users/michaelwhyte/.m2/repository/org/apache/tomcat/embed/tomcat-embed-logging-juli/8.0.23/tomcat-embed-logging-juli-8.0.23.jar:/Users/michaelwhyte/.m2/repository/org/apache/tomcat/embed/tomcat-embed-websocket/8.0.23/tomcat-embed-websocket-8.0.23.jar:/Users/michaelwhyte/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.4.6/jackson-databind-2.4.6.jar:/Users/michaelwhyte/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.4.6/jackson-annotations-2.4.6.jar:/Users/michaelwhyte/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.4.6/jackson-core-2.4.6.jar:/Users/michaelwhyte/.m2/repository/org/hibernate/hibernate-validator/5.1.3.Final/hibernate-validator-5.1.3.Final.jar:/Users/michaelwhyte/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar:/Users/michaelwhyte/.m2/repository/org/jboss/logging/jboss-logging/3.1.3.GA/jboss-logging-3.1.3.GA.jar:/Users/michaelwhyte/.m2/repository/com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-web/4.1.7.RELEASE/spring-web-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-aop/4.1.7.RELEASE/spring-aop-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-beans/4.1.7.RELEASE/spring-beans-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-context/4.1.7.RELEASE/spring-context-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-webmvc/4.1.7.RELEASE/spring-webmvc-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-expression/4.1.7.RELEASE/spring-expression-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter-data-jpa/1.2.5.RELEASE/spring-boot-starter-data-jpa-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter-aop/1.2.5.RELEASE/spring-boot-starter-aop-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/aspectj/aspectjrt/1.8.6/aspectjrt-1.8.6.jar:/Users/michaelwhyte/.m2/repository/org/aspectj/aspectjweaver/1.8.6/aspectjweaver-1.8.6.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/1.2.5.RELEASE/spring-boot-starter-jdbc-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-jdbc/4.1.7.RELEASE/spring-jdbc-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/apache/tomcat/tomcat-jdbc/8.0.23/tomcat-jdbc-8.0.23.jar:/Users/michaelwhyte/.m2/repository/org/apache/tomcat/tomcat-juli/8.0.23/tomcat-juli-8.0.23.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-tx/4.1.7.RELEASE/spring-tx-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/hibernate/hibernate-entitymanager/4.3.10.Final/hibernate-entitymanager-4.3.10.Final.jar:/Users/michaelwhyte/.m2/repository/org/jboss/logging/jboss-logging-annotations/1.2.0.Beta1/jboss-logging-annotations-1.2.0.Beta1.jar:/Users/michaelwhyte/.m2/repository/org/hibernate/hibernate-core/4.3.10.Final/hibernate-core-4.3.10.Final.jar:/Users/michaelwhyte/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar:/Users/michaelwhyte/.m2/repository/org/jboss/jandex/1.1.0.Final/jandex-1.1.0.Final.jar:/Users/michaelwhyte/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar:/Users/michaelwhyte/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar:/Users/michaelwhyte/.m2/repository/org/hibernate/common/hibernate-commons-annotations/4.0.5.Final/hibernate-commons-annotations-4.0.5.Final.jar:/Users/michaelwhyte/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar:/Users/michaelwhyte/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar:/Users/michaelwhyte/.m2/repository/javax/transaction/javax.transaction-api/1.2/javax.transaction-api-1.2.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-orm/4.1.7.RELEASE/spring-orm-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/data/spring-data-jpa/1.7.3.RELEASE/spring-data-jpa-1.7.3.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/data/spring-data-commons/1.9.3.RELEASE/spring-data-commons-1.9.3.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar:/Users/michaelwhyte/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.12/jcl-over-slf4j-1.7.12.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-aspects/4.1.7.RELEASE/spring-aspects-4.1.7.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter-thymeleaf/1.2.5.RELEASE/spring-boot-starter-thymeleaf-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/thymeleaf/thymeleaf-spring4/2.1.4.RELEASE/thymeleaf-spring4-2.1.4.RELEASE.jar:/Users/michaelwhyte/.m2/repository/org/thymeleaf/thymeleaf/2.1.4.RELEASE/thymeleaf-2.1.4.RELEASE.jar:/Users/michaelwhyte/.m2/repository/ognl/ognl/3.0.8/ognl-3.0.8.jar:/Users/michaelwhyte/.m2/repository/org/unbescape/unbescape/1.1.0.RELEASE/unbescape-1.1.0.RELEASE.jar:/Users/michaelwhyte/.m2/repository/nz/net/ultraq/thymeleaf/thymeleaf-layout-dialect/1.2.9/thymeleaf-layout-dialect-1.2.9.jar:/Users/michaelwhyte/.m2/repository/org/flywaydb/flyway-core/3.1/flyway-core-3.1.jar:/Users/michaelwhyte/.m2/repository/org/hsqldb/hsqldb/2.3.2/hsqldb-2.3.2.jar:/Users/michaelwhyte/.m2/repository/javax/mail/mail/1.4.5/mail-1.4.5.jar:/Users/michaelwhyte/.m2/repository/javax/activation/activation/1.1/activation-1.1.jar:/Users/michaelwhyte/.m2/repository/org/springframework/boot/spring-boot-starter-test/1.2.5.RELEASE/spring-boot-starter-test-1.2.5.RELEASE.jar:/Users/michaelwhyte/.m2/repository/junit/junit/4.12/junit-4.12.jar:/Users/michaelwhyte/.m2/repository/org/mockito/mockito-core/1.10.19/mockito-core-1.10.19.jar:/Users/michaelwhyte/.m2/repository/org/objenesis/objenesis/2.1/objenesis-2.1.jar:/Users/michaelwhyte/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/michaelwhyte/.m2/repository/org/hamcrest/hamcrest-library/1.3/hamcrest-library-1.3.jar:/Users/michaelwhyte/.m2/repository/org/springframework/spring-test/4.1.7.RELEASE/spring-test-4.1.7.RELEASE.jar:/Users/michaelwhyte/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar:/Users/michaelwhyte/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.7.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.codenerve.util.RecoveryTest,testRecoveryWithThreads
Connecting to tp
Failed to connect to tp
Trying to reconnect to tp
Connecting to tp
Failed to connect to tp
Trying to reconnect to tp
Connecting to tp
Failed to connect to tp
Trying to reconnect to tp
Connecting to tp
Failed to connect to tp
Process finished with exit code 130
package com.code.util;
public class Recovery {
private long SLEEP_TIME = 3000;
public void connectToTp(){
try {
System.out.println("Connecting to tp");
throw new Exception("up");
} catch (Exception e) {
System.out.println("Failed to connect to tp");
try {Thread.sleep(SLEEP_TIME);} catch (InterruptedException e1) {}
System.out.println("Trying to reconnect to tp");
connectToTp();
}
}
}
package com.code.util;
import org.junit.Before;
import org.junit.Test;
public class RecoveryTest {
private Recovery recovery;
private RecoveryWithThreads recoveryWithThreads;
@Before
public void setup(){
recovery = new Recovery();
recoveryWithThreads = new RecoveryWithThreads();
}
@Test
public void testRecovery() {
recovery.connectToTp();
}
@Test
public void testRecoveryWithThreads() {
recoveryWithThreads.connectToTp();
}
}
package com.code.util;
public class RecoveryWithThreads {
private long SLEEP_TIME = 3000;
public void connectToTp(){
try {
System.out.println("Connecting to tp");
throw new Exception("up");
} catch (Exception e) {
System.out.println("Failed to connect to tp");
new Recover().start();
}
}
private class Recover extends Thread {
public void run(){
while (true) {
try {Thread.sleep(SLEEP_TIME);} catch (InterruptedException e1) {}
System.out.println("Trying to reconnect to tp");
connectToTp();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment