Example usage for java.util Calendar getTimeInMillis

List of usage examples for java.util Calendar getTimeInMillis

Introduction

In this page you can find the example usage for java.util Calendar getTimeInMillis.

Prototype

public long getTimeInMillis() 

Source Link

Document

Returns this Calendar's time value in milliseconds.

Usage

From source file:com.indoqa.lang.util.TimeUtilsTest.java

@Test
public void parseDate() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(TimeZone.getTimeZone("GMT+1"));
    calendar.set(2012, 2, 1, 10, 5, 30);
    calendar.set(Calendar.MILLISECOND, 501);

    assertEquals(calendar.getTimeInMillis(), TimeUtils.parseDate("2012-03-01 09:05:30.501").getTime());
}

From source file:com.fivesticks.time.activity.xwork.TimeResolver.java

public Date resolve() {

    if (this.date == null || this.timestring == null)
        throw new RuntimeException("Unable to resolve time.");

    Calendar c = new GregorianCalendar();
    c.setTime(date);/*from  ww w .j ava  2  s.c om*/

    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    parseTimeString();

    Calendar c2 = new GregorianCalendar(year, month, day, this.getResolvedHours(), this.getResolvedMinutes());
    Date ret = new Date();
    ret.setTime(c2.getTimeInMillis());

    return ret;
}

From source file:core.clients.service.ServiceAdminClient.java

/**
 * Wait till the service get deployed/*ww  w.  j  a  v  a2 s .  co  m*/
 * 
 * @param serviceName
 *            service name
 * @return deploy status
 * @throws java.rmi.RemoteException
 */
public boolean isServiceDeployed(String serviceName) throws RemoteException, NullPointerException {

    boolean isServiceDeployed = false;
    Calendar startTime = Calendar.getInstance();
    while (Calendar.getInstance().getTimeInMillis() - startTime.getTimeInMillis() < SERVICE_DEPLOYMENT_DELAY) {
        if (isServiceExists(serviceName)) {
            isServiceDeployed = true;
            break;
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ignored) {
            // Exception is ignored
        }
    }
    return isServiceDeployed;
}

From source file:core.clients.service.ServiceAdminClient.java

/**
 * Wait till the service get deployed//from  w  w w  .  j  av  a2  s  .c  o  m
 * 
 * @param serviceName
 *            service name
 * @return deploy status
 * @throws java.rmi.RemoteException
 */
public boolean isServiceUnDeployed(String serviceName) throws RemoteException, NullPointerException {

    boolean isServiceUnDeployed = false;
    Calendar startTime = Calendar.getInstance();
    while (Calendar.getInstance().getTimeInMillis() - startTime.getTimeInMillis() < SERVICE_DEPLOYMENT_DELAY) {
        if (!isServiceExists(serviceName)) {
            isServiceUnDeployed = true;
            break;
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ignored) {
            // Exception is ignored
        }
    }
    return isServiceUnDeployed;
}

From source file:eu.planets_project.tb.gui.backing.exp.EvaluationPropertyResultsBean.java

public void setEvalResultValue(Calendar runDate, String[] stageNames, int runEvalValue) {
    //a stagename contains different values but all contain the same evalRecBean eval value.
    for (String stageName : stageNames) {
        this.evalresults.get(runDate.getTimeInMillis()).get(stageName).setEvalValue(runEvalValue);
    }/* w  w  w. j a v a  2  s.  c o m*/
}

From source file:org.fornax.cartridges.sculptor.framework.drools.DroolsAdvice.java

public Object invoke(MethodInvocation procJointpoint) throws Throwable {
    long startTimeExec = System.currentTimeMillis();
    log.info("############# START DROOLS RULES");
    RequestDescription req = new RequestDescription(procJointpoint);
    try {/*from ww  w.java 2  s. com*/
        Object[] arguments = procJointpoint.getArguments();
        ServiceContext ctx;
        int startArg;
        if (arguments[0] instanceof ServiceContext) {
            ctx = (ServiceContext) arguments[0];
            startArg = 1;
        } else {
            ctx = ServiceContextStore.get();
            startArg = 0;
        }

        HashMap<String, Object> objects = new HashMap<String, Object>();
        for (int i = startArg; i < arguments.length; i++) {
            objects.put("arg" + i, arguments[i]);
        }
        objects.put("request", req);
        objects.put("service", procJointpoint.getThis());
        objects.put("username", ServiceContextStore.getCurrentUser());

        HashMap<String, Object> globals = new HashMap<String, Object>();
        if (ctx != null) {
            globals.put("serviceContext", ctx);
        }
        globals.put("appContext", appContext);
        globals.put("log", log);

        Calendar curDate = Calendar.getInstance();
        globals.put("currentDate", curDate);
        globals.put("currentTimestamp", curDate.getTimeInMillis());

        applyCompanyPolicy(objects, globals);
    } catch (Throwable th) {
        if (catchAllExceptions) {
            while (th.getCause() != null) {
                th = th.getCause();
            }
            log.warn("Applying company policy finished with error: " + th.getMessage(), th);
        } else {
            throw th;
        }
    } finally {
        log.info("############# END DROOLS RULES (" + (System.currentTimeMillis() - startTimeExec) + " ms)");
    }

    if (req.wasProceed() && req.getLastResult() != null && req.getLastResult() instanceof Throwable) {
        throw (Throwable) req.getLastResult();
    } else if (req.wasProceed()) {
        return req.getLastResult();
    } else {
        return procJointpoint.proceed();
    }
}

