List of usage examples for java.lang Long longValue
@HotSpotIntrinsicCandidate public long longValue()
From source file:com.liferay.portal.language.LanguageUtil.java
public static String getTimeDescription(PageContext pageContext, Long milliseconds) throws LanguageException { return getTimeDescription(pageContext, milliseconds.longValue()); }
From source file:com.googlecode.psiprobe.Utils.java
public static long toLong(Long num, long defaultValue) { return num == null ? defaultValue : num.longValue(); }
From source file:nc.noumea.mairie.appock.core.utility.AppockUtil.java
public static boolean sameIdAndNotNull(Long id1, Long id2) { if (id1 == null || id2 == null) { return false; }//from ww w .j av a 2 s. co m return id1.longValue() == id2.longValue(); }
From source file:amplify.NTPClient.java
/** * Process <code>TimeInfo</code> object and print its details. * * @param info <code>TimeInfo</code> object. *///from w w w.j a v a 2 s.c o m public static void processResponse(TimeInfo info) { NtpV3Packet message = info.getMessage(); int stratum = message.getStratum(); String refType; if (stratum <= 0) refType = "(Unspecified or Unavailable)"; else if (stratum == 1) refType = "(Primary Reference; e.g., GPS)"; // GPS, radio clock, etc. else refType = "(Secondary Reference; e.g. via NTP or SNTP)"; // stratum should be 0..15... System.out.println(" Stratum: " + stratum + " " + refType); int version = message.getVersion(); int li = message.getLeapIndicator(); System.out.println(" leap=" + li + ", version=" + version + ", precision=" + message.getPrecision()); System.out.println(" mode: " + message.getModeName() + " (" + message.getMode() + ")"); int poll = message.getPoll(); // poll value typically btwn MINPOLL (4) and MAXPOLL (14) System.out.println( " poll: " + (poll <= 0 ? 1 : (int) Math.pow(2, poll)) + " seconds" + " (2 ** " + poll + ")"); double disp = message.getRootDispersionInMillisDouble(); System.out.println(" rootdelay=" + numberFormat.format(message.getRootDelayInMillisDouble()) + ", rootdispersion(ms): " + numberFormat.format(disp)); int refId = message.getReferenceId(); String refAddr = NtpUtils.getHostAddress(refId); String refName = null; if (refId != 0) { if (refAddr.equals("127.127.1.0")) { refName = "LOCAL"; // This is the ref address for the Local Clock } else if (stratum >= 2) { // If reference id has 127.127 prefix then it uses its own reference clock // defined in the form 127.127.clock-type.unit-num (e.g. 127.127.8.0 mode 5 // for GENERIC DCF77 AM; see refclock.htm from the NTP software distribution. if (!refAddr.startsWith("127.127")) { try { InetAddress addr = InetAddress.getByName(refAddr); String name = addr.getHostName(); if (name != null && !name.equals(refAddr)) refName = name; } catch (UnknownHostException e) { // some stratum-2 servers sync to ref clock device but fudge stratum level higher... (e.g. 2) // ref not valid host maybe it's a reference clock name? // otherwise just show the ref IP address. refName = NtpUtils.getReferenceClock(message); } } } else if (version >= 3 && (stratum == 0 || stratum == 1)) { refName = NtpUtils.getReferenceClock(message); // refname usually have at least 3 characters (e.g. GPS, WWV, LCL, etc.) } // otherwise give up on naming the beast... } if (refName != null && refName.length() > 1) refAddr += " (" + refName + ")"; TimeStamp refNtpTime = message.getReferenceTimeStamp(); // Originate Time is time request sent by client (t1) TimeStamp origNtpTime = message.getOriginateTimeStamp(); long destTime = info.getReturnTime(); long localDestTime = System.currentTimeMillis(); // Receive Time is time request received by server (t2) TimeStamp rcvNtpTime = message.getReceiveTimeStamp(); // Transmit time is time reply sent by server (t3) TimeStamp xmitNtpTime = message.getTransmitTimeStamp(); // Destination time is time reply received by client (t4) TimeStamp destNtpTime = TimeStamp.getNtpTime(destTime); info.computeDetails(); // compute offset/delay if not already done Long offsetValue = info.getOffset(); Long delayValue = info.getDelay(); String delay = (delayValue == null) ? "N/A" : delayValue.toString(); String offset = (offsetValue == null) ? "N/A" : offsetValue.toString(); clockOffset = offsetValue != null ? offsetValue.longValue() : 0L; System.out.println(" Reference Identifier:\t" + refAddr); System.out.println(" Reference Timestamp:\t" + refNtpTime + " " + refNtpTime.toDateString()); System.out.println(" Originate Timestamp:\t" + origNtpTime + " " + origNtpTime.toDateString()); System.out.println(" Receive Timestamp:\t" + rcvNtpTime + " " + rcvNtpTime.toDateString()); System.out.println(" Transmit Timestamp:\t" + xmitNtpTime + " " + xmitNtpTime.toDateString()); System.out.println(" Destination Timestamp:\t" + destNtpTime + " " + destNtpTime.toDateString()); System.out.println(" Roundtrip delay(ms)=" + delay + ", clock offset(ms)=" + offset); // offset in ms }
From source file:com.amplify.gcm.hack.NTPClient.java
/** * Process <code>TimeInfo</code> object and print its details. * * @param info <code>TimeInfo</code> object. *///from w w w .j a va2 s . c om public static void processResponse(TimeInfo info) { NtpV3Packet message = info.getMessage(); int stratum = message.getStratum(); String refType; if (stratum <= 0) refType = "(Unspecified or Unavailable)"; else if (stratum == 1) refType = "(Primary Reference; e.g., GPS)"; // GPS, radio clock, etc. else refType = "(Secondary Reference; e.g. via NTP or SNTP)"; // stratum should be 0..15... System.out.println(" Stratum: " + stratum + " " + refType); int version = message.getVersion(); int li = message.getLeapIndicator(); System.out.println(" leap=" + li + ", version=" + version + ", precision=" + message.getPrecision()); System.out.println(" mode: " + message.getModeName() + " (" + message.getMode() + ")"); int poll = message.getPoll(); // poll value typically btwn MINPOLL (4) and MAXPOLL (14) System.out.println( " poll: " + (poll <= 0 ? 1 : (int) Math.pow(2, poll)) + " seconds" + " (2 ** " + poll + ")"); double disp = message.getRootDispersionInMillisDouble(); System.out.println(" rootdelay=" + numberFormat.format(message.getRootDelayInMillisDouble()) + ", rootdispersion(ms): " + numberFormat.format(disp)); int refId = message.getReferenceId(); String refAddr = NtpUtils.getHostAddress(refId); String refName = null; if (refId != 0) { if (refAddr.equals("127.127.1.0")) { refName = "LOCAL"; // This is the ref address for the Local Clock } else if (stratum >= 2) { // If reference id has 127.127 prefix then it uses its own reference clock // defined in the form 127.127.clock-type.unit-num (e.g. 127.127.8.0 mode 5 // for GENERIC DCF77 AM; see refclock.htm from the NTP software distribution. if (!refAddr.startsWith("127.127")) { try { InetAddress addr = InetAddress.getByName(refAddr); String name = addr.getHostName(); if (name != null && !name.equals(refAddr)) refName = name; } catch (UnknownHostException e) { // some stratum-2 servers sync to ref clock device but fudge stratum level higher... (e.g. 2) // ref not valid host maybe it's a reference clock name? // otherwise just show the ref IP address. refName = NtpUtils.getReferenceClock(message); } } } else if (version >= 3 && (stratum == 0 || stratum == 1)) { refName = NtpUtils.getReferenceClock(message); // refname usually have at least 3 characters (e.g. GPS, WWV, LCL, etc.) } // otherwise give up on naming the beast... } if (refName != null && refName.length() > 1) refAddr += " (" + refName + ")"; TimeStamp refNtpTime = message.getReferenceTimeStamp(); // Originate Time is time request sent by client (t1) TimeStamp origNtpTime = message.getOriginateTimeStamp(); long destTime = info.getReturnTime(); long localDestTime = System.currentTimeMillis(); // Receive Time is time request received by server (t2) TimeStamp rcvNtpTime = message.getReceiveTimeStamp(); // Transmit time is time reply sent by server (t3) TimeStamp xmitNtpTime = message.getTransmitTimeStamp(); // Destination time is time reply received by client (t4) TimeStamp destNtpTime = TimeStamp.getNtpTime(destTime); info.computeDetails(); // compute offset/delay if not already done Long offsetValue = info.getOffset(); Long delayValue = info.getDelay(); String delay = (delayValue == null) ? "N/A" : delayValue.toString(); String offset = (offsetValue == null) ? "N/A" : offsetValue.toString(); clockOffset = offsetValue != null ? offsetValue.longValue() : 0L; Log.i(TAG, " Reference Identifier:\t" + refAddr); Log.i(TAG, " Reference Timestamp:\t" + refNtpTime + " " + refNtpTime.toDateString()); Log.i(TAG, " Originate Timestamp:\t" + origNtpTime + " " + origNtpTime.toDateString()); Log.i(TAG, " Receive Timestamp:\t" + rcvNtpTime + " " + rcvNtpTime.toDateString()); Log.i(TAG, " Transmit Timestamp:\t" + xmitNtpTime + " " + xmitNtpTime.toDateString()); Log.i(TAG, " Destination Timestamp:\t" + destNtpTime + " " + destNtpTime.toDateString()); Log.i(TAG, " Roundtrip delay(ms)=" + delay + ", clock offset(ms)=" + offset); }
From source file:edu.monash.merc.util.DMUtil.java
public static String generateIdBasedOnTimeStamp() { String suffix = null;//from ww w . ja v a2 s. com synchronized (lock) { try { Thread.sleep(10); } catch (Exception e) { // ignore whatever } // Long time = new Long("12219292800000"); Long time = System.currentTimeMillis(); long currentTime = new Date().getTime() + time.longValue(); suffix = encode(currentTime); } return suffix; }
From source file:org.openiot.gsn.utils.VSMonitor.java
public static void checkUpdateTimes() { for (int i = 0; i < sensorsUpdateDelay.size(); i++) { Long lastUpdated = (Long) sensorsUpdateDelay.values().toArray()[i]; String sensorName = (String) sensorsUpdateDelay.keySet().toArray()[i]; if (lastUpdated.longValue() > monitoredSensors.get(sensorName).getTimeout()) { warningsBuffer.append(sensorName).append("@").append(monitoredSensors.get(sensorName).getHost()) .append(":").append(monitoredSensors.get(sensorName).getPort()).append(" not updated for ") .append(VSensorMonitorConfig.ms2dhms(sensorsUpdateDelay.get(sensorName))) .append(" (expected <") .append(VSensorMonitorConfig.ms2dhms(monitoredSensors.get(sensorName).getTimeout())) .append(")\n"); nSensorsLate++;/* www. ja va2s . c o m*/ } else { infosBuffer.append(sensorName).append("@").append(monitoredSensors.get(sensorName).getHost()) .append(":").append(monitoredSensors.get(sensorName).getPort()).append(" (on time)\n"); } } }
From source file:net.sf.farrago.namespace.sfdc.SfdcUdx.java
public static void getDeleted(String objectName, String start, String end, PreparedStatement resultInserter) throws SQLException { SoapBindingStub binding = (SoapBindingStub) FarragoUdrRuntime.getDataServerRuntimeSupport(null); if (((start == null) || start.equals("")) || ((end == null) || end.equals(""))) { throw SfdcResource.instance().InvalidRangeException.ex(); }//from www .j ava 2 s . c om Calendar startTime; Calendar endTime; Calendar thirtyDaysAgo; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); java.util.Date sd = sdf.parse(start, new ParsePosition(0)); startTime = Calendar.getInstance(); startTime.setTime(sd); java.util.Date now = new java.util.Date(); // 30 days == 30*24*60*60*1000 ms Long thirty = new Long("2592000000"); java.util.Date thirtyDate = new java.util.Date(now.getTime() - thirty.longValue()); thirtyDaysAgo = Calendar.getInstance(); thirtyDaysAgo.setTime(thirtyDate); java.util.Date ed = sdf.parse(end, new ParsePosition(0)); endTime = Calendar.getInstance(); endTime.setTime(ed); } catch (Exception ex) { ex.printStackTrace(); throw SfdcResource.instance().InvalidTimeException.ex(ex.getMessage()); } if (thirtyDaysAgo.compareTo(startTime) > 0) { throw SfdcResource.instance().InvalidStartTimeException.ex(startTime.getTime().toString()); } if (startTime.compareTo(endTime) > 0) { throw SfdcResource.instance().InvalidEndTimeException.ex(endTime.getTime().toString(), startTime.getTime().toString()); } SfdcDataServer server = (SfdcDataServer) FarragoUdrRuntime.getDataServerRuntimeSupport(new Object()); try { DescribeSObjectResult describeSObjectResult = (DescribeSObjectResult) server .getEntityDescribe(objectName); // check the name if ((describeSObjectResult != null) && describeSObjectResult.getName().equals(objectName)) { // check if data replication is allowed on object if (!describeSObjectResult.isReplicateable()) { throw SfdcResource.instance().ReplicationException.ex(objectName); } } else { throw SfdcResource.instance().InvalidObjectException.ex(objectName); } GetDeletedResult gdr = binding.getDeleted(objectName, startTime, endTime); if ((gdr.getDeletedRecords() != null) && (gdr.getDeletedRecords().length > 0)) { for (int i = 0; i < gdr.getDeletedRecords().length; i++) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); StringBuffer sbuf = new StringBuffer(); String idString = gdr.getDeletedRecords(i).getId(); int prec = 25 + server.getVarcharPrecision(); if (idString.length() > prec) { idString = idString.substring(0, prec); } resultInserter.setString(1, idString); String timeStr = sdf .format(gdr.getDeletedRecords(i).getDeletedDate().getTime(), sbuf, new FieldPosition(0)) .toString(); resultInserter.setTimestamp(2, java.sql.Timestamp.valueOf(timeStr)); resultInserter.executeUpdate(); } } } catch (AxisFault ae) { SQLException retryExcn = new SQLException(ae.getFaultString(), null, 460150); Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn); throw SfdcResource.instance().BindingCallException.ex(ae.getFaultString(), chainedEx); } catch (RemoteException re) { SQLException retryExcn = new SQLException(re.getMessage(), null, 460150); Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn); throw SfdcResource.instance().BindingCallException.ex(re.getMessage(), chainedEx); } }
From source file:org.openiot.gsn.utils.GSNMonitor.java
public static void checkUpdateTimes() { for (int i = 0; i < sensorsUpdateDelay.size(); i++) { Long lastUpdated = (Long) sensorsUpdateDelay.values().toArray()[i]; String sensorName = (String) sensorsUpdateDelay.keySet().toArray()[i]; if (lastUpdated.longValue() > monitoredSensors.get(sensorName).getTimeout()) { raiseStatusTo(STATUS_WARNING); warningsBuffer.append(sensorName).append("@").append(monitoredSensors.get(sensorName).getHost()) .append(":").append(monitoredSensors.get(sensorName).getPort()).append(" not updated for ") .append(VSensorMonitorConfig.ms2dhms(sensorsUpdateDelay.get(sensorName))) .append(" (expected <") .append(VSensorMonitorConfig.ms2dhms(monitoredSensors.get(sensorName).getTimeout())) .append(")\n"); nSensorsLate++;//from www . j a va 2s .c o m } else { infosBuffer.append(sensorName).append("@").append(monitoredSensors.get(sensorName).getHost()) .append(":").append(monitoredSensors.get(sensorName).getPort()).append(" (on time)\n"); } } }
From source file:com.jkoolcloud.jesl.simulator.TNT4JSimulator.java
public static void incrementValue(Map<String, Long> map, String item, long amount) { Long prev = map.put(item, amount); if (prev != null) { map.put(item, prev.longValue() + amount); }/*ww w. ja va 2 s .c o m*/ }