com.google.common.primitives.Longs Java Examples

The following examples show how to use com.google.common.primitives.Longs. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TensorUtil.java    From jpmml-tensorflow with GNU Affero General Public License v3.0 7 votes vote down vote up
static
public List<?> getValues(Tensor tensor){
	DataType dataType = tensor.dataType();

	switch(dataType){
		case FLOAT:
			return Floats.asList(TensorUtil.toFloatArray(tensor));
		case DOUBLE:
			return Doubles.asList(TensorUtil.toDoubleArray(tensor));
		case INT32:
			return Ints.asList(TensorUtil.toIntArray(tensor));
		case INT64:
			return Longs.asList(TensorUtil.toLongArray(tensor));
		case STRING:
			return Arrays.asList(TensorUtil.toStringArray(tensor));
		case BOOL:
			return Booleans.asList(TensorUtil.toBooleanArray(tensor));
		default:
			throw new IllegalArgumentException();
	}
}
 
Example #2
Source File: OrcMetadataReader.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public List<BloomFilter> readBloomFilterIndexes(InputStream inputStream)
        throws IOException
{
    CodedInputStream input = CodedInputStream.newInstance(inputStream);
    OrcProto.BloomFilterIndex bloomFilter = OrcProto.BloomFilterIndex.parseFrom(input);
    List<OrcProto.BloomFilter> bloomFilterList = bloomFilter.getBloomFilterList();
    ImmutableList.Builder<BloomFilter> builder = ImmutableList.builder();
    for (OrcProto.BloomFilter orcBloomFilter : bloomFilterList) {
        if (orcBloomFilter.hasUtf8Bitset()) {
            ByteString utf8Bitset = orcBloomFilter.getUtf8Bitset();
            long[] bits = new long[utf8Bitset.size() / 8];
            utf8Bitset.asReadOnlyByteBuffer().order(ByteOrder.LITTLE_ENDIAN).asLongBuffer().get(bits);
            builder.add(new BloomFilter(bits, orcBloomFilter.getNumHashFunctions()));
        }
        else {
            builder.add(new BloomFilter(Longs.toArray(orcBloomFilter.getBitsetList()), orcBloomFilter.getNumHashFunctions()));
        }
    }
    return builder.build();
}
 
Example #3
Source File: SimpleDataWriter.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * Write a source record to the staging file
 *
 * @param record data record to write
 * @throws java.io.IOException if there is anything wrong writing the record
 */
@Override
public void write(byte[] record) throws IOException {
  Preconditions.checkNotNull(record);

  byte[] toWrite = record;
  if (this.recordDelimiter.isPresent()) {
    toWrite = Arrays.copyOf(record, record.length + 1);
    toWrite[toWrite.length - 1] = this.recordDelimiter.get();
  }
  if (this.prependSize) {
    long recordSize = toWrite.length;
    ByteBuffer buf = ByteBuffer.allocate(Longs.BYTES);
    buf.putLong(recordSize);
    toWrite = ArrayUtils.addAll(buf.array(), toWrite);
  }
  this.stagingFileOutputStream.write(toWrite);
  this.bytesWritten += toWrite.length;
  this.recordsWritten++;
}
 
Example #4
Source File: ConditionEvaluator.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Boolean visit(ComparisonCondition condition, @Nullable Object json) {
    Comparison comparison = condition.getComparison();
    Object value = condition.getValue();

    // Null comparisons are always false.
    if (json == null || value == null) {
        return false;
    }
    if (json instanceof Number && value instanceof Number) {
        Number nLeft = (Number) json;
        Number nRight = (Number) value;
        if (promoteToDouble(nLeft) || promoteToDouble(nRight)) {
            return matchesComparison(comparison, Doubles.compare(nLeft.doubleValue(), nRight.doubleValue()));
        } else {
            return matchesComparison(comparison, Longs.compare(nLeft.longValue(), nRight.longValue()));
        }
    }
    if (json instanceof String && value instanceof String) {
        return matchesComparison(comparison, ((String) json).compareTo((String) value));
    }
    // Everything else is unsupported and therefore does not match.
    return false;
}
 