From source file:eu.vital.orchestrator.rest.EvaluationRESTService.java

@POST
@Path("/prediction")
public Response executePredictionScenario(JsonNode input) throws Exception {
    String dmsUrl = "https://local.vital-iot.eu:8443/vital-core-dms";

    // 1. Get List of sensors from DMS observing AvailableBikes
    Client dmsClient = ClientBuilder.newClient();
    WebTarget dmsTarget = dmsClient.target(dmsUrl).path("querySensor").queryParam("encodeKeys", "false");
    ObjectNode sensorQuery = objectMapper.createObjectNode();
    sensorQuery.put("http://purl\\u002eoclc\\u002eorg/NET/ssnx/ssn#observes.@type",
            "http://vital-iot.eu/ontology/ns/Speed");
    ArrayNode sensorList = dmsTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(sensorQuery),
            ArrayNode.class);

    // 2. Find the nearest sensor
    double minDistance = Double.MAX_VALUE;
    JsonNode nearestSensor = null;//from ww  w.  java  2 s  . c  o m
    for (int i = 0; i < sensorList.size(); i++) {
        JsonNode sensor = sensorList.get(i);

        // Calculate Distance:
        double tmp = distance(input.get("lat").asDouble(), input.get("lng").asDouble(),
                sensor.get("hasLastKnownLocation").get("geo:lat").asDouble(),
                sensor.get("hasLastKnownLocation").has("geo:long")
                        ? sensor.get("hasLastKnownLocation").get("geo:long").asDouble()
                        : sensor.get("hasLastKnownLocation").get("geo:lon").asDouble());
        if (tmp < minDistance) {
            minDistance = tmp;
            nearestSensor = sensor;
        }
    }

    // 3. Get all observations of this sensor from DMS archive
    dmsTarget = dmsClient.target(dmsUrl).path("queryObservation").queryParam("encodeKeys", "false");
    ObjectNode observationQuery = objectMapper.createObjectNode();
    observationQuery.put("http://purl\\u002eoclc\\u002eorg/NET/ssnx/ssn#observedBy.@value",
            nearestSensor.get("id").asText());
    observationQuery.put("http://purl\\u002eoclc\\u002eorg/NET/ssnx/ssn#observationProperty.@type",
            "http://vital-iot.eu/ontology/ns/Speed");

    ArrayNode observationList = dmsTarget.request(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(observationQuery), ArrayNode.class);

    // 4. Run the prediction algorithm
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < observationList.size(); i++) {
        JsonNode observation = observationList.get(i);
        double value = observation.get("ssn:observationResult").get("ssn:hasValue").get("value").asDouble();
        String dateStr = observation.get("ssn:observationResultTime").get("time:inXSDDateTime").asText();
        Calendar date = javax.xml.bind.DatatypeConverter.parseDateTime(dateStr);
        regression.addData(date.getTimeInMillis(), value);
    }
    double futureMillis = javax.xml.bind.DatatypeConverter.parseDateTime(input.get("atDate").asText())
            .getTimeInMillis();
    double prediction = regression.predict(futureMillis);

    // 5. Return the result:
    ObjectNode result = objectMapper.createObjectNode();
    result.put("predictionValue", prediction);
    result.put("predictionDate", input.get("atDate").asText());

    return Response.ok(result).build();
}

From source file:helper.lang.DateHelperTest.java

@Test
public void testNowUtc() {
    long nowBeforeCall = System.currentTimeMillis();
    Calendar cal = DateHelper.nowUtc();
    long nowAfterCall = System.currentTimeMillis();
    assertTrue(cal.getTimeInMillis() >= nowBeforeCall);
    assertTrue(cal.getTimeInMillis() <= nowAfterCall);
    assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone());
}

From source file:com.datatorrent.lib.bucket.AbstractTimeBasedBucketManager.java

private void recomputeNumBuckets() {
    Calendar calendar = Calendar.getInstance();
    long now = calendar.getTimeInMillis();
    calendar.add(Calendar.DATE, -daysSpan);
    startOfBucketsInMillis = calendar.getTimeInMillis();
    expiryTime = startOfBucketsInMillis;
    noOfBuckets = (int) Math.ceil((now - startOfBucketsInMillis) / (bucketSpanInMillis * 1.0));
    if (bucketStore != null) {
        bucketStore.setNoOfBuckets(noOfBuckets);
        bucketStore.setWriteEventKeysOnly(writeEventKeysOnly);
    }/*from   w  ww. j  a va2s  .  c  o m*/
    maxTimesPerBuckets = new Long[noOfBuckets];
}

From source file:com.ewcms.publication.freemarker.directive.ArticleListDirectiveTest.java

private List<Article> createArticleRow(int row) {
    List<Article> articles = new ArrayList<Article>();
    for (int i = 0; i < row; i++) {

        Article article = new Article();
        article.setId(new Long(i));
        article.setAuthor("");
        article.setOrigin("163.com");
        article.setTitle("ewcms" + String.valueOf(i));
        article.setShortTitle("");
        Calendar calendar = Calendar.getInstance();
        article.setPublished(new Date(calendar.getTimeInMillis()));
        article.setSummary("?ewcms");
        article.setImage("http://www.jict.org/image/test.jpg");

        articles.add(article);//w  w w .  j a  va2  s  . com
    }
    return articles;
}