Example usage for com.google.common.base Preconditions checkState

List of usage examples for com.google.common.base Preconditions checkState

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkState.

Prototype

public static void checkState(boolean expression, @Nullable Object errorMessage) 

Source Link

Document

Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.

Usage

From source file:com.opentable.db.postgres.embedded.EmbeddedPostgreSQLRule.java

public EmbeddedPostgreSQL getEmbeddedPostgreSQL() {
    EmbeddedPostgreSQL epg = this.epg;
    Preconditions.checkState(epg != null, "JUnit test not started yet!");
    return epg;//  w  ww  .jav a 2  s  .c o m
}

From source file:model.gui.PlayButton.java

public PlayButton(MacroII modelToRun) {
    super("Play");
    Preconditions.checkState(modelToRun.hasStarted(), "need to have started before this is spawned!");

    //create the pause metaphore
    playPauseSemaphore = new Semaphore(0);

    //create the thread running the simulation
    Thread modelThread = new Thread(() -> {
        try {//from  w w w. j  a  va 2 s .  com
            //this trick I found by asking on :
            // http://stackoverflow.com/questions/23017888/boolean-semaphore-in-java/23018659?noredirect=1#23018659
            playPauseSemaphore.acquire(); // Block if paused
            playPauseSemaphore.release();
            while (true) {
                //step the model
                modelToRun.schedule.step(modelToRun);
                playPauseSemaphore.acquire(); // Block if paused
                playPauseSemaphore.release();
            }
        } catch (InterruptedException ignored) {
            System.err.println("interrupted");
        }
    });
    modelThread.setName("Simulation Thread");
    modelThread.setDaemon(true); //close with the simulation

    //you can start it immediately, it will immediately pause
    modelThread.start();

    this.setPrefSize(200, 40);
    this.addEventHandler(javafx.event.ActionEvent.ACTION, this);

}

From source file:lemon.elastic.query4j.esproxy.core.facet.AbstractFacetResult.java

protected AbstractFacetResult(String name, FacetType type) {
    Preconditions.checkState(SpringStringUtils.hasText(name),
            "Facet name can't be null and should have a value");
    this.name = name;
    this.type = type;
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.jmx.CassandraJmxCompactionManagers.java

/**
 * Running compaction against C* without SSL enabled experiences some hanging tcp connection
 * during compaction processes. So System.setProperty("sun.rmi.transport.tcp.responseTimeout",
 * String.valueOf(jmxRmiTimeoutMillis)); will enforce the tcp connection timeout in case it
 * happens.//from  w w  w .  j a  va 2s . c o m
 *
 * @param jmxConfig
 */
private static void setJmxSslProperty(CassandraJmxCompactionConfig jmxConfig) {
    long rmiTimeoutMillis = jmxConfig.rmiTimeoutMillis();
    // NOTE: RMI timeout to avoid hanging tcp connection
    System.setProperty("sun.rmi.transport.tcp.responseTimeout", String.valueOf(rmiTimeoutMillis));

    String keyStoreFile = jmxConfig.keystore();
    String keyStorePassword = jmxConfig.keystorePassword();
    String trustStoreFile = jmxConfig.truststore();
    String trustStorePassword = jmxConfig.truststorePassword();
    Preconditions.checkState((new File(keyStoreFile)).exists(), "file:" + keyStoreFile + " does not exist!");
    Preconditions.checkState((new File(trustStoreFile)).exists(),
            "file:" + trustStoreFile + " does not exist!");
    System.setProperty("javax.net.ssl.keyStore", keyStoreFile);
    System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
    System.setProperty("javax.net.ssl.trustStore", trustStoreFile);
    System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
}

From source file:ezbake.thrift.authentication.EzX509.java

public void assertValidPeer(String msg) {
    Preconditions.checkState(peerDn.isPresent(), msg);
}

From source file:org.opendaylight.yangtools.yang.model.util.type.DecimalTypeBuilder.java

@Override
DecimalTypeDefinition buildType() {//from www .  ja  va 2 s  . c  o  m
    Preconditions.checkState(fractionDigits != null, "Fraction digits not defined");

    return new BaseDecimalType(getPath(), getUnknownSchemaNodes(), fractionDigits,
            calculateRangeConstraints(BaseDecimalType.constraintsForDigits(fractionDigits)));
}

From source file:alluxio.master.job.ProtoUtils.java

/**
 * @param taskInfo the protocol buffer task information to convert
 * @return the {@link TaskInfo} version of the given protocol buffer task info
 *///from   w  w w  .  j av a  2s.  c o  m
public static TaskInfo fromProto(Job.TaskInfo taskInfo) {
    Preconditions.checkState(taskInfo.hasJobId(), "Deserializing protocol task info with unset jobId");
    Preconditions.checkState(taskInfo.hasTaskId(), "Deserializing protocol task info with unset taskId");
    Preconditions.checkState(taskInfo.hasStatus(), "Deserializing protocol task info with unset status");
    TaskInfo info = new TaskInfo().setJobId(taskInfo.getJobId()).setTaskId(taskInfo.getTaskId())
            .setStatus(fromProto(taskInfo.getStatus())).setErrorMessage(taskInfo.getErrorMessage());
    if (taskInfo.hasResult()) {
        info.setResult(taskInfo.getResult().toByteArray());
    }
    return info;
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.CQLExpiringKeyValueService.java

public static CQLExpiringKeyValueService create(CassandraKeyValueServiceConfigManager configManager) {
    Preconditions.checkState(!configManager.getConfig().servers().isEmpty(), "address list was empty");

    Optional<CassandraJmxCompactionManager> compactionManager = CassandraJmxCompaction
            .createJmxCompactionManager(configManager);
    CQLExpiringKeyValueService kvs = new CQLExpiringKeyValueService(configManager, compactionManager);
    kvs.initializeConnectionPool();//from  w  ww.j  a v  a2 s.c o m
    kvs.performInitialSetup();
    return kvs;
}

From source file:com.vmware.photon.controller.clustermanager.templates.NodeTemplateUtils.java

/**
 * Generates the hostname for a node.// w w  w  . ja v  a  2  s .c  o m
 */
public static String generateHostName(String vmName, String hostId) {
    String hostname = vmName + '-' + hostId;
    Preconditions.checkState(hostname.equals(hostname.toLowerCase()),
            "hostname should not contain upper case characters");
    return hostname;
}

From source file:net.tridentsdk.Trident.java

/**
 * Do not call// w ww  . j  a  v  a 2s. c  o  m
 * <p/>
 * <p>Will throw an exception if you are not calling from a trusted source</p>
 *
 * @param s the server to set
 */
public static void setServer(Server s) {
    Preconditions.checkState(isTrident(), "Server instance can only be set by TridentSDK!");
    server = s;
}