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
<project> | |
... | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-jar-plugin</artifactId> | |
... | |
<configuration> | |
<archive> |
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
<project> | |
<build> | |
<plugins> | |
<plugin> | |
<!-- Create the property $buildNumber holding the current Git revision --> | |
<groupId>org.codehaus.mojo</groupId> | |
<artifactId>buildnumber-maven-plugin</artifactId> | |
<version>1.2</version> | |
<executions> | |
<execution> |
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 set backed by a database table */ | |
public class PersistentDatafileSetStraightforward extends AbstractSet<Datafile> { | |
public enum StorageType {Hive, JDBC} | |
public static final String JDBC_URL = "jdbc.url"; | |
public static final String JDBC_USERNAME = "jdbc.username"; | |
public static final String JDBC_PASSWORD = "jdbc.password"; | |
private final Configuration conf; |
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 class PersistentDatafileSetStructured extends AbstractSet<Datafile> { | |
public static enum StorageType {Hive, JDBC}; | |
private final StatementExecutor db; | |
private final String tableName; | |
private final StorageType storageType; | |
private final String selectAll; |
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 class SimpleSingletonBatchJob { | |
private static boolean getLock() { | |
File file = new File(LOCK_DIRECTORY+File.separatorChar+Configuration.getGroupPrefix()); | |
try { | |
return file.createNewFile(); | |
} catch (IOException e) { | |
return false; | |
} | |
} |
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 class RobustSingletonBatchJob { | |
// Note: We could use File.deleteOnExit() but the docs says it is not 100% reliable and recommends to | |
// use java.nio.channels.FileLock; however this code works well enough for us | |
static synchronized boolean getLock() { | |
File file = new File(LOCK_DIRECTORY, StaticConfiguration.getGroupPrefix()); | |
try { | |
// Will try to create path to lockfile if it does not exist. | |
file.getParentFile().mkdirs(); // #1 Create the lock dir if it doesn't exist | |
if (file.createNewFile()) { |
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
class Person (val id: Int) { | |
var infected = false | |
var sick = false | |
var immune = false | |
var dead = false | |
// to complete with simulation logic | |
// [infection progression] | |
} |
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
def randomBelow = ... | |
/** When should the health state change and what to */ | |
class HealthChange(val time: Int, val newHealth: Health) { | |
def immediate = (time == 0) | |
} | |
/** The root of the health hierarchy; the health (i.e. infection) evolves in stages */ | |
sealed abstract class Health(val infectious: Boolean, val visiblyInfectious: Boolean) { | |
def evolve(): Option[HealthChange] // returns None if no further change possibly/expected | |
} |
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
sealed class Health(val infectious: Boolean, val visiblyInfectious: Boolean) { | |
def evolve(implicit randomGenerator: RandomIntGenerator, config: MySimConfig): Option[HealthChange] = | |
this match { | |
case Healthy => | |
if (randomGenerator.randomBelow(101) <= config.transmissibilityPct) | |
Some(new HealthChange(0, Incubatious)) | |
else None | |
case Incubatious => | |
Some(new HealthChange(6, Sick)) |
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
// P.S.: Excuse the underscores ... | |
class Person (val id: Int) { | |
// Simplified primitive version, assuming the information when should the evolution | |
// happen is handled somewhere else | |
def evolveHealth(): Unit = { | |
if (!_infected) | |
if (randomGenerator.randomBelow(101) <= config.transmissibilityPct) | |
this._infected = true | |
if (_infected && !_sick && !_immune) |