Created
March 16, 2017 20:41
-
-
Save dunnousername/45a29b27743022ba0c1e8d5e5473d9c9 to your computer and use it in GitHub Desktop.
Beginning of the "MPVM" project... (does not run yet, so can't post in repo)
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
package me.dunnousername.mpvm; | |
import com.google.common.util.concurrent.SimpleTimeLimiter; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* Created by dunnousername on 3/16/17. | |
*/ | |
public class Execute { | |
public static final long TIME_NS = 2000000; | |
public Execute(String code) { | |
SimpleTimeLimiter simpleTimeLimiter = new SimpleTimeLimiter(); | |
MPVMError mpvmError = null; | |
try { | |
mpvmError = simpleTimeLimiter.callWithTimeout(new ExecuteCallable(code), TIME_NS, TimeUnit.NANOSECONDS, true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
success = false; | |
} | |
if (mpvmError == null) { | |
success = false; | |
} | |
if (mpvmError.getErrorType() == MPVMEnumError.NONE) { | |
success = true; | |
} else { | |
success = false; | |
error = mpvmError; | |
} | |
} | |
public boolean success = false; | |
public MPVMError error = new MPVMError(MPVMEnumError.NONE, 1); | |
private class ExecuteCallable implements Callable<MPVMError> { | |
private String code; | |
public ExecuteCallable(String code) { | |
this.code = code; | |
} | |
@Override | |
public MPVMError call() throws Exception { | |
return Execute._Execute(this.code); | |
} | |
} | |
protected static MPVMError _Execute(String code) { | |
/* Would be better if it actually did something... */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment