List of usage examples for java.lang System identityHashCode
@HotSpotIntrinsicCandidate public static native int identityHashCode(Object x);
From source file:org.castor.cpa.test.test88.TestLazyLoading.java
public void testIterWithAdd() throws PersistenceException { LOG.info("Running testIterWithAdd..."); // Tests iterating over a lazy-loaded Collection that has // had data added ArrayList<LazyAddress> masterData = new ArrayList<LazyAddress>(); Identity fullname = new Identity("First", "Person"); LazyPerson loadPerson;// w ww. j ava2s.co m // test java.util.Collection.clear() for lazy loading (bug 801) _db.begin(); loadPerson = _db.load(LazyEmployee.class, fullname); Collection<LazyAddress> addresses = loadPerson.getAddress(); // Store the list in the database at the start of the transaction, // for comparison purposes Iterator<LazyAddress> it = addresses.iterator(); while (it.hasNext()) { masterData.add(it.next()); } _db.rollback(); // Now start over, and add something to the collection. Then try // iterating and clearing the collection _db.begin(); loadPerson = _db.load(LazyEmployee.class, fullname); addresses = loadPerson.getAddress(); LazyAddress la = new LazyAddress(); la.setId(999); la.setStreet("Rogue Street"); la.setCity("Rogue City"); la.setState("RS"); la.setZip("10666"); la.setPerson(loadPerson); addresses.add(la); LOG.debug("masterData size: " + masterData.size()); LOG.debug("addresses size: " + addresses.size()); if (addresses.size() != (masterData.size() + 1)) { fail("Lazy collection size is different from what is expected"); } boolean matchNewElement = false; int matchCount = 0; it = addresses.iterator(); /* * The problem with the following block is that the second loop is * entered but never exited. */ bigloop: while (it.hasNext()) { LazyAddress addr1 = it.next(); Iterator<LazyAddress> it2 = masterData.iterator(); while (it2.hasNext()) { LazyAddress addr2 = it2.next(); LOG.debug("addr1: " + addr1); LOG.debug("addr2: " + addr2); if (addr2.equals(addr1)) { LOG.debug("matched"); matchCount++; continue bigloop; } else if (addr1 == la) { LOG.debug("matched lazy"); matchNewElement = true; matchCount++; continue bigloop; } else { LOG.debug("no match"); } } LOG.debug("newly added:" + la + "@" + System.identityHashCode(la)); LOG.debug("matchNewElement " + matchNewElement); LOG.debug("matchCount " + matchCount); LOG.error("Error: found unexpected address in the new lazy collection"); fail("found unexpected address in the new lazy collection:" + addr1 + "@" + System.identityHashCode(la)); } if (!matchNewElement) { LOG.error("Error: Newly added element is missing"); fail("Newly added element is missing"); } if (matchCount != (masterData.size() + 1)) { LOG.error("Error: Lazy collection contains unexpected number of elements"); fail("Lazy collection contains unexpected number of elements. expected: " + (masterData.size() + 1) + " found: " + matchCount); } addresses.clear(); if (!addresses.isEmpty()) { LOG.error("Error: clear failed in testIterWithAdd"); fail("Error: clear failed in testIterWithAdd"); } _db.rollback(); }
From source file:org.apache.geode.internal.DeployedJar.java
@Override public String toString() { final StringBuilder sb = new StringBuilder(getClass().getName()); sb.append('@').append(System.identityHashCode(this)).append('{'); sb.append("jarName=").append(this.jarName); sb.append(",file=").append(this.file.getAbsolutePath()); sb.append(",md5hash=").append(Arrays.toString(this.md5hash)); sb.append(",version=").append(this.getVersion()); sb.append('}'); return sb.toString(); }
From source file:WeakIdentityMap.java
public Set<Map.Entry<K, V>> entrySet() { if (this.entrySet == null) { this.entrySet = new AbstractSet<Map.Entry<K, V>>() { public Iterator<Map.Entry<K, V>> iterator() { return createHashIterator(ENTRIES); }//from w w w . ja va2s. c om public boolean contains(Object o) { if (!(o instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) o; Object key = entry.getKey(); Entry[] tab = WeakIdentityMap.this.table; int hash = System.identityHashCode(key); int index = (hash & 0x7fffffff) % tab.length; for (Entry e = tab[index], prev = null; e != null; e = e.next) { Object entryKey = e.get(); if (entryKey == null) { // Clean up after a cleared Reference. WeakIdentityMap.this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } WeakIdentityMap.this.count--; } else if (e.hash == hash && e.equals(entry)) { return true; } else { prev = e; } } return false; } public boolean remove(Object o) { if (!(o instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) o; Object key = entry.getKey(); Entry[] tab = WeakIdentityMap.this.table; int hash = System.identityHashCode(key); int index = (hash & 0x7fffffff) % tab.length; for (Entry e = tab[index], prev = null; e != null; e = e.next) { if (e.get() == null) { // Clean up after a cleared Reference. WeakIdentityMap.this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } WeakIdentityMap.this.count--; } else if (e.hash == hash && e.equals(entry)) { WeakIdentityMap.this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } WeakIdentityMap.this.count--; e.value = null; return true; } else { prev = e; } } return false; } public int size() { return WeakIdentityMap.this.count; } public void clear() { WeakIdentityMap.this.clear(); } public String toString() { return WeakIdentityMap.toString(this); } }; } return this.entrySet; }
From source file:com.ayuget.redface.ui.fragment.PostsFragment.java
public void loadPage(int page) { Log.d(LOG_TAG, String.format("@%d -> Loading page '%d'", System.identityHashCode(this), page)); subscribe(/*from w w w . java 2s . co m*/ dataService.loadPosts(userManager.getActiveUser(), topic, page, new EndlessObserver<List<Post>>() { @Override public void onNext(List<Post> posts) { swipeRefreshLayout.setRefreshing(false); displayedPosts.clear(); displayedPosts.addAll(posts); topicPageView.setTopic(topic); topicPageView.setPage(currentPage); Log.d(LOG_TAG, String.format("@%d -> Done loading page, settings posts", System.identityHashCode(PostsFragment.this))); topicPageView.setPosts(posts); showPosts(); } @Override public void onError(Throwable throwable) { swipeRefreshLayout.setRefreshing(false); Log.e(LOG_TAG, String.format("Error displaying topic '%s'", topic), throwable); showErrorView(); } })); }
From source file:org.openvpms.web.component.mail.MailEditor.java
/** * Downloads an attachment, if it has been double clicked. * * @param downloader the downloader to use * @param mimeType the mime type. May be {@code null} * @param reference the document reference *//*from w w w . ja v a 2s.c o m*/ private void onDownload(Downloader downloader, String mimeType, IMObjectReference reference) { int hash = System.identityHashCode(downloader); // avoid holding onto the downloader reference if (monitor.isDoubleClick(hash)) { downloader.download(mimeType); } for (int i = 0; i < documents.size(); ++i) { if (documents.get(i).getReference().equals(reference)) { attachments.getSelectionModel().setSelectedIndex(i, true); break; } } }
From source file:org.kitodo.filemanagement.locking.LockManagement.java
/** * With this method, file management reports that it has opened a write * channel for a URI. It wraps around the stream with a stream guard because * the lock management must be able to detect when the stream is shut down * because it depends on whether the lock in question can be reset, is * automatically reset, or other locks can be granted or not. * //from w ww . j a v a 2 s . c o m * @param uri * URI to which a read channel was opened * @param outputStream * the opened output stream * @param lockingResult * the authorization object * @return the output stream that the user should use. The output stream is * wrapped in an instance of a vigilant output stream that notifies * the lock management when the stream is closed. */ public VigilantOutputStream reportGrant(URI uri, OutputStream outputStream, LockResult lockingResult) { GrantedAccess permissions = (GrantedAccess) lockingResult; if (logger.isTraceEnabled()) { String hexString = Integer.toHexString(System.identityHashCode(outputStream)); logger.trace("For {}, the writing channel {} was opened to {}.", permissions, hexString, uri); } AbstractLock lock = permissions.getLock(uri); UpgradeableReadLock upgradeableReadLock = null; if (lock instanceof UpgradeableReadLock) { upgradeableReadLock = (UpgradeableReadLock) lock; upgradeableReadLock.noteWritingStarts(); } VigilantOutputStream vigilantOutputStream = new VigilantOutputStream(outputStream, uri, streamManagement, immutableReadFileManagement, upgradeableReadLock, permissions); streamManagement.registerStreamGuard(vigilantOutputStream); return vigilantOutputStream; }
From source file:org.pentaho.reporting.engine.classic.core.cache.CachingDataFactory.java
private TableModel queryDesignTimeStructureInternal(final String query, final DataRow parameters) throws ReportDataFactoryException { if (profileDataSources && CachingDataFactory.logger.isDebugEnabled()) { CachingDataFactory.logger// www.j ava 2 s.c o m .debug(System.identityHashCode(Thread.currentThread()) + ": Query processing time: Starting"); } final long startTime = System.currentTimeMillis(); try { return backend.queryDesignTimeStructure(query, parameters); } finally { final long queryTime = System.currentTimeMillis(); if (profileDataSources && CachingDataFactory.logger.isDebugEnabled()) { CachingDataFactory.logger.debug(System.identityHashCode(Thread.currentThread()) + ": Query processing time: " + ((queryTime - startTime) / 1000.0)); } } }
From source file:de.innovationgate.wgpublisher.webtml.utils.TMLContext.java
public void removeThreadMainContext() { LinkedList<TMLContext> contexts = _threadMainContexts.get(); if ("true".equals(System.getProperty("de.innovationgate.wga.threadmaincontexts.verbose"))) { try {/* w w w . ja va 2 s . c o m*/ StackTraceElement[] elements = Thread.currentThread().getStackTrace(); getlog().info("Thread " + Thread.currentThread().hashCode() + " - Removing main context '" + getpath() + "' (" + System.identityHashCode(this) + ") at position " + (contexts.size() - 1) + ", Stacktrace " + elements[2]); } catch (WGAPIException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (contexts != null) { TMLContext lastContext = contexts.removeLast(); if (lastContext != this) { try { getlog().error( "Error in WebTML context management: Thread main context mismatch on removal. Removed: " + this.getpath() + " (" + System.identityHashCode(this) + "), In stack: " + lastContext.getpath() + " (" + System.identityHashCode(lastContext) + ")"); } catch (WGAPIException e) { } } } }
From source file:org.apache.solr.core.CoreContainer.java
/** * Stops all cores.// ww w. ja v a 2 s . co m */ public void shutdown() { log.info("Shutting down CoreContainer instance=" + System.identityHashCode(this)); synchronized (cores) { try { for (SolrCore core : cores.values()) { core.close(); } cores.clear(); } finally { if (zkController != null) { zkController.close(); } if (zkServer != null) { zkServer.stop(); } isShutDown = true; } } }
From source file:net.ontopia.topicmaps.nav2.portlets.pojos.RelatedTopics.java
private void updateCache(TopicMapIF topicmap) { if (System.identityHashCode(topicmap.getStore()) == storeid && System.identityHashCode(topicmap) == tmid) return; // we already have this String decl = "using port for i\"http://psi.ontopia.net/portlets/\" "; QueryProcessorIF proc = QueryUtils.getQueryProcessor(topicmap); weaktypes_cache = new CompactHashSet(); try {/* w w w . j ava 2s.c o m*/ QueryResultIF result = proc.execute(decl + "port:not-semantic-type($AT : port:type)?"); while (result.next()) weaktypes_cache.add(((TopicIF) result.getValue(0)).getObjectId()); result.close(); } catch (InvalidQueryException e) { // happens if the port:* topics don't exist in the TM; that's OK } excltopics_cache = new CompactHashSet(); try { QueryResultIF result = proc.execute(decl + "port:is-hidden-topic-type($AT : port:type)?"); while (result.next()) excltopics_cache.add(((TopicIF) result.getValue(0)).getObjectId()); result.close(); } catch (InvalidQueryException e) { // happens if the port:* topics don't exist in the TM; that's OK } exclassocs_cache = new CompactHashSet(); try { QueryResultIF result = proc.execute(decl + "port:is-hidden-association-type($AT : port:type)?"); while (result.next()) exclassocs_cache.add(((TopicIF) result.getValue(0)).getObjectId()); result.close(); } catch (InvalidQueryException e) { // happens if the port:* topics don't exist in the TM; that's OK } sort = TopicStringifiers.getFastSortNameStringifier(topicmap); storeid = System.identityHashCode(topicmap.getStore()); tmid = System.identityHashCode(topicmap); }