List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:org.eclipse.gyrex.cloud.internal.zk.ZooKeeperGate.java
/** * Closes the gate.//w ww . j a v a2 s . c o m * * @param notify * set to <code>true</code> to notify registered connection * listeners */ void shutdown(final boolean notify) { if (CloudDebug.zooKeeperGateLifecycle) { LOG.debug("Shutdown of ZooKeeper Gate. {}", this, new Exception("ZooKeeper Gate Shutdown Call Stack")); } // close ZooKeeper try { zooKeeper.close(); LOG.info("ZooKeeper session 0x{} closed. Gate ({}) shut down.", Long.toHexString(zooKeeper.getSessionId()), this); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); } catch (final RuntimeException e) { // ignored shutdown exceptions if (CloudDebug.zooKeeperGateLifecycle) { LOG.debug("Ignored exception during shutdown: {}", e.getMessage(), e); } } // notify listeners if (notify) { notifyGateDown(); } }
From source file:io.orchestrate.client.itest.KvTest.java
@Theory public void conditionalMergePatchKey(@ForAll(sampleSize = 10) final String key) throws InterruptedException { assumeThat(key, not(isEmptyString())); String name1 = Long.toHexString(RAND.nextLong()); final KvMetadata kvMetadata = insertItem(key, "{`name1`:`%s`}", name1); String name2 = Long.toHexString(RAND.nextLong()); final KvMetadata patched = client.kv(collection(), key).ifMatch(kvMetadata.getRef()) .merge("{\"name2\":\"" + name2 + "\"}").get(); assertNotEquals(kvMetadata, patched); final KvObject<ObjectNode> kvObject = client.kv(kvMetadata.getCollection(), kvMetadata.getKey()) .get(ObjectNode.class).get(); assertEquals(patched.getRef(), kvObject.getRef()); assertEquals(name1, kvObject.getValue().get("name1").asText()); assertEquals(name2, kvObject.getValue().get("name2").asText()); }
From source file:io.orchestrate.client.itest.KvTest.java
@Theory public void conditionalMergePatchKeyAsync(@ForAll(sampleSize = 10) final String key) throws InterruptedException { assumeThat(key, not(isEmptyString())); String name1 = Long.toHexString(RAND.nextLong()); final KvMetadata kvMetadata = insertItem(key, "{`name1`:`%s`}", name1); String name2 = Long.toHexString(RAND.nextLong()); final BlockingQueue<KvMetadata> queue = DataStructures.getLTQInstance(KvMetadata.class); client.kv(collection(), key).ifMatch(kvMetadata.getRef()).merge("{\"name2\":\"" + name2 + "\"}") .on(new ResponseAdapter<KvMetadata>() { @Override/* w ww .j a v a2 s . c om*/ public void onFailure(final Throwable error) { fail(error.getMessage()); } @Override public void onSuccess(final KvMetadata object) { queue.add(object); } }); final KvMetadata patched = queue.poll(5000, TimeUnit.MILLISECONDS); assertNotEquals(kvMetadata, patched); final KvObject<ObjectNode> kvObject = client.kv(kvMetadata.getCollection(), kvMetadata.getKey()) .get(ObjectNode.class).get(); assertEquals(patched.getRef(), kvObject.getRef()); assertEquals(name1, kvObject.getValue().get("name1").asText()); assertEquals(name2, kvObject.getValue().get("name2").asText()); }
From source file:org.trafodion.dtm.TmAuditTlog.java
public static String getRecord(final String transidString) throws IOException { if (LOG.isTraceEnabled()) LOG.trace("getRecord start"); long lvTransid = Long.parseLong(transidString, 10); int lv_lockIndex = (int) (lvTransid & tLogHashKey); String lvTxState = new String("NO RECORD"); try {/*from www.ja va 2 s. co m*/ Get g; //create our own hashed key long key = (((lvTransid & tLogHashKey) << tLogHashShiftFactor) + (lvTransid & 0xFFFFFFFF)); if (LOG.isTraceEnabled()) LOG.trace("key: " + key + " hex: " + Long.toHexString(key)); g = new Get(Bytes.toBytes(key)); try { Result r = table[lv_lockIndex].get(g); byte[] value = r.getValue(TLOG_FAMILY, ASN_STATE); StringTokenizer st = new StringTokenizer(value.toString(), ","); String asnToken = st.nextElement().toString(); String transidToken = st.nextElement().toString(); lvTxState = st.nextElement().toString(); if (LOG.isTraceEnabled()) LOG.trace("transid: " + transidToken + " state: " + lvTxState); } catch (IOException e) { LOG.error("getRecord IOException"); throw e; } } catch (Exception e) { LOG.error("getRecord Exception " + e); throw e; } if (LOG.isTraceEnabled()) LOG.trace("getRecord end; returning String:" + lvTxState); return lvTxState; }
From source file:jef.tools.StringUtils.java
/** * CRC?,8???//from w w w. j a v a 2 s .c o m */ public static String getCRC(InputStream in) { CRC32 crc32 = new CRC32(); byte[] b = new byte[65536]; int len = 0; try { while ((len = in.read(b)) != -1) { crc32.update(b, 0, len); } return Long.toHexString(crc32.getValue()); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(in); } }
From source file:nf.frex.android.FrexActivity.java
private void readFrexDoc(final Uri frexDocUri) { new Thread(new Runnable() { @Override//from www . j av a 2s . c o m public void run() { try { InputStream stream; try { stream = openLocalContentStream(frexDocUri); } catch (IOException e) { try { stream = openHttpContentStream(frexDocUri); } catch (IOException e1) { throw e; } } if (stream != null) { try { readFrexDoc(stream, Long.toHexString(new Random().nextLong())); } finally { stream.close(); } } } catch (IOException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); } catch (Throwable t) { Toast.makeText(FrexActivity.this, t.getClass().getSimpleName() + ": " + t.getMessage(), Toast.LENGTH_LONG).show(); } } }).start(); }
From source file:edu.harvard.i2b2.fhir.FhirUtil.java
public static Bundle pageBundle(Bundle b, int maxEntries, int pageNum) { Bundle pagedB = new Bundle(); FhirUtil.setId(pagedB, Long.toHexString(new Random().nextLong())); pagedB.setMeta(FhirUtil.createMeta()); if (maxEntries <= 0) throw new IllegalArgumentException("max Entries should be >0 "); if (pageNum < 1) throw new IllegalArgumentException("page NUmber should be >=1 "); int sob = b.getEntry().size();// size of Bundle int lowIdx = maxEntries * (pageNum - 1);// index of lowest entry in // selected page int highIdx = (maxEntries * pageNum);// index of highest entry in // selected page int lastPageNum = (int) Math.ceil(sob / maxEntries); // if low and high index of if (lowIdx > sob) { return pagedB; }// www .ja v a 2s. c o m List<Object> listBE = new ArrayList<>(); for (int i = lowIdx; i < highIdx; i++) { if (i < sob) { Resource r = FhirUtil.getResourceFromContainer(b.getEntry().get(i).getResource()); listBE.add(r); } } pagedB = createBundle(listBE); // create links // get link for self from inputBundle if it exits String baseUrlValue = null; for (BundleLink link : b.getLink()) { if (link.getRelation() != null & link.getRelation().getValue() != null & link.getRelation().getValue().equals("self") & link.getUrl() != null) { baseUrlValue = link.getUrl().getValue().replaceAll("&{0,1}page=\\d+", "").replaceAll("\\?$", ""); } } if (baseUrlValue == null) { throw new RuntimeException("the self link is null "); } // self pagedB.getLink().add(createBundleLink("self", baseUrlValue + (baseUrlValue.contains("?") ? "&" : "?") + "page=" + pageNum)); // first page pagedB.getLink().add( createBundleLink("first", baseUrlValue + (baseUrlValue.contains("?") ? "&" : "?") + "page=" + 1)); // previous if (pageNum > 1) { pagedB.getLink().add(createBundleLink("previous", baseUrlValue + (baseUrlValue.contains("?") ? "&" : "?") + "page=" + (pageNum - 1))); } // next if (pageNum < lastPageNum) { pagedB.getLink().add(createBundleLink("next", baseUrlValue + (baseUrlValue.contains("?") ? "&" : "?") + "page=" + (pageNum + 1))); } // last page pagedB.getLink().add(createBundleLink("last", baseUrlValue + (baseUrlValue.contains("?") ? "&" : "?") + "page=" + lastPageNum)); return pagedB; }
From source file:org.springframework.amqp.rabbit.core.RabbitTemplatePublisherCallbacksIntegrationTests.java
@Test public void testPublisherCallbackChannelImplCloseWithPending() throws Exception { final AtomicInteger nacks = new AtomicInteger(); Listener listener = mock(Listener.class); doAnswer(invocation -> {/* w w w . ja v a2 s. co m*/ boolean ack = (Boolean) invocation.getArguments()[1]; if (!ack) { nacks.incrementAndGet(); } return null; }).when(listener).handleConfirm(any(PendingConfirm.class), anyBoolean()); when(listener.getUUID()).thenReturn(UUID.randomUUID().toString()); when(listener.isConfirmListener()).thenReturn(true); Channel channelMock = mock(Channel.class); PublisherCallbackChannelImpl channel = new PublisherCallbackChannelImpl(channelMock); channel.addListener(listener); for (int i = 0; i < 2; i++) { long seq = i + 1000; channel.addPendingConfirm(listener, seq, new PendingConfirm(new CorrelationData(Long.toHexString(seq)), System.currentTimeMillis())); } channel.close(); assertEquals(0, TestUtils.getPropertyValue(channel, "pendingConfirms", Map.class).size()); assertEquals(2, nacks.get()); }
From source file:io.orchestrate.client.itest.KvTest.java
@Theory public void conditionalMergePatchKeyRefFailed(@ForAll(sampleSize = 10) final String key) { assumeThat(key, not(isEmptyString())); String name1 = Long.toHexString(RAND.nextLong()); insertItem(key, "{`name1`:`%s`}", name1); String name2 = Long.toHexString(RAND.nextLong()); ItemVersionMismatchException thrown = null; try {/*from ww w . j av a 2 s . c o m*/ final KvMetadata patched = client.kv(collection(), key).ifMatch("0000000000000000") .merge("{\"name2\":\"" + name2 + "\"}").get(); fail("Should have failed with a concurrency conflict."); } catch (ItemVersionMismatchException ex) { thrown = ex; } assertNotNull(thrown); }
From source file:org.trafodion.dtm.TmAuditTlog.java
public static boolean deleteRecord(final long lvTransid) throws IOException { if (LOG.isTraceEnabled()) LOG.trace("deleteRecord start " + lvTransid); String transidString = new String(String.valueOf(lvTransid)); int lv_lockIndex = (int) (lvTransid & tLogHashKey); try {/*www . j a v a2 s .c o m*/ Delete d; //create our own hashed key long key = (((lvTransid & tLogHashKey) << tLogHashShiftFactor) + (lvTransid & 0xFFFFFFFF)); if (LOG.isTraceEnabled()) LOG.trace("key: " + key + " hex: " + Long.toHexString(key)); d = new Delete(Bytes.toBytes(key)); if (LOG.isTraceEnabled()) LOG.trace("deleteRecord (" + lvTransid + ") "); table[lv_lockIndex].delete(d); } catch (Exception e) { LOG.error("deleteRecord Exception " + e); } if (LOG.isTraceEnabled()) LOG.trace("deleteRecord - exit"); return true; }