Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateTimeInstance.

Prototype

public static final DateFormat getDateTimeInstance(int dateStyle, int timeStyle) 

Source Link

Document

Gets the date/time formatter with the given date and time formatting styles for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:com.intuit.tank.harness.APITestHarness.java

/**
 * Run concurrent test plans at the same time
 * /*from  ww  w.j av  a  2 s .c  o  m*/
 * @param parser
 */
public void runConcurrentTestPlans() {
    if (started) {
        LOG.warn("Agent already started. Ignoring start command");
        return;
    }
    tpsMonitor = new TPSMonitor(tankConfig.getAgentConfig().getTPSPeriod());
    StringBuilder info = new StringBuilder().append(" RAMP_TIME=").append(agentRunData.getRampTime())
            .append("; agentRunData.getNumUsers()=").append(agentRunData.getNumUsers())
            .append("; NUM_START_THREADS=").append(agentRunData.getNumStartUsers()).append("; simulationTime=")
            .append(agentRunData.getSimulationTime());
    LOG.info(LogUtil.getLogMessage("starting test with " + info.toString()));
    started = true;

    if (agentRunData.getJobId() == null) {
        String jobId = AmazonUtil.getJobId();
        agentRunData.setJobId(jobId);
    }

    TestPlanRunner[] sessions = new TestPlanRunner[agentRunData.getNumUsers()];
    sessionThreads = new Thread[agentRunData.getNumUsers()];
    Thread monitorThread = null;
    doneSignal = new CountDownLatch(agentRunData.getNumUsers());
    try {
        HDWorkload hdWorkload = TestPlanSingleton.getInstance().getTestPlans().get(0);
        if (StringUtils.isBlank(tankHttpClientClass)) {
            tankHttpClientClass = hdWorkload.getTankHttpClientClass();
        }
        agentRunData.setProjectName(hdWorkload.getName());
        agentRunData.setTankhttpClientClass(tankHttpClientClass);
        List<TestPlanStarter> testPlans = new ArrayList<TestPlanStarter>();
        int total = 0;
        for (HDTestPlan plan : hdWorkload.getPlans()) {
            if (plan.getUserPercentage() > 0) {
                plan.setVariables(hdWorkload.getVariables());
                TestPlanStarter starter = new TestPlanStarter(plan, agentRunData.getNumUsers());
                total += starter.getNumThreads();
                testPlans.add(starter);
                LOG.info(LogUtil.getLogMessage("Users for Test Plan " + plan.getTestPlanName() + " at "
                        + plan.getUserPercentage() + "% = " + starter.getNumThreads()));
            }
        }
        LOG.info(LogUtil.getLogMessage("Total Users calculated for all test Plans = " + total));
        if (total != agentRunData.getNumUsers()) {
            int numToAdd = agentRunData.getNumUsers() - total;
            TestPlanStarter starter = testPlans.get(testPlans.size() - 1);
            LOG.info(LogUtil.getLogMessage(
                    "adding " + numToAdd + " threads to testPlan " + starter.getPlan().getTestPlanName()));
            starter.setNumThreads(starter.getNumThreads() + numToAdd);
        }

        // create threads
        int tp = 0;
        for (TestPlanStarter starter : testPlans) {
            for (int i = 0; i < starter.getNumThreads(); i++) {
                sessions[tp] = new TestPlanRunner(starter.getPlan(), tp);
                sessionThreads[tp] = new Thread(threadGroup, sessions[tp], "AGENT");
                sessionThreads[tp].setDaemon(true);// system won't shut down normally until all user threads stop
                starter.addThread(sessionThreads[tp]);
                sessions[tp].setUniqueName(
                        sessionThreads[tp].getThreadGroup().getName() + "-" + sessionThreads[tp].getId());
                tp++;
            }
        }
        LOG.info(LogUtil.getLogMessage("Have all testPlan runners configured"));
        // start status thread first only
        if (!isLocal && !isDebug() && NumberUtils.isDigits(agentRunData.getJobId())) {
            LOG.info(LogUtil.getLogMessage("Starting monitor thread..."));
            CloudVmStatus status = getInitialStatus();
            monitorThread = new Thread(new APIMonitor(status));
            monitorThread.setDaemon(true);
            monitorThread.setPriority(Thread.NORM_PRIORITY - 2);
            monitorThread.start();
        }

        LOG.info(LogUtil.getLogMessage("Starting threads..."));
        // start initial users
        startTime = System.currentTimeMillis();
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
        LOG.info(LogUtil.getLogMessage("Simulation start: " + df.format(new Date(getStartTime()))));
        if (agentRunData.getSimulationTime() != 0) {
            LOG.info(LogUtil.getLogMessage(
                    "Scheduled Simulation End : " + df.format(new Date(getSimulationEndTimeMillis()))));
            LOG.info(LogUtil.getLogMessage(
                    "Max Simulation End : " + df.format(new Date(getMaxSimulationEndTimeMillis()))));
        } else {
            LOG.info(LogUtil.getLogMessage("Ends at script loops completed with no Max Simulation Time."));
        }
        currentNumThreads = 0;
        if (agentRunData.getNumUsers() > 0) {
            for (TestPlanStarter starter : testPlans) {
                if (isDebug()) {
                    starter.run();
                } else {
                    Thread t = new Thread(starter);
                    t.setDaemon(true);
                    t.start();
                }
            }
            boolean ramping = true;
            while (ramping) {
                boolean done = true;
                for (TestPlanStarter starter : testPlans) {
                    done = done && starter.isDone();
                }
                ramping = !done;
                if (ramping) {
                    Thread.sleep(5000);
                }
            }
            // if we broke early, fix our countdown latch
            int numToCount = 0;
            for (TestPlanStarter starter : testPlans) {
                numToCount += starter.getThreadsStarted();
            }
            while (numToCount < agentRunData.getNumUsers()) {
                doneSignal.countDown();
                numToCount++;
            }
            // wait for them to finish
            LOG.info(LogUtil.getLogMessage("Ramp Complete..."));

            doneSignal.await();
        }
    } catch (Throwable t) {
        LOG.error("error executing..." + t, t);
    } finally {
        LOG.info(LogUtil.getLogMessage("Test Complete..."));
        if (!isDebug() && NumberUtils.isDigits(agentRunData.getJobId())) {
            if (null != monitorThread) {
                APIMonitor.setJobStatus(JobStatus.Completed);
                APIMonitor.setDoMonitor(false);
            }
            sendBatchToDB(false);
            // sleep for 60 seconds to let wily agent clear any data
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                // nothing to do
            }
        }
    }
    flowControllerTemplate.endTest();
    // System.exit(0);
}