Example #5
Source File: JavaClassProcessor.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
    if (componentType == boolean.class) {
        return Booleans.toArray((Collection) values);
    } else if (componentType == byte.class) {
        return Bytes.toArray((Collection) values);
    } else if (componentType == short.class) {
        return Shorts.toArray((Collection) values);
    } else if (componentType == int.class) {
        return Ints.toArray((Collection) values);
    } else if (componentType == long.class) {
        return Longs.toArray((Collection) values);
    } else if (componentType == float.class) {
        return Floats.toArray((Collection) values);
    } else if (componentType == double.class) {
        return Doubles.toArray((Collection) values);
    } else if (componentType == char.class) {
        return Chars.toArray((Collection) values);
    }
    return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
 
Example #6
Source File: GetDeliveryForecastForLineItems.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemIds the IDs of the line items to get a forecast for. You may pass multiple
 *     values.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(
    AdManagerServices adManagerServices, AdManagerSession session, List<Long> lineItemIds)
    throws RemoteException {
  // Get the ForecastService.
  ForecastServiceInterface forecastService =
      adManagerServices.get(session, ForecastServiceInterface.class);

  DeliveryForecastOptions options = new DeliveryForecastOptions();

  DeliveryForecast forecast =
      forecastService.getDeliveryForecastByIds(Longs.toArray(lineItemIds), options);

  for (LineItemDeliveryForecast lineItemForecast : forecast.getLineItemDeliveryForecasts()) {
    String unitType = lineItemForecast.getUnitType().toString().toLowerCase();
    System.out.printf("Forecast for line item %d:%n", lineItemForecast.getLineItemId());
    System.out.printf("\t%d %s matched%n", lineItemForecast.getMatchedUnits(), unitType);
    System.out.printf("\t%d %s delivered%n", lineItemForecast.getDeliveredUnits(), unitType);
    System.out.printf(
        "\t%d %s predicted%n", lineItemForecast.getPredictedDeliveryUnits(), unitType);
  }
}
 
Example #7
Source File: ThreadsIterator.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public ThreadsIterator(final SabotContext dbContext, final OperatorContext context) {
  this.dbContext = dbContext;
  threadMXBean = ManagementFactory.getThreadMXBean();
  final long[] ids = threadMXBean.getAllThreadIds();

  final Iterator<Long> threadIdIterator = Longs.asList(ids).iterator();

  this.threadInfoIterator = Iterators.filter(
    Iterators.transform(threadIdIterator, new Function<Long, ThreadInfo>() {

      @Override
      public ThreadInfo apply(Long input) {
        return threadMXBean.getThreadInfo(input, 100);
      }
    }),
    Predicates.notNull());

  logger.debug("number of threads = {}, number of cores = {}", ids.length, VM.availableProcessors());

  this.stats = dbContext.getWorkStatsProvider().get();
}
 
Example #8
Source File: H5tiledLayoutBB.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
DataChunk(DataBTree.DataChunk delegate) {
  this.delegate = delegate;

  // Check that the chunk length (delegate.size) isn't greater than the maximum array length that we can
  // allocate (MAX_ARRAY_LEN). This condition manifests in two ways.
  // 1) According to the HDF docs (https://www.hdfgroup.org/HDF5/doc/Advanced/Chunking/, "Chunk Maximum Limits"),
  // max chunk length is 4GB (i.e. representable in an unsigned int). Java, however, only has signed ints.
  // So, if we try to store a large unsigned int in a singed int, it'll overflow, and the signed int will come
  // out negative. We're trusting here that the chunk size read from the HDF file is never negative.
  // 2) In most JVM implementations MAX_ARRAY_LEN is actually less than Integer.MAX_VALUE (see note in ArrayList).
  // So, we could have: "MAX_ARRAY_LEN < chunkSize <= Integer.MAX_VALUE".
  if (delegate.size < 0 || delegate.size > MAX_ARRAY_LEN) {
    // We want to report the size of the chunk, but we may be in an arithmetic overflow situation. So to get the
    // correct value, we're going to reinterpet the integer's bytes as long bytes.
    byte[] intBytes = Ints.toByteArray(delegate.size);
    byte[] longBytes = new byte[8];
    System.arraycopy(intBytes, 0, longBytes, 4, 4); // Copy int bytes to the lowest 4 positions.
    long chunkSize = Longs.fromByteArray(longBytes); // Method requires an array of length 8.

    throw new IllegalArgumentException(String.format("Filtered data chunk is %s bytes and we must load it all "
        + "into memory. However the maximum length of a byte array in Java is %s.", chunkSize, MAX_ARRAY_LEN));
  }
}
 
