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
/** | |
* A circuit that accepts re-entrant {@link #open()} and {@link #close()} calls and ensures fairness | |
* when releasing {@link #await() waiting} threads. | |
* | |
* @author Jonathan Halterman | |
*/ | |
public class ReentrantCircuit { | |
private final Sync sync = new Sync(); | |
/** |
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
/** | |
* A waiter where waiting threads can be interrupted (as opposed to awakened). | |
* | |
* @author Jonathan Halterman | |
*/ | |
public class InterruptableWaiter { | |
private final Sync sync = new Sync(); | |
private static final class Sync extends AbstractQueuedSynchronizer { | |
private static final long serialVersionUID = 4016766900138538852L; |
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
import io.dropwizard.Configuration; | |
import io.dropwizard.configuration.ConfigurationFactory; | |
import io.dropwizard.jackson.Jackson; | |
import io.dropwizard.jersey.DropwizardResourceConfig; | |
import io.dropwizard.jersey.jackson.JacksonMessageBodyProvider; | |
import io.dropwizard.logging.LoggingFactory; | |
import io.dropwizard.setup.Environment; | |
import java.io.File; | |
import java.io.FileNotFoundException; |
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
import io.dropwizard.Application; | |
import io.dropwizard.Configuration; | |
import io.dropwizard.cli.ServerCommand; | |
import io.dropwizard.lifecycle.ServerLifecycleListener; | |
import io.dropwizard.setup.Bootstrap; | |
import io.dropwizard.setup.Environment; | |
import io.dropwizard.testing.junit.ConfigOverride; | |
import java.util.Enumeration; |
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
public static <T> T getWithDcl(Supplier<T> supplier, Supplier<T> factory, Object mutex) { | |
T object = supplier.get(); | |
if (object == null) { | |
synchronized (mutex) { | |
object = supplier.get(); | |
if (object == null) { | |
object = factory.get(); | |
} | |
} | |
} |
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
# Usage setjdk 1.8 | |
function setjdk() { | |
if [ $# -ne 0 ]; then | |
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin' | |
if [ -n "${JAVA_HOME+x}" ]; then | |
removeFromPath $JAVA_HOME | |
fi | |
export JAVA_HOME=`/usr/libexec/java_home -v $@` | |
export PATH=$JAVA_HOME/bin:$PATH | |
fi |
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
:cas (timeout 5000 (assoc op :type :info :value :timed-out) | |
(let [cas (reify Function | |
(apply [this, tr] | |
(let [ | |
[value value'] (:value op) | |
key_var (byte-array (map byte key)) | |
old_value (.getLong (Tuple/fromBytes (.get (.get tr (byte-array (map byte key))))) 0) | |
new_value (.pack (Tuple/from (into-array [value'])))] | |
(if (= old_value value) | |
(do |
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
(deftest create-cas-test | |
(let [test (run! | |
(assoc | |
noop-test | |
:name "foundationdb" | |
:os ubuntu/os | |
:db db | |
:client (cas-register) | |
:model (model/cas-register) | |
:checker (checker/compose {:html timeline/html |
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
(defn try-until-success | |
"Accepts a try-fn to try a failure-fn to call upon failure, supplying the failure/exception. The try-fn is retried | |
until no failure is thrown." | |
[try-fn failure-fn] | |
(loop [] | |
(if-let [result (try | |
(try-fn) | |
(catch Exception e | |
(failure-fn e) | |
nil))] |
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
/** | |
* An exponentially weighted moving average implementation that decays based on the elapsed time since the last update, | |
* approximating a time windowed moving average. | |
*/ | |
public class MovingAverage { | |
private final long windowNanos; | |
// Mutable state | |
private volatile long lastNanos; | |
private volatile double average; |
OlderNewer