From source file:org.rhq.enterprise.server.system.SystemManagerBean.java

@RequiredPermission(Permission.MANAGE_SETTINGS)
public ServerDetails getServerDetails(Subject subject) {
    CoreServerMBean coreServerMBean = LookupUtil.getCoreServer();

    ServerDetails serverDetails = new ServerDetails();

    serverDetails.setProductInfo(getProductInfo(subject));

    HashMap<Detail, String> details = serverDetails.getDetails();

    DateFormat localTimeFormatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL);
    details.put(ServerDetails.Detail.SERVER_LOCAL_TIME, localTimeFormatter.format(new Date()));
    details.put(ServerDetails.Detail.SERVER_TIMEZONE, TimeZone.getDefault().getDisplayName());
    details.put(ServerDetails.Detail.SERVER_HOME_DIR,
            coreServerMBean.getJBossServerHomeDir().getAbsolutePath());
    details.put(ServerDetails.Detail.SERVER_INSTALL_DIR, coreServerMBean.getInstallDir().getAbsolutePath());

    SystemDatabaseInformation dbInfo = SystemDatabaseInformation.getInstance();
    details.put(ServerDetails.Detail.DATABASE_CONNECTION_URL, dbInfo.getDatabaseConnectionURL());
    details.put(ServerDetails.Detail.DATABASE_DRIVER_NAME, dbInfo.getDatabaseDriverName());
    details.put(ServerDetails.Detail.DATABASE_DRIVER_VERSION, dbInfo.getDatabaseDriverVersion());
    details.put(ServerDetails.Detail.DATABASE_PRODUCT_NAME, dbInfo.getDatabaseProductName());
    details.put(ServerDetails.Detail.DATABASE_PRODUCT_VERSION, dbInfo.getDatabaseProductVersion());
    details.put(ServerDetails.Detail.CURRENT_MEASUREMENT_TABLE, dbInfo.getCurrentMeasurementTable());
    details.put(ServerDetails.Detail.NEXT_MEASUREMENT_TABLE_ROTATION, dbInfo.getNextMeasurementTableRotation());

    return serverDetails;
}

From source file:com.bizosys.hsearch.index.IndexReaderTest.java

public void testCreatedAfter() throws Exception {
    String id = "ID021";

    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);

    HDocument doc1 = new HDocument(ANONYMOUS);
    doc1.key = "Id 1 : " + id;
    doc1.title = "My daughter birth was after my birth";
    doc1.createdOn = format.parse("Nov 18, 2008 6:15 AM");
    IndexWriter.getInstance().insert(doc1, acc, isMultiClient);

    String myBirth = new Long(format.parse("Feb 05, 1977 8:00 PM").getTime()).toString();
    QueryResult res1 = IndexReader.getInstance()
            .search(new QueryContext(acc, "createda:" + myBirth + " birth"));
    assertEquals(1, res1.teasers.length);

    String toDate = new Long(new Date().getTime()).toString();
    QueryResult res2 = IndexReader.getInstance().search(new QueryContext(acc, "createda:" + toDate + " birth"));
    assertEquals(0, res2.teasers.length);

    IndexWriter.getInstance().delete(ANONYMOUS, doc1.key, isMultiClient);
}

From source file:ca.oson.json.Oson.java

public Oson setDateFormat(int dateStyle, int timeStyle) {
    options.setDateFormat(DateFormat.getDateTimeInstance(dateStyle, timeStyle));
    reset();//w w  w. j av  a2 s . com

    return this;
}

From source file:com.bizosys.hsearch.index.IndexReaderTest.java

public void testModifiedAfter() throws Exception {
    String id = "ID022";

    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);

    HDocument doc1 = new HDocument(ANONYMOUS);
    doc1.key = "Id 1 : " + id;
    doc1.title = "My Trading balance as 234.00";
    doc1.modifiedOn = new Date();
    IndexWriter.getInstance().insert(doc1, acc, isMultiClient);

    String myBirth = new Long(format.parse("Feb 05, 1977 8:00 PM").getTime()).toString();
    QueryResult res1 = IndexReader.getInstance()
            .search(new QueryContext(acc, "modifieda:" + myBirth + " balance"));
    assertEquals(1, res1.teasers.length);

    String future = new Long(format.parse("Feb 05, 2121 8:00 PM").getTime()).toString();
    QueryResult res2 = IndexReader.getInstance()
            .search(new QueryContext(acc, "modifieda:" + future + " balance"));
    assertEquals(0, res2.teasers.length);

    IndexWriter.getInstance().delete(ANONYMOUS, doc1.key, isMultiClient);
}

From source file:ca.oson.json.Oson.java

public <T> Oson setDateFormat(Class<T> type, int dateStyle, int timeStyle) {
    cMap(type).setDateFormat(DateFormat.getDateTimeInstance(dateStyle, timeStyle));
    reset();//from  w  w  w .ja  v  a 2 s .  c o  m

    return this;
}

From source file:org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.java

public static void addToResultDB(final IStepResultMeta stepResultMeta, final Date stepDate,
        final File outputDir) {
    // TODO: retrieve time zone from central plugin preferences
    final DateFormat dateFormatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
    dateFormatter.setTimeZone(KalypsoCorePlugin.getDefault().getTimeZone());

    if (ResultManager.STEADY_DATE.equals(stepDate)) {
        stepResultMeta.setName(//from   ww w.j  a v  a 2 s. co  m
                Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.93")); //$NON-NLS-1$
        stepResultMeta.setDescription(
                Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.94")); //$NON-NLS-1$
        stepResultMeta.setStepType(IStepResultMeta.STEPTYPE.steady);
        stepResultMeta.setStepTime(null);
    } else if (ResultManager.MAXI_DATE.equals(stepDate)) {
        stepResultMeta.setName(
                Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.95")); //$NON-NLS-1$
        stepResultMeta.setDescription(
                Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.96")); //$NON-NLS-1$
        stepResultMeta.setStepType(IStepResultMeta.STEPTYPE.maximum);
        stepResultMeta.setStepTime(null);
    } else {
        // TODO: check for right time zone
        final String dateString = dateFormatter.format(stepDate);
        stepResultMeta.setName(Messages
                .getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.97", dateString)); //$NON-NLS-1$
        stepResultMeta.setDescription(
                Messages.getString("org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.98") //$NON-NLS-1$
                        + dateString);
        stepResultMeta.setStepType(IStepResultMeta.STEPTYPE.unsteady);
        stepResultMeta.setStepTime(stepDate);
    }

    stepResultMeta.setPath(new Path(outputDir.getName()));
}

From source file:com.bizosys.hsearch.index.IndexReaderTest.java

public void testModifiedBefore() throws Exception {
    String id = "ID023";

    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);

    HDocument doc1 = new HDocument(ANONYMOUS);
    doc1.key = "Id 1 : " + id;
    doc1.title = "My Trading balance as 234.00";
    doc1.modifiedOn = new Date();
    IndexWriter.getInstance().insert(doc1, acc, isMultiClient);

    String myBirth = new Long(format.parse("Feb 05, 1977 8:00 PM").getTime()).toString();
    QueryResult res1 = IndexReader.getInstance()
            .search(new QueryContext(acc, "modifiedb:" + myBirth + " balance"));
    assertEquals(0, res1.teasers.length);

    String future = new Long(format.parse("Feb 05, 2121 8:00 PM").getTime()).toString();
    QueryResult res2 = IndexReader.getInstance()
            .search(new QueryContext(acc, "modifiedb:" + future + " balance"));
    assertEquals(1, res2.teasers.length);

    IndexWriter.getInstance().delete(ANONYMOUS, doc1.key, isMultiClient);
}

From source file:main.java.edu.isistan.genCom.gui.Principal.java

/**
  * Registra la generacin en el historial
  *//* w w w .  jav a 2 s.c om*/
 private void cargarHistorial() {
     ConfiguracionAG conf = generacionCargada.getConfiguracion();

     // Carga la tabla de historial
     DefaultTableModel dtmLog = (DefaultTableModel) tbHistorial.getModel();

     dtmLog.addRow(new String[] {
             DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG)
                     .format(generacionCargada.getFecha()),
             conf.getCruce().toString(), conf.getMutacion().toString(), conf.getSeleccion().toString(),
             conf.getModelo().toString(), String.valueOf(generacionCargada.getEjecuciones().size()),
             String.valueOf(conf.getCorte()), generacionCargada.getConfiguracion().getFitness().toString(),
             String.valueOf(generacionCargada.getFitnessPromedio()),
             String.valueOf(generacionCargada.getFitnessDesviacion()) });
 }

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Formats as a <code>String</code> the specified time.
 * //from  w ww .j  a v a 2s. c om
 * @param time The timestamp to format.
 * @return Returns the stringified version of the passed timestamp.
 */
public static String formatShortDateTime(Timestamp time) {
    if (time == null)
        time = getDefaultTimestamp();
    return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(time);
}