List of usage examples for java.lang System identityHashCode
@HotSpotIntrinsicCandidate public static native int identityHashCode(Object x);
From source file:org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod.java
@SuppressWarnings("rawtypes") @Override//from w w w.j a va 2 s . co m protected Object doInvokeInternal(final Object target, Object[] arguments) { GrailsDomainClass domainClass = (GrailsDomainClass) application.getArtefact(DomainClassArtefactHandler.TYPE, target.getClass().getName()); DeferredBindingActions.runActions(); boolean shouldFlush = shouldFlush(arguments); boolean shouldValidate = shouldValidate(arguments, domainClass); if (shouldValidate) { Validator validator = domainClass.getValidator(); if (domainClass instanceof DefaultGrailsDomainClass) { GrailsHibernateUtil.autoAssociateBidirectionalOneToOnes((DefaultGrailsDomainClass) domainClass, target); } Errors errors = setupErrorsProperty(target); if (validator != null) { application.getMainContext().publishEvent(new ValidationEvent(datastore, target)); boolean deepValidate = true; Map argsMap = null; if (arguments.length > 0 && arguments[0] instanceof Map) { argsMap = (Map) arguments[0]; } if (argsMap != null && argsMap.containsKey(ARGUMENT_DEEP_VALIDATE)) { deepValidate = GrailsClassUtils.getBooleanFromMap(ARGUMENT_DEEP_VALIDATE, argsMap); } AbstractPersistentConstraint.sessionFactory.set(datastore.getSessionFactory()); try { if (deepValidate && (validator instanceof CascadingValidator)) { ((CascadingValidator) validator).validate(target, errors, deepValidate); } else { validator.validate(target, errors); } } finally { AbstractPersistentConstraint.sessionFactory.remove(); } if (errors.hasErrors()) { handleValidationError(domainClass, target, errors); boolean shouldFail = shouldFail(application, domainClass); if (argsMap != null && argsMap.containsKey(ARGUMENT_FAIL_ON_ERROR)) { shouldFail = GrailsClassUtils.getBooleanFromMap(ARGUMENT_FAIL_ON_ERROR, argsMap); } if (shouldFail) { throw new ValidationException("Validation Error(s) occurred during save()", errors); } return null; } setObjectToReadWrite(target); } } // this piece of code will retrieve a persistent instant // of a domain class property is only the id is set thus // relieving this burden off the developer if (domainClass != null) { autoRetrieveAssocations(domainClass, target); } if (!shouldValidate) { Set<Integer> identifiers = disableAutoValidationFor.get(); identifiers.add(System.identityHashCode(target)); } if (shouldInsert(arguments)) { return performInsert(target, shouldFlush); } return performSave(target, shouldFlush); }
From source file:org.polymap.core.runtime.event.EventManager.java
/** * Registeres the given {@link EventHandler annotated} handler as event listener. * <p/>/*ww w . ja v a 2s. c o m*/ * Listeners are <b>weakly</b> referenced by the EventManager. A listener is * reclaimed by the GC and removed from the EventManager as soon as there is no * strong reference to it. An anonymous inner class can not be used as event * listener. * <p/> * The given handler and filters are called within the <b> * {@link SessionContext#current() current session}</b>. If the current method * call is done outside a session, then the handler is called with no session * set. A handler can use {@link EventManager#publishSession()} to retrieve the * session the event was published from. * * @see EventHandler * @param annotated The {@link EventHandler annotated} event handler. * @throws IllegalStateException If the handler is subscribed already. */ public void subscribe(Object annotated, EventFilter... filters) { assert annotated != null; Integer key = System.identityHashCode(annotated); AnnotatedEventListener listener = new AnnotatedEventListener(annotated, key, filters); if (!listeners.add(listener)) { throw new IllegalStateException("Event handler already registered: " + annotated); } }
From source file:brooklyn.util.internal.ssh.sshj.SshjTool.java
@Override public void connect() { try {//from w w w.j av a2 s . c o m if (LOG.isTraceEnabled()) LOG.trace("Connecting SshjTool {} ({})", this, System.identityHashCode(this)); acquire(sshClientConnection); } catch (Exception e) { if (LOG.isDebugEnabled()) LOG.debug(toString() + " failed to connect (rethrowing)", e); throw propagate(e, "failed to connect"); } }
From source file:com.microsoft.tfs.core.clients.workitem.internal.WorkItemImpl.java
@Override public String toString() { final String messageFormat = Messages.getString("WorkItemImpl.WorkItemIdWithHexFormat"); //$NON-NLS-1$ return MessageFormat.format(messageFormat, getID(), Integer.toHexString(System.identityHashCode(this))); }
From source file:it.tidalwave.northernwind.core.impl.model.DefaultSite.java
/******************************************************************************************************************* * * {@inheritDoc}/*w ww. j a v a 2 s . c om*/ * ******************************************************************************************************************/ @Override @Nonnull public String toString() { return String.format("DefaultSite(@%x)", System.identityHashCode(this)); }
From source file:org.broadleafcommerce.common.copy.MultiTenantCopyContext.java
/** * Create a new instance of the polymorphic entity type - could be an extended type outside of Broadleaf. * * @param instance the object instance for the actual entity type (could be extended) * @param <G>/*from w w w .j ava 2 s.c o m*/ * @return the new, empty instance of the entity * @throws java.lang.CloneNotSupportedException */ public <G> CreateResponse<G> createOrRetrieveCopyInstance(Object instance) throws CloneNotSupportedException { BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext(); context.setCurrentCatalog(getToCatalog()); context.setCurrentProfile(getToSite()); context.setSite(getToSite()); if (instance instanceof Status && 'Y' == ((Status) instance).getArchived()) { throw new CloneNotSupportedException("Attempting to clone an archived instance"); } Class<?> instanceClass = instance.getClass(); if (instanceClass.getAnnotation(Embeddable.class) != null) { G response; try { response = (G) instanceClass.newInstance(); } catch (InstantiationException e) { throw ExceptionHelper.refineException(e); } catch (IllegalAccessException e) { throw ExceptionHelper.refineException(e); } return new CreateResponse<G>(response, false); } Long originalId = getIdentifier(instance); Object previousClone; if (currentEquivalentMap.inverse().containsKey(instanceClass.getName() + "_" + originalId)) { previousClone = currentCloneMap .get(currentEquivalentMap.inverse().get(instanceClass.getName() + "_" + originalId)); } else { previousClone = getClonedVersion(instanceClass, originalId); } G response; boolean alreadyPopulate; if (previousClone != null) { response = (G) previousClone; alreadyPopulate = true; } else { try { response = (G) instanceClass.newInstance(); } catch (InstantiationException e) { throw ExceptionHelper.refineException(e); } catch (IllegalAccessException e) { throw ExceptionHelper.refineException(e); } checkCloneable(response); alreadyPopulate = false; currentEquivalentMap.put(System.identityHashCode(response), instanceClass.getName() + "_" + originalId); currentCloneMap.put(System.identityHashCode(response), response); try { for (Field field : getAllFields(instanceClass)) { if (field.getType().getAnnotation(Embeddable.class) != null && MultiTenantCloneable.class.isAssignableFrom(field.getType())) { Object embeddable = field.get(instance); if (embeddable != null) { field.set(response, ((MultiTenantCloneable) embeddable) .createOrRetrieveCopyInstance(this).getClone()); } } } } catch (IllegalAccessException e) { throw ExceptionHelper.refineException(e); } } context.setCurrentCatalog(getFromCatalog()); context.setCurrentProfile(getFromSite()); context.setSite(getFromSite()); return new CreateResponse<G>(response, alreadyPopulate); }
From source file:org.apache.ranger.plugin.policyevaluator.RangerDefaultPolicyEvaluator.java
@Override public void evaluate(RangerAccessRequest request, RangerAccessResult result) { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerDefaultPolicyEvaluator.evaluate(" + request + ", " + result + ")"); }//from w ww. jav a 2s .c o m RangerPerfTracer perf = null; if (RangerPerfTracer.isPerfTraceEnabled(PERF_POLICY_REQUEST_LOG)) { perf = RangerPerfTracer.getPerfTracer(PERF_POLICY_REQUEST_LOG, "RangerPolicyEvaluator.evaluate(requestHashCode=" + Integer.toHexString(System.identityHashCode(request)) + "," + perfTag + ")"); } if (request != null && result != null) { if (!result.getIsAccessDetermined() || !result.getIsAuditedDetermined()) { RangerPolicyResourceMatcher.MatchType matchType = resourceMatcher != null ? resourceMatcher.getMatchType(request.getResource(), request.getContext()) : RangerPolicyResourceMatcher.MatchType.NONE; final boolean isMatched; if (request.isAccessTypeAny()) { isMatched = matchType != RangerPolicyResourceMatcher.MatchType.NONE; } else if (request .getResourceMatchingScope() == RangerAccessRequest.ResourceMatchingScope.SELF_OR_DESCENDANTS) { isMatched = matchType == RangerPolicyResourceMatcher.MatchType.SELF || matchType == RangerPolicyResourceMatcher.MatchType.DESCENDANT; } else { isMatched = matchType == RangerPolicyResourceMatcher.MatchType.SELF || matchType == RangerPolicyResourceMatcher.MatchType.ANCESTOR; } if (isMatched) { if (RangerTagAccessRequest.class.isInstance(request)) { matchType = ((RangerTagAccessRequest) request).getMatchType(); } if (!result.getIsAuditedDetermined()) { if (isAuditEnabled()) { result.setIsAudited(true); result.setAuditPolicyId(getPolicy().getId()); } } if (!result.getIsAccessDetermined()) { if (hasMatchablePolicyItem(request)) { evaluatePolicyItems(request, result, matchType != RangerPolicyResourceMatcher.MatchType.DESCENDANT); } } } } } RangerPerfTracer.log(perf); if (LOG.isDebugEnabled()) { LOG.debug("<== RangerDefaultPolicyEvaluator.evaluate(" + request + ", " + result + ")"); } }
From source file:com.sworddance.util.perf.LapTimer.java
/** * Create a LapTimer with no name and an allowed lapHistory of 100 * Must also be available for the serialization of LapTimers. * * @see #LapTimer(String,Runnable,int)/*from ww w . jav a 2s. c om*/ */ public LapTimer() { this(null, null, 100); this.timerName = "LapTimer#" + System.identityHashCode(this); }
From source file:WeakIdentityMap.java
public V get(Object key) { if (key == null) { key = KeyFactory.NULL;//ww w .j a v a 2s . c om } Entry<K, V>[] tab = this.table; int hash = System.identityHashCode(key); int index = (hash & 0x7fffffff) % tab.length; for (Entry<K, V> e = tab[index], prev = null; e != null; e = e.next) { Object entryKey = e.get(); if (entryKey == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } this.count--; } else if (e.hash == hash && key == entryKey) { return e.value; } else { prev = e; } } return null; }
From source file:com.cloud.utils.db.Transaction.java
public static Connection getStandaloneAwsapiConnection() { try {/*ww w .j a va 2 s . c o m*/ Connection conn = s_awsapiDS.getConnection(); if (s_connLogger.isTraceEnabled()) { s_connLogger.trace( "Retrieving a standalone connection for usage: dbconn" + System.identityHashCode(conn)); } return conn; } catch (SQLException e) { s_logger.warn("Unexpected exception: ", e); return null; } }