Example #9
Source File: HttpClient.java    From intercom-java with Apache License 2.0 6 votes vote down vote up
private <T> T throwException(int responseCode, ErrorCollection errors, HttpURLConnection conn) {
    // bind some well known response codes to exceptions
    if (responseCode == 403 || responseCode == 401) {
        throw new AuthorizationException(errors);
    } else if (responseCode == 429) {
        throw new RateLimitException(errors, Ints.tryParse(conn.getHeaderField(RATE_LIMIT_HEADER)),
                Ints.tryParse(conn.getHeaderField(RATE_LIMIT_REMAINING_HEADER)),
                Longs.tryParse(conn.getHeaderField(RATE_LIMIT_RESET_HEADER)));
    } else if (responseCode == 404) {
        throw new NotFoundException(errors);
    } else if (responseCode == 422) {
        throw new InvalidException(errors);
    } else if (responseCode == 400 || responseCode == 405 || responseCode == 406) {
        throw new ClientException(errors);
    } else if (responseCode == 500 || responseCode == 503) {
        throw new ServerException(errors);
    } else {
        throw new IntercomException(errors);
    }
}
 
Example #10
Source File: TestAsyncHBaseSink.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Test
public void testOneEventWithDefaults() throws Exception {
  Map<String,String> ctxMap = new HashMap<String,String>();
  ctxMap.put("table", tableName);
  ctxMap.put("columnFamily", columnFamily);
  ctxMap.put("serializer",
          "org.apache.flume.sink.hbase.SimpleAsyncHbaseEventSerializer");
  ctxMap.put("keep-alive", "0");
  ctxMap.put("timeout", "10000");
  Context tmpctx = new Context();
  tmpctx.putAll(ctxMap);

  testUtility.createTable(tableName.getBytes(), columnFamily.getBytes());
  deleteTable = true;
  AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration());
  Configurables.configure(sink, tmpctx);
  Channel channel = new MemoryChannel();
  Configurables.configure(channel, tmpctx);
  sink.setChannel(channel);
  sink.start();
  Transaction tx = channel.getTransaction();
  tx.begin();
  Event e = EventBuilder.withBody(
          Bytes.toBytes(valBase));
  channel.put(e);
  tx.commit();
  tx.close();
  Assert.assertFalse(sink.isConfNull());
  sink.process();
  sink.stop();
  HTable table = new HTable(testUtility.getConfiguration(), tableName);
  byte[][] results = getResults(table, 1);
  byte[] out = results[0];
  Assert.assertArrayEquals(e.getBody(), out);
  out = results[1];
  Assert.assertArrayEquals(Longs.toByteArray(1), out);
}
 
Example #11
Source File: HHCODEFUNC.java    From warp10-platform with Apache License 2.0 5 votes vote down vote up
private static Object manageFormat(long hh, int res, Object input) {
  Object o;
  if (input instanceof byte[]) {
    o = Longs.toByteArray(hh);
  } else if (input instanceof String) {
    o = HHCodeHelper.toString(hh, res);
  } else {
    o = hh;
  }
  return o;
}
 
Example #12
Source File: PollerController.java    From sofa-lookout with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(Slot o1,
                   Slot o2) {
    return Longs.compare(
        o2.getCursor(),
        o1.getCursor());
}
 
Example #13
Source File: LittleEndianDataInputStream.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Reads a {@code long} as specified by {@link DataInputStream#readLong()}, except using
 * little-endian byte order.
 *
 * @return the next eight bytes of the input stream, interpreted as a {@code long} in
 *     little-endian byte order
 * @throws IOException if an I/O error occurs
 */

@CanIgnoreReturnValue // to skip some bytes
@Override
public long readLong() throws IOException {
  byte b1 = readAndCheckByte();
  byte b2 = readAndCheckByte();
  byte b3 = readAndCheckByte();
  byte b4 = readAndCheckByte();
  byte b5 = readAndCheckByte();
  byte b6 = readAndCheckByte();
  byte b7 = readAndCheckByte();
  byte b8 = readAndCheckByte();
  return Longs.fromBytes(b8, b7, b6, b5, b4, b3, b2, b1);
}
 
Example #14
Source File: ArbitraryTransaction.java    From Qora with MIT License 5 votes vote down vote up
@Override
public boolean isSignatureValid() 
{
	byte[] data = new byte[0];
	
	//WRITE TYPE
	byte[] typeBytes = Ints.toByteArray(ARBITRARY_TRANSACTION);
	typeBytes = Bytes.ensureCapacity(typeBytes, TYPE_LENGTH, 0);
	data = Bytes.concat(data, typeBytes);
	
	//WRITE TIMESTAMP
	byte[] timestampBytes = Longs.toByteArray(this.timestamp);
	timestampBytes = Bytes.ensureCapacity(timestampBytes, TIMESTAMP_LENGTH, 0);
	data = Bytes.concat(data, timestampBytes);
	
	//WRITE REFERENCE
	data = Bytes.concat(data, this.reference);
	
	//WRITE CREATOR
	data = Bytes.concat(data, this.creator.getPublicKey());
	
	//WRITE SERVICE
	byte[] serviceBytes = Ints.toByteArray(this.service);
	data = Bytes.concat(data, serviceBytes);
	
	//WRITE DATA SIZE
	byte[] dataSizeBytes = Ints.toByteArray(this.data.length);
	data = Bytes.concat(data, dataSizeBytes);
	
	//WRITE DATA
	data = Bytes.concat(data, this.data);
	
	//WRITE FEE
	byte[] feeBytes = this.fee.unscaledValue().toByteArray();
	byte[] fill = new byte[FEE_LENGTH - feeBytes.length];
	feeBytes = Bytes.concat(fill, feeBytes);
	data = Bytes.concat(data, feeBytes);
	
	return Crypto.getInstance().verify(this.creator.getPublicKey(), this.signature, data);
}
 
Example #15
Source File: AltContext.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int hashCode() {
    int h = 5381;
    h += (h << 5) + ref.hashCode();
    h += (h << 5) + alt.hashCode();
    h += (h << 5) + chromosome().hashCode();
    h += (h << 5) + Longs.hashCode(position());
    return h;
}
 
Example #16
Source File: FullTraversalSample.java    From cloud-search-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a document for indexing.
 *
 * For this connector sample, the created document is domain public
 *  searchable. The content is a simple text string.
 *
 * @param id unique local id for the document
 * @return the fully formed document ready for indexing
 */
private ApiOperation buildDocument(int id) {
  // [START cloud_search_content_sdk_domain_acl]
  // Make the document publicly readable within the domain
  Acl acl = new Acl.Builder()
      .setReaders(Collections.singletonList(Acl.getCustomerPrincipal()))
      .build();
  // [END cloud_search_content_sdk_domain_acl]

  // [START cloud_search_content_sdk_build_item]
  // Url is required. Use google.com as a placeholder for this sample.
  String viewUrl = "https://www.google.com";

  // Version is required, set to current timestamp.
  byte[] version = Longs.toByteArray(System.currentTimeMillis());

  // Using the SDK item builder class to create the document with appropriate attributes
  // (this can be expanded to include metadata fields etc.)
  Item item = IndexingItemBuilder.fromConfiguration(Integer.toString(id))
      .setItemType(IndexingItemBuilder.ItemType.CONTENT_ITEM)
      .setAcl(acl)
      .setSourceRepositoryUrl(IndexingItemBuilder.FieldOrValue.withValue(viewUrl))
      .setVersion(version)
      .build();
  // [END cloud_search_content_sdk_build_item]

  // [START cloud_search_content_sdk_build_repository_doc]
  // For this sample, content is just plain text
  String content = String.format("Hello world from sample doc %d", id);
  ByteArrayContent byteContent = ByteArrayContent.fromString("text/plain", content);

  // Create the fully formed document
  RepositoryDoc doc = new RepositoryDoc.Builder()
      .setItem(item)
      .setContent(byteContent, IndexingService.ContentFormat.TEXT)
      .build();
  // [END cloud_search_content_sdk_build_repository_doc]
  return doc;
}
 
Example #17
Source File: FileSystemMetadataTable.java    From geowave with Apache License 2.0 5 votes vote down vote up
public void add(final GeoWaveMetadata value) {
  byte[] key;
  final byte[] secondaryId =
      value.getSecondaryId() == null ? new byte[0] : value.getSecondaryId();
  byte[] endBytes;
  if (visibilityEnabled) {
    final byte[] visibility = value.getVisibility() == null ? new byte[0] : value.getVisibility();

    endBytes =
        Bytes.concat(
            visibility,
            new byte[] {(byte) visibility.length, (byte) value.getPrimaryId().length});
  } else {
    endBytes = new byte[] {(byte) value.getPrimaryId().length};
  }
  if (requiresTimestamp) {
    // sometimes rows can be written so quickly that they are the exact
    // same millisecond - while Java does offer nanosecond precision,
    // support is OS-dependent. Instead this check is done to ensure
    // subsequent millis are written at least within this ingest
    // process.
    long time = Long.MAX_VALUE - System.currentTimeMillis();
    if (time >= prevTime) {
      time = prevTime - 1;
    }
    prevTime = time;
    key = Bytes.concat(value.getPrimaryId(), secondaryId, Longs.toByteArray(time), endBytes);
  } else {
    key = Bytes.concat(value.getPrimaryId(), secondaryId, endBytes);
  }
  put(key, value.getValue());
}
 
Example #18
Source File: CreatePollTransaction.java    From Qora with MIT License 5 votes vote down vote up
public static Transaction Parse(byte[] data) throws Exception
{	
	//CHECK IF WE MATCH BLOCK LENGTH
	if(data.length < BASE_LENGTH)
	{
		throw new Exception("Data does not match block length");
	}
	
	int position = 0;
	
	//READ TIMESTAMP
	byte[] timestampBytes = Arrays.copyOfRange(data, position, position + TIMESTAMP_LENGTH);
	long timestamp = Longs.fromByteArray(timestampBytes);	
	position += TIMESTAMP_LENGTH;
	
	//READ REFERENCE
	byte[] reference = Arrays.copyOfRange(data, position, position + REFERENCE_LENGTH);
	position += REFERENCE_LENGTH;
	
	//READ CREATOR
	byte[] creatorBytes = Arrays.copyOfRange(data, position, position + CREATOR_LENGTH);
	PublicKeyAccount creator = new PublicKeyAccount(creatorBytes);
	position += CREATOR_LENGTH;
	
	//READ POLL
	Poll poll = Poll.parse(Arrays.copyOfRange(data, position, data.length));
	position += poll.getDataLength();
	
	//READ FEE
	byte[] feeBytes = Arrays.copyOfRange(data, position, position + FEE_LENGTH);
	BigDecimal fee = new BigDecimal(new BigInteger(feeBytes), 8);
	position += FEE_LENGTH;		
	
	//READ SIGNATURE
	byte[] signatureBytes = Arrays.copyOfRange(data, position, position + SIGNATURE_LENGTH);
	
	return new CreatePollTransaction(creator, poll, fee, timestamp, reference, signatureBytes);
}
 
Example #19
Source File: HaloDBTest.java    From HaloDB with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void testDeleteAfterCloseWithoutWrites() throws HaloDBException {
    String directory = TestUtils.getTestDirectory("HaloDBTest", "testDeleteAfterCloseWithoutWrites");

    HaloDB db = getTestDB(directory, new HaloDBOptions());
    db.put(Longs.toByteArray(1), Longs.toByteArray(1));
    Assert.assertEquals(db.get(Longs.toByteArray(1)), Longs.toByteArray(1));
    db.close();
    db.delete(Longs.toByteArray(1));
}
 
Example #20
Source File: TwitterSourceConnectorConfig.java    From kafka-connect-twitter with Apache License 2.0 5 votes vote down vote up
@Override
public void ensureValid(String key, Object o) {
  if (o instanceof List) {
    List<String> userIds = (List<String>) o;
    for (String userId : userIds) {
      if (null == Longs.tryParse(userId)) {
        throw new ConfigException(key, userId, "Could not parse to long.");
      }
    }
  }
}
 
Example #21
Source File: AddressUtilsTest.java    From dhcp4j with Apache License 2.0 5 votes vote down vote up
private void testSubtract(byte[] expect, byte[] in, long value) {
    byte[] out = AddressUtils.subtract(C(in), value);
    LOG.info(S(in) + " - " + value + " = " + S(out)
            + " (expected " + S(expect) + ")");
    assertArrayEquals(expect, out);

    byte[] tmp = C(Longs.toByteArray(value), in.length);
    LOG.info(S(in) + " - " + S(tmp) + " = " + S(out) + " (expected " + S(expect) + ")");
    out = AddressUtils.subtract(in, tmp);
    assertArrayEquals(expect, out);
}
 
Example #22
Source File: ParquetTimestampUtils.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * Returns GMT timestamp from binary encoded parquet timestamp (12 bytes - julian date + time of day nanos).
 *
 * @param timestampBinary INT96 parquet timestamp
 * @return timestamp in millis, GMT timezone
 */
public static long getTimestampMillis(Binary timestampBinary)
{
    if (timestampBinary.length() != 12) {
        throw new PrestoException(NOT_SUPPORTED, "Parquet timestamp must be 12 bytes, actual " + timestampBinary.length());
    }
    byte[] bytes = timestampBinary.getBytes();

    // little endian encoding - need to invert byte order
    long timeOfDayNanos = Longs.fromBytes(bytes[7], bytes[6], bytes[5], bytes[4], bytes[3], bytes[2], bytes[1], bytes[0]);
    int julianDay = Ints.fromBytes(bytes[11], bytes[10], bytes[9], bytes[8]);

    return julianDayToMillis(julianDay) + (timeOfDayNanos / NANOS_PER_MILLISECOND);
}
 
Example #23
Source File: Weaver.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private void checkForDeadlockedActiveWeaving(List<Long> activeWeavingThreadIds) {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long[] deadlockedThreadIds = threadBean.findDeadlockedThreads();
    if (deadlockedThreadIds == null || Collections.disjoint(Longs.asList(deadlockedThreadIds),
            activeWeavingThreadIds)) {
        return;
    }
    // need to disable weaving, otherwise getThreadInfo can trigger class loading and itself get
    // blocked by the deadlocked threads
    weavingDisabledForLoggingDeadlock = true;
    try {
        @Nullable
        ThreadInfo[] threadInfos = threadBean.getThreadInfo(deadlockedThreadIds,
                threadBean.isObjectMonitorUsageSupported(), false);
        StringBuilder sb = new StringBuilder();
        for (ThreadInfo threadInfo : threadInfos) {
            if (threadInfo != null) {
                sb.append('\n');
                appendThreadInfo(sb, threadInfo);
            }
        }
        logger.error("deadlock detected in class weaving, please report to the Glowroot"
                + " project:\n{}", sb);
        // no need to keep checking for (and logging) deadlocked active weaving
        throw new TerminateSubsequentExecutionsException();
    } finally {
        weavingDisabledForLoggingDeadlock = false;
    }
}
 
Example #24
Source File: PLong.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
  if (rhsType == PDecimal.INSTANCE) {
    return -((BigDecimal) rhs).compareTo(BigDecimal.valueOf(((Number) lhs).longValue()));
  } else if (equalsAny(rhsType, PDouble.INSTANCE, PFloat.INSTANCE, PUnsignedDouble.INSTANCE, PUnsignedFloat.INSTANCE)) {
    return Doubles.compare(((Number) lhs).doubleValue(), ((Number) rhs).doubleValue());
  }
  return Longs.compare(((Number) lhs).longValue(), ((Number) rhs).longValue());
}
 
Example #25
Source File: GenesisBlock.java    From Qora with MIT License 5 votes vote down vote up
public static byte[] generateHash()
{
	byte[] data = new byte[0];
	
	//WRITE VERSION
	byte[] versionBytes = Longs.toByteArray(genesisVersion);
	versionBytes = Bytes.ensureCapacity(versionBytes, 4, 0);
	data = Bytes.concat(data, versionBytes);
	
	//WRITE REFERENCE
	byte[] referenceBytes = Bytes.ensureCapacity(genesisReference, 64, 0);
	data = Bytes.concat(data, referenceBytes);
	
	//WRITE GENERATING BALANCE
	byte[] generatingBalanceBytes = Longs.toByteArray(genesisGeneratingBalance);
	generatingBalanceBytes = Bytes.ensureCapacity(generatingBalanceBytes, 8, 0);
	data = Bytes.concat(data, generatingBalanceBytes);
	
	//WRITE GENERATOR
	byte[] generatorBytes = Bytes.ensureCapacity(genesisGenerator.getPublicKey(), 32, 0);
	data = Bytes.concat(data, generatorBytes);
	
	//DIGEST
	byte[] digest = Crypto.getInstance().digest(data);		
	digest = Bytes.concat(digest, digest);
	
	return digest;
}
 
Example #26
Source File: TestRunRecording.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gathers the thread ids of threads that look deadlocked.
 *
 * @return the thread ids of deadlocked threads
 */
private static Set<Long> getDeadlockThreadIds() {
  Set<Long> deadlockedThreads = Sets.newHashSet();
  long[] dead = THREAD_BEAN.findDeadlockedThreads();
  if (dead != null) {
    deadlockedThreads.addAll(Longs.asList(dead));
  }
  dead = THREAD_BEAN.findMonitorDeadlockedThreads();
  if (dead != null) {
    deadlockedThreads.addAll(Longs.asList(dead));
  }
  return deadlockedThreads;
}
 
Example #27
Source File: ChronicleMapPersistentActorStore.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
public void put(String actorId, byte[] persistentActorBytes, long offset) {
    // first store the bytes
    backingMap.put(actorId, persistentActorBytes);
    // if this fails it is not a problem as we will just reload the state from kafka
    backingMap.put(OFFSET_KEY, Longs.toByteArray(offset));
}
 
Example #28
Source File: ReadFence.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<byte[]> getTxChanges() {
  if (tx == null) {
    throw new IllegalStateException("Transaction has not started yet");
  }
  return Collections.singleton(Bytes.concat(fenceId, Longs.toByteArray(tx.getTransactionId())));
}
 
Example #29
Source File: TestFieldCacher.java    From imhotep with Apache License 2.0 5 votes vote down vote up
private static void verifyCache(long[] cache, IntValueLookup ivl) {
    int[] docIds = new int[10];
    for (int j = 0; j < 10; ++j) docIds[j] = j;
    long[] values = new long[10];
    ivl.lookup(docIds, values, 10);
    assertEquals(Longs.asList(cache), Longs.asList(values));
}
 
Example #30
Source File: ClientDatanodeProtocolTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public HdfsBlocksMetadata getHdfsBlocksMetadata(String blockPoolId,
    long[] blockIds,
    List<Token<BlockTokenIdentifier>> tokens) throws IOException {
  List<TokenProto> tokensProtos = 
      new ArrayList<TokenProto>(tokens.size());
  for (Token<BlockTokenIdentifier> t : tokens) {
    tokensProtos.add(PBHelper.convert(t));
  }
  // Build the request
  GetHdfsBlockLocationsRequestProto request = 
      GetHdfsBlockLocationsRequestProto.newBuilder()
      .setBlockPoolId(blockPoolId)
      .addAllBlockIds(Longs.asList(blockIds))
      .addAllTokens(tokensProtos)
      .build();
  // Send the RPC
  GetHdfsBlockLocationsResponseProto response;
  try {
    response = rpcProxy.getHdfsBlockLocations(NULL_CONTROLLER, request);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
  // List of volumes in the response
  List<ByteString> volumeIdsByteStrings = response.getVolumeIdsList();
  List<byte[]> volumeIds = new ArrayList<byte[]>(volumeIdsByteStrings.size());
  for (ByteString bs : volumeIdsByteStrings) {
    volumeIds.add(bs.toByteArray());
  }
  // Array of indexes into the list of volumes, one per block
  List<Integer> volumeIndexes = response.getVolumeIndexesList();
  // Parsed HdfsVolumeId values, one per block
  return new HdfsBlocksMetadata(blockPoolId, blockIds,
      volumeIds, volumeIndexes);
}