List of usage examples for java.lang Object Object
@HotSpotIntrinsicCandidate
public Object()
From source file:it.anyplace.sync.bep.BlockPuller.java
public FileDownloadObserver pullBlocks(FileBlocks fileBlocks) throws InterruptedException { logger.info("pulling file = {}", fileBlocks); checkArgument(connectionHandler.hasFolder(fileBlocks.getFolder()), "supplied connection handler %s will not share folder %s", connectionHandler, fileBlocks.getFolder());// w ww . j ava2 s . co m final Object lock = new Object(); final AtomicReference<Exception> error = new AtomicReference<>(); final Object listener = new Object() { @Subscribe public void handleResponseMessageReceivedEvent(ResponseMessageReceivedEvent event) { synchronized (lock) { try { if (!requestIds.contains(event.getMessage().getId())) { return; } checkArgument(equal(event.getMessage().getCode(), ErrorCode.NO_ERROR), "received error response, code = %s", event.getMessage().getCode()); byte[] data = event.getMessage().getData().toByteArray(); String hash = BaseEncoding.base16().encode(Hashing.sha256().hashBytes(data).asBytes()); blockCache.pushBlock(data); if (missingHashes.remove(hash)) { blocksByHash.put(hash, data); logger.debug("aquired block, hash = {}", hash); lock.notify(); } else { logger.warn("received not-needed block, hash = {}", hash); } } catch (Exception ex) { error.set(ex); lock.notify(); } } } }; FileDownloadObserver fileDownloadObserver = new FileDownloadObserver() { private long getReceivedData() { return blocksByHash.size() * BLOCK_SIZE; } private long getTotalData() { return (blocksByHash.size() + missingHashes.size()) * BLOCK_SIZE; } @Override public double getProgress() { return isCompleted() ? 1d : getReceivedData() / ((double) getTotalData()); } @Override public String getProgressMessage() { return (Math.round(getProgress() * 1000d) / 10d) + "% " + FileUtils.byteCountToDisplaySize(getReceivedData()) + " / " + FileUtils.byteCountToDisplaySize(getTotalData()); } @Override public boolean isCompleted() { return missingHashes.isEmpty(); } @Override public void checkError() { if (error.get() != null) { throw new RuntimeException(error.get()); } } @Override public double waitForProgressUpdate() throws InterruptedException { if (!isCompleted()) { synchronized (lock) { checkError(); lock.wait(); checkError(); } } return getProgress(); } @Override public InputStream getInputStream() { checkArgument(missingHashes.isEmpty(), "pull failed, some blocks are still missing"); List<byte[]> blockList = Lists .newArrayList(Lists.transform(hashList, Functions.forMap(blocksByHash))); return new SequenceInputStream(Collections .enumeration(Lists.transform(blockList, new Function<byte[], ByteArrayInputStream>() { @Override public ByteArrayInputStream apply(byte[] data) { return new ByteArrayInputStream(data); } }))); } @Override public void close() { missingHashes.clear(); hashList.clear(); blocksByHash.clear(); try { connectionHandler.getEventBus().unregister(listener); } catch (Exception ex) { } if (closeConnection) { connectionHandler.close(); } } }; try { synchronized (lock) { hashList.addAll(Lists.transform(fileBlocks.getBlocks(), new Function<BlockInfo, String>() { @Override public String apply(BlockInfo block) { return block.getHash(); } })); missingHashes.addAll(hashList); for (String hash : missingHashes) { byte[] block = blockCache.pullBlock(hash); if (block != null) { blocksByHash.put(hash, block); missingHashes.remove(hash); } } connectionHandler.getEventBus().register(listener); for (BlockInfo block : fileBlocks.getBlocks()) { if (missingHashes.contains(block.getHash())) { int requestId = Math.abs(new Random().nextInt()); requestIds.add(requestId); connectionHandler.sendMessage(Request.newBuilder().setId(requestId) .setFolder(fileBlocks.getFolder()).setName(fileBlocks.getPath()) .setOffset(block.getOffset()).setSize(block.getSize()) .setHash(ByteString.copyFrom(BaseEncoding.base16().decode(block.getHash()))) .build()); logger.debug("sent request for block, hash = {}", block.getHash()); } } return fileDownloadObserver; } } catch (Exception ex) { fileDownloadObserver.close(); throw ex; } }
From source file:org.openspaces.eviction.test.ClassSpecificOrderTest.java
@Test public void inClassLRUModifyTest() throws Exception { logger.info("same as inClassLRUTest but modify the object instead of read it"); SilverMedal silverMedal = new SilverMedal(0); gigaSpace.write(silverMedal);/* www. ja v a 2 s . co m*/ silverMedal.setContest("Butterfly 100m"); for (int i = 1; i <= cacheSize + 10; i++) { if (i == (cacheSize / 2)) gigaSpace.write(silverMedal); else gigaSpace.write(new SilverMedal(i)); } Assert.assertEquals("amount of objects in space is larger than cache size", gigaSpace.count(new Object()), cacheSize); Assert.assertNotNull("silver medal 0 is not in space", gigaSpace.read(silverMedal)); }
From source file:main.BasicTSVImporterTest.java
/** * Test the number of reports.//from w w w . j av a2 s. co m */ @Test public void testNumberReports() { System.out.println("Running test " + this.getClass().getSimpleName() + "." + new Object() { }.getClass().getEnclosingMethod().getName()); assertEquals(9, reports.size()); }
From source file:edu.xjtu.qxcamerabridge.Qx10ServiceDelegatorImpl.java
@Override public String awaitTakePicture() { String service = "camera"; String serviceName = new Object() { }.getClass().getEnclosingMethod().getName(); JSONObject replyJson = JSONActionWrapper.jsonrpc(service, serviceName, new ArrayList<>()); String postviewurl = replyJson.getJSONArray("result").getJSONArray(0).getString(0); System.out.println(postviewurl); return postviewurl; }
From source file:com.redhat.lightblue.metadata.types.BooleanTypeTest.java
@Test public void testCompareV1Null() { assertEquals(booleanType.compare(null, new Object()), -1); }
From source file:org.slf4j.impl.PiazzaLogger.java
public void debug(String format, Object arg) { processLogs(Severity.DEBUG, format, new Object()); }
From source file:spring.travel.site.request.RequestInfoInterceptorTest.java
@Test public void shouldSetRequestInfoAttributeWithIpAddressIfNoSessionCookiePresent() throws Exception { List<String> cookies = Arrays.asList("SOME_COOKIE=\"gkdsjlsdijg\"", "ANOTHER_COOKIE=\"soihgweitj\""); when(request.getHeaders("Cookie")).thenReturn(Collections.enumeration(cookies)); assertTrue(interceptor.preHandle(request, response, new Object())); verify(request, times(1)).setAttribute(eq(attributeName), requestCaptor.capture()); Request requestInfo = requestCaptor.getValue(); assertEquals(Optional.empty(), requestInfo.getCookieValue()); assertEquals(ipAddress, requestInfo.getRemoteAddress()); assertEquals(Optional.empty(), requestInfo.getUser()); }
From source file:it.anyplace.sync.discovery.protocol.ld.LocalDiscorveryHandler.java
public List<DeviceAddress> queryAndClose(final Set<String> deviceIds) { try {//from w w w . j av a2 s . com final Object lock = new Object(); synchronized (lock) { eventBus.register(new Object() { @Subscribe public void handleMessageReceivedEvent(MessageReceivedEvent event) { if (deviceIds.contains(event.getDeviceId())) { synchronized (lock) { lock.notify(); } } } }); startListener(); sendAnnounceMessage(); try { lock.wait(MAX_WAIT); } catch (InterruptedException ex) { } synchronized (localDiscoveryRecords) { return Lists.newArrayList(Iterables.concat( Iterables.transform(deviceIds, Functions.forMap(localDiscoveryRecords.asMap())))); } } } finally { close(); } }
From source file:com.job.portal.dao.UserDetailsDAO.java
public boolean checkPhoneExists(String phone) { boolean flag = false; try {//w ww . jav a2 s . c o m String query = "select email from user_details where phone=?"; Object arr[] = { phone }; JSONObject obj = fetchOne(query, arr); flag = obj == null ? false : true; } catch (Exception e) { LogOut.log.error("In " + new Object() { }.getClass().getEnclosingClass().getName() + "." + new Object() { }.getClass().getEnclosingMethod().getName() + " " + e); } finally { return flag; } }
From source file:org.jboss.arquillian.warp.extension.spring.container.SpringMvcResultBuilderTestCase.java
/** * <p>Tests the {@link SpringMvcResultBuilder#setHandler(Object)} method.</p> *//*from w w w .j a va 2 s .c o m*/ @Test public void testSetHandler() { // given Object handler = new Object(); // when instance = SpringMvcResultBuilder.buildMvc(servletRequest).setHandler(handler); // then assertNotNull("The returned builder instance was null.", instance); assertEquals("The property has not been set.", handler, springMvcResult.getHandler()); }