Example usage for org.apache.commons.lang.time DateUtils MILLIS_PER_SECOND

List of usage examples for org.apache.commons.lang.time DateUtils MILLIS_PER_SECOND

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils MILLIS_PER_SECOND.

Prototype

long MILLIS_PER_SECOND

To view the source code for org.apache.commons.lang.time DateUtils MILLIS_PER_SECOND.

Click Source Link

Document

Number of milliseconds in a standard second.

Usage

From source file:org.jumpmind.symmetric.service.impl.NodeCommunicationService.java

protected void unlock(NodeCommunication nodeCommunication, RemoteNodeStatus status, boolean failed, long ts) {
    boolean unlocked = false;
    int attempts = 1;
    do {/*from   w  w w .j  a v a 2 s  .  c o  m*/
        try {
            long millis = System.currentTimeMillis() - ts;
            nodeCommunication.setLockTime(null);
            nodeCommunication.setLastLockMillis(millis);
            if (failed) {
                nodeCommunication.setFailCount(nodeCommunication.getFailCount() + 1);
                nodeCommunication.setTotalFailCount(nodeCommunication.getTotalFailCount() + 1);
                nodeCommunication.setTotalFailMillis(nodeCommunication.getTotalFailMillis() + millis);
            } else {
                nodeCommunication.setSuccessCount(nodeCommunication.getSuccessCount() + 1);
                nodeCommunication.setTotalSuccessCount(nodeCommunication.getTotalSuccessCount() + 1);
                nodeCommunication.setTotalSuccessMillis(nodeCommunication.getTotalSuccessMillis() + millis);
                nodeCommunication.setFailCount(0);
            }
            status.setComplete(true);
            save(nodeCommunication);
            unlocked = true;
            if (attempts > 1) {
                log.info(String.format(
                        "Successfully unlocked %s node communication record for %s after %d attempts",
                        nodeCommunication.getCommunicationType().name(), nodeCommunication.getNodeId(),
                        attempts));
            }
        } catch (Throwable e) {
            log.error(String.format("Failed to unlock %s node communication record for %s",
                    nodeCommunication.getCommunicationType().name(), nodeCommunication.getNodeId()), e);
            long sleepTime = DateUtils.MILLIS_PER_SECOND
                    * new RandomTimeSlot(nodeCommunication.getNodeId(), 30).getRandomValueSeededByExternalId();
            log.warn("Sleeping for {} ms before attempting to unlock the node communication record again",
                    sleepTime);
            AppUtils.sleep(sleepTime);
            attempts++;
        }
        ;
    } while (!unlocked);
}

From source file:org.jumpmind.symmetric.service.impl.RegistrationService.java

private void sleepBeforeRegistrationRetry() {
    long sleepTimeInMs = DateUtils.MILLIS_PER_SECOND * randomTimeSlot.getRandomValueSeededByExternalId();
    log.info("Could not register.  Sleeping before attempting again.", sleepTimeInMs);
    log.info("Sleeping for {}ms", sleepTimeInMs);
    AppUtils.sleep(sleepTimeInMs);//  w  w w. j  a va2 s. c o  m
}

From source file:org.jumpmind.symmetric.service.impl.RegistrationService.java

public void requestNodeCopy() {
    Node copyFrom = nodeService.findIdentity();
    if (copyFrom == null) {
        throw new IllegalStateException("No identity found.  Can only copy if the node has an identity");
    }/*w  w w. jav a 2s . c  o  m*/
    boolean copied = false;
    int maxNumberOfAttempts = parameterService.getInt(ParameterConstants.REGISTRATION_NUMBER_OF_ATTEMPTS);
    while (!copied && (maxNumberOfAttempts < 0 || maxNumberOfAttempts > 0)) {

        try {
            log.info(
                    "Detected that node '{}' should be copied to a new node id.  Attempting to contact server to accomplish this",
                    copyFrom.getNodeId());
            copied = transportManager.sendCopyRequest(copyFrom) == HttpURLConnection.HTTP_OK;
            if (copied) {
                nodeService.deleteIdentity();
            }
        } catch (ConnectException e) {
            log.warn("The request to copy failed because the client failed to connect to the server");
        } catch (UnknownHostException e) {
            log.warn("The request to copy failed because the host was unknown");
        } catch (ConnectionRejectedException ex) {
            log.warn(
                    "The request to copy was rejected by the server.  Either the server node is not started, the server is not configured properly or the registration url is incorrect");
        } catch (Exception e) {
            log.error("", e);
        }

        maxNumberOfAttempts--;

        if (!copied) {
            long sleepTimeInMs = DateUtils.MILLIS_PER_SECOND
                    * randomTimeSlot.getRandomValueSeededByExternalId();
            log.warn("Copy failed.  Sleeping before attempting again.", sleepTimeInMs);
            log.info("Sleeping for {}ms", sleepTimeInMs);
            AppUtils.sleep(sleepTimeInMs);
        }

    }

    if (!copied) {
        throw new RegistrationFailedException(String.format("Failed after trying to copy %s times.",
                parameterService.getString(ParameterConstants.REGISTRATION_NUMBER_OF_ATTEMPTS)));
    }
}

From source file:org.openvpms.web.workspace.workflow.payment.OpenDrawerTask.java

/**
 * Opens the cash drawer for a payment or refund if:
 * <ul>/*from  w  w w. ja  va  2  s  .c  o m*/
 * <li> the act is POSTED</li>
 * <li>the till has a drawer command</li>
 * </ul>
 *
 * @param act the payment or refund act
 */
public void open(Act act) {
    if (ActStatus.POSTED.equals(act.getStatus())) {
        ActBean bean = new ActBean(act);
        Entity till = bean.getNodeParticipant("till");
        if (till != null) {
            CashDrawer drawer = new CashDrawer(till);
            if (drawer.canOpen() && drawer.needsOpen(act)) {
                final InformationDialog dialog = new InformationDialog(Messages.get("till.opendrawer"));
                dialog.setStyleName("InformationDialog.Compact");
                dialog.show((int) DateUtils.MILLIS_PER_SECOND); // close the dialog after 1 second
                try {
                    drawer.open();
                } catch (Throwable exception) {
                    dialog.close();
                    ErrorHelper.show(exception);
                }
            }
        }
    }
}

From source file:org.sipfoundry.sipxconfig.admin.intercom.Intercom.java

/** Return the timeout (seconds) after which the phone auto-answers */
public int getTimeoutInSeconds() {
    return getTimeout() / (int) DateUtils.MILLIS_PER_SECOND;
}

From source file:org.sipfoundry.sipxconfig.admin.intercom.Intercom.java

/** Set the timeout (seconds) after which the phone auto-answers */
public void setTimeoutInSeconds(int timeout) {
    setTimeout(timeout * (int) DateUtils.MILLIS_PER_SECOND);
}

From source file:org.sipfoundry.sipxconfig.components.MillisDurationFormat.java

public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
    // only works for numbers - class exception otherwise
    Number millisNumber = (Number) obj;
    long millis = millisNumber.longValue();

    if (m_formats == null) {
        initLocale(null);/*from   w  w w .  java  2  s.c om*/
    }

    if (millis < DateUtils.MILLIS_PER_SECOND && !m_showZero) {
        return toAppendTo;
    }

    boolean added = false;
    long[] result = calculate(millis);
    for (int i = 0; i < result.length; i++) {
        long l = result[i];
        if (l >= 0 || added || i == result.length - 1) {
            if (added) {
                toAppendTo.append(m_separator);
            }
            Object params = new Object[] { l };
            m_formats[i].format(params, toAppendTo, pos);
            added = true;
        }
    }
    return toAppendTo;
}

From source file:org.sipfoundry.sipxconfig.phone.ciscoplus.Ciscoplus.java

@Override
public void restart() {
    if (getLines().size() == 0) {
        throw new RestartException("&phone.line.not.valid");
    }/*  www.j a v a2  s.  c o  m*/
    Line line = getLines().get(0);
    List<RegistrationItem> registrations = m_registrationContext.getRegistrationsByUser(line.getUser());
    List<String> notifies = new ArrayList<String>();
    long currentTime = System.currentTimeMillis() / DateUtils.MILLIS_PER_SECOND;
    for (RegistrationItem registration : registrations) {
        if (registration.getInstrument().contains(getSerialNumber())) {
            long timeToExpire = registration.timeToExpireAsSeconds(currentTime);
            if (timeToExpire > 0) {
                notifies.add(String.format(RESET_MESSAGE, registration.getRegCallId()));
            }
        }
    }
    boolean success = false;
    for (String notify : notifies) {
        try {
            getSipService().sendNotify(line.getAddrSpec(), "service-control", "text/plain", notify.getBytes());
            success = true;
        } catch (IllegalArgumentException iae) {
            // do nothing, success will be on false and error thrown
            continue;
        } catch (RuntimeException re) {
            // do nothing, success will be on false and error thrown
            continue;
        }
    }

    if (!success) {
        throw new RestartException("&phone.sip.exception");
    }
}

From source file:org.sipfoundry.sipxconfig.site.admin.commserver.Registrations.java

/**
 * Retrieves registration metrics object. Can be called multiple times during rewind/render
 * and it'll lazily initialize registrations metrics only the first time it is called.
 *
 * Workaround for Tapestry 4.0 table model problem, in some case table model is retrieved
 * before pageBenginRender gets called/*from ww w. jav  a2  s . co m*/
 *
 * @return properly initialized registration metrics object
 */
public RegistrationMetrics getMetrics() {
    RegistrationMetrics metrics = getMetricsProperty();
    if (metrics != null) {
        return metrics;
    }
    long startRenderingTime = System.currentTimeMillis() / DateUtils.MILLIS_PER_SECOND;
    metrics = new RegistrationMetrics();
    metrics.setRegistrations(getRegistrationContext().getRegistrations());
    metrics.setStartTime(startRenderingTime);
    setMetricsProperty(metrics);
    return metrics;
}

From source file:org.sipfoundry.sipxconfig.site.setting.RegistrationsTable.java

protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
    long startRenderingTime = System.currentTimeMillis() / DateUtils.MILLIS_PER_SECOND;
    setStartTime(startRenderingTime);//  w w w. j ava  2  s  .  co m
    super.renderComponent(writer, cycle);
}