Example usage for org.springframework.util ObjectUtils getIdentityHexString

List of usage examples for org.springframework.util ObjectUtils getIdentityHexString

Introduction

In this page you can find the example usage for org.springframework.util ObjectUtils getIdentityHexString.

Prototype

public static String getIdentityHexString(Object obj) 

Source Link

Document

Return a hex String form of an object's identity hash code.

Usage

From source file:org.springframework.http.server.reactive.UndertowServerHttpRequest.java

@Override
protected String initId() {
    return ObjectUtils.getIdentityHexString(this.exchange.getConnection());
}

From source file:org.springframework.integration.jms.JmsOutboundGateway.java

private void setContainerProperties(GatewayReplyListenerContainer container) {
    container.setConnectionFactory(this.connectionFactory);
    if (this.replyDestination != null) {
        container.setDestination(this.replyDestination);
    }//  ww  w.  j  a va2  s. co  m
    if (StringUtils.hasText(this.replyDestinationName)) {
        container.setDestinationName(this.replyDestinationName);
    }
    if (this.destinationResolver != null) {
        container.setDestinationResolver(this.destinationResolver);
    }
    container.setPubSubDomain(this.replyPubSubDomain);
    if (this.correlationKey != null) {
        String messageSelector = this.correlationKey + " LIKE '" + this.gatewayCorrelation + "%'";
        container.setMessageSelector(messageSelector);
    }
    container.setMessageListener(this);
    if (this.replyContainerProperties != null) {
        if (this.replyContainerProperties.isSessionTransacted() != null) {
            container.setSessionTransacted(this.replyContainerProperties.isSessionTransacted());
        }
        if (this.replyContainerProperties.getCacheLevel() != null) {
            container.setCacheLevel(this.replyContainerProperties.getCacheLevel());
        }
        if (this.replyContainerProperties.getConcurrentConsumers() != null) {
            container.setConcurrentConsumers(this.replyContainerProperties.getConcurrentConsumers());
        }
        if (this.replyContainerProperties.getIdleConsumerLimit() != null) {
            container.setIdleConsumerLimit(this.replyContainerProperties.getIdleConsumerLimit());
        }
        if (this.replyContainerProperties.getIdleTaskExecutionLimit() != null) {
            container.setIdleTaskExecutionLimit(this.replyContainerProperties.getIdleTaskExecutionLimit());
        }
        if (this.replyContainerProperties.getMaxConcurrentConsumers() != null) {
            container.setMaxConcurrentConsumers(this.replyContainerProperties.getMaxConcurrentConsumers());
        }
        if (this.replyContainerProperties.getMaxMessagesPerTask() != null) {
            container.setMaxMessagesPerTask(this.replyContainerProperties.getMaxMessagesPerTask());
        }
        if (this.replyContainerProperties.getReceiveTimeout() != null) {
            container.setReceiveTimeout(this.replyContainerProperties.getReceiveTimeout());
        }
        if (this.replyContainerProperties.getRecoveryInterval() != null) {
            container.setRecoveryInterval(this.replyContainerProperties.getRecoveryInterval());
        }
        if (StringUtils.hasText(this.replyContainerProperties.getSessionAcknowledgeModeName())) {
            Integer acknowledgeMode = JmsAdapterUtils
                    .parseAcknowledgeMode(this.replyContainerProperties.getSessionAcknowledgeModeName());
            if (acknowledgeMode != null) {
                if (JmsAdapterUtils.SESSION_TRANSACTED == acknowledgeMode) {
                    container.setSessionTransacted(true);
                } else {
                    container.setSessionAcknowledgeMode(acknowledgeMode);
                }
            }
        } else if (this.replyContainerProperties.getSessionAcknowledgeMode() != null) {
            Integer sessionAcknowledgeMode = this.replyContainerProperties.getSessionAcknowledgeMode();
            if (Session.SESSION_TRANSACTED == sessionAcknowledgeMode) {
                container.setSessionTransacted(true);
            } else {
                container.setSessionAcknowledgeMode(sessionAcknowledgeMode);
            }

        }

        if (this.replyContainerProperties.getTaskExecutor() != null) {
            container.setTaskExecutor(this.replyContainerProperties.getTaskExecutor());
        } else {
            // set the beanName so the default TE threads get a meaningful name
            String containerBeanName = this.getComponentName();
            containerBeanName = ((!StringUtils.hasText(containerBeanName)
                    ? "JMS_OutboundGateway@" + ObjectUtils.getIdentityHexString(this)
                    : containerBeanName) + ".replyListener");
            container.setBeanName(containerBeanName);
        }
    }
}

From source file:org.springframework.integration.jms.JmsOutboundGatewayTests.java

@Test
public void testContainerBeanNameWhenNoGatewayBeanName() {
    JmsOutboundGateway gateway = new JmsOutboundGateway();
    gateway.setConnectionFactory(mock(ConnectionFactory.class));
    gateway.setRequestDestinationName("foo");
    gateway.setUseReplyContainer(true);//from www.ja  v a  2  s.  co m
    gateway.setReplyContainerProperties(new ReplyContainerProperties());
    gateway.afterPropertiesSet();
    assertEquals("JMS_OutboundGateway@" + ObjectUtils.getIdentityHexString(gateway) + ".replyListener",
            TestUtils.getPropertyValue(gateway, "replyContainer.beanName"));
}

From source file:org.springframework.jmx.support.JmxUtils.java

/**
 * Append an additional key/value pair to an existing {@link ObjectName} with the key being
 * the static value {@code identity} and the value being the identity hash code of the
 * managed resource being exposed on the supplied {@link ObjectName}. This can be used to
 * provide a unique {@link ObjectName} for each distinct instance of a particular bean or
 * class. Useful when generating {@link ObjectName ObjectNames} at runtime for a set of
 * managed resources based on the template value supplied by a
 * {@link org.springframework.jmx.export.naming.ObjectNamingStrategy}.
 * @param objectName the original JMX ObjectName
 * @param managedResource the MBean instance
 * @return an ObjectName with the MBean identity added
 * @throws MalformedObjectNameException in case of an invalid object name specification
 * @see org.springframework.util.ObjectUtils#getIdentityHexString(Object)
 *//* w  w  w .jav  a 2s  . c  om*/
public static ObjectName appendIdentityToObjectName(ObjectName objectName, Object managedResource)
        throws MalformedObjectNameException {

    Hashtable<String, String> keyProperties = objectName.getKeyPropertyList();
    keyProperties.put(IDENTITY_OBJECT_NAME_KEY, ObjectUtils.getIdentityHexString(managedResource));
    return ObjectNameManager.getInstance(objectName.getDomain(), keyProperties);
}

From source file:org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler.java

public String getBeanName() {
    return this.beanName != null ? this.beanName
            : getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this);
}

From source file:org.springframework.messaging.support.AbstractMessageChannel.java

public AbstractMessageChannel() {
    this.beanName = getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this);
}

From source file:org.springframework.messaging.support.channel.AbstractSubscribableChannel.java

public AbstractSubscribableChannel() {
    this.beanName = getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this);
}

From source file:org.springframework.osgi.extender.internal.support.ExtenderConfiguration.java

private TaskExecutor createDefaultTaskExecutor() {
    // create thread-pool for starting contexts
    ThreadGroup threadGroup = new ThreadGroup(
            "spring-osgi-extender[" + ObjectUtils.getIdentityHexString(this) + "]-threads");
    threadGroup.setDaemon(false);/* w  w w .  java 2  s.c  o m*/

    SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    taskExecutor.setThreadGroup(threadGroup);
    taskExecutor.setThreadNamePrefix("SpringOsgiExtenderThread-");

    isTaskExecutorManagedInternally = true;

    return taskExecutor;
}

From source file:org.springframework.osgi.web.deployer.support.DefaultContextPathStrategy.java

/**
 * Determines the context path associated with this bundle. This method can be overridden by possible subclasses
 * that wish to decorate or modify the existing behaviour.
 * /*  ww w  . ja  va2 s  . c o  m*/
 * @param bundle bundle for which the context path needs to be determined
 * @return non-null context path determined for the given bundle
 */
protected String determineContextPath(Bundle bundle) {
    boolean trace = log.isTraceEnabled();

    // first get the header
    String path = getBundleHeader(bundle);

    if (path == null) {
        if (trace)
            log.trace("No " + CONTEXT_PATH_HEADER + " found; falling back to bundle location...");
        String location = bundle.getLocation();
        if (StringUtils.hasText(location)) {
            path = getBundleLocation(location);
        }
        // the location is not good, use a fall back
        else {
            if (trace)
                log.trace("No bundle location found; falling back to bundle name...");

            // fall-back to bundle name
            Dictionary headers = bundle.getHeaders();
            path = (headers != null ? (String) headers.get(Constants.BUNDLE_NAME) : null);

            if (!StringUtils.hasText(path)) {
                if (trace)
                    log.trace("No bundle name found; falling back to bundle symbolic name...");

                // fall back to bundle sym name
                path = bundle.getSymbolicName();

                // fall back to object identity
                if (!StringUtils.hasText(path)) {
                    path = ClassUtils.getShortName(bundle.getClass()) + "-"
                            + ObjectUtils.getIdentityHexString(bundle);
                    if (trace)
                        log.trace("No bundle symbolic found; returning bundle identity [" + path
                                + "] as context path");
                } else {
                    if (trace)
                        log.trace("Returning bundle symbolic name [" + path + "] as context path");
                }
            } else {
                if (trace)
                    log.trace("Returning bundle name [" + path + "] as context path");
            }
        }
    } else {
        if (trace)
            log.trace("Using the bundle " + CONTEXT_PATH_HEADER + " header as context path [" + path + "]");
    }

    return path;
}

From source file:org.springframework.retry.interceptor.StatefulRetryOperationsInterceptor.java

/**
 * Wrap the method invocation in a stateful retry with the policy and other helpers
 * provided. If there is a failure the exception will generally be re-thrown. The only
 * time it is not re-thrown is when retry is exhausted and the recovery path is taken
 * (though the {@link MethodInvocationRecoverer} provided if there is one). In that
 * case the value returned from the method invocation will be the value returned by
 * the recoverer (so the return type for that should be the same as the intercepted
 * method).//w w  w  .  j  ava2s .  com
 * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
 * @see MethodInvocationRecoverer#recover(Object[], Throwable)
 *
 */
public Object invoke(final MethodInvocation invocation) throws Throwable {

    if (logger.isDebugEnabled()) {
        logger.debug("Executing proxied method in stateful retry: " + invocation.getStaticPart() + "("
                + ObjectUtils.getIdentityHexString(invocation) + ")");
    }

    Object[] args = invocation.getArguments();
    Assert.state(args.length > 0,
            "Stateful retry applied to method that takes no arguments: " + invocation.getStaticPart());
    Object arg = args;
    if (args.length == 1) {
        arg = args[0];
    }
    final Object item = arg;

    RetryState retryState = new DefaultRetryState(keyGenerator != null ? keyGenerator.getKey(args) : item,
            newMethodArgumentsIdentifier != null && newMethodArgumentsIdentifier.isNew(args));

    Object result = retryOperations.execute(new MethodInvocationRetryCallback(invocation),
            recoverer != null ? new ItemRecovererCallback(args, recoverer) : null, retryState);

    if (logger.isDebugEnabled()) {
        logger.debug("Exiting proxied method in stateful retry with result: (" + result + ")");
    }

    return result;

}