Example usage for java.lang System identityHashCode

List of usage examples for java.lang System identityHashCode

Introduction

In this page you can find the example usage for java.lang System identityHashCode.

Prototype

@HotSpotIntrinsicCandidate
public static native int identityHashCode(Object x);

Source Link

Document

Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode().

Usage

From source file:org.regenstrief.util.Util.java

/**
 * Retrieves the same String for the given Object as would be returned by the default method
 * toString(), whether or not the given Object's class overrides toString(), the toString
 * equivalent of System.identityHashCode
 * //from   w ww .jav a 2  s . com
 * @param o the Object
 * @return the String
 **/
public final static String identityToString(final Object o) {
    return o == null ? null : o.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(o));
}

From source file:org.apache.jmeter.protocol.http.sampler.HTTPHC3Impl.java

/**
 * Returns an <code>HttpConnection</code> fully ready to attempt
 * connection. This means it sets the request method (GET or POST), headers,
 * cookies, and authorization for the URL request.
 * <p>/*from   w w  w.ja  v  a2 s.c o  m*/
 * The request infos are saved into the sample result if one is provided.
 *
 * @param u
 *            <code>URL</code> of the URL request
 * @param httpMethod
 *            GET/PUT/HEAD etc
 * @param res
 *            sample result to save request infos to
 * @return <code>HttpConnection</code> ready for .connect
 * @exception IOException
 *                if an I/O Exception occurs
 */
protected HttpClient setupConnection(URL u, HttpMethodBase httpMethod, HTTPSampleResult res)
        throws IOException {

    String urlStr = u.toString();

    org.apache.commons.httpclient.URI uri = new org.apache.commons.httpclient.URI(urlStr, false);

    String schema = uri.getScheme();
    if ((schema == null) || (schema.length() == 0)) {
        schema = HTTPConstants.PROTOCOL_HTTP;
    }

    final boolean isHTTPS = HTTPConstants.PROTOCOL_HTTPS.equalsIgnoreCase(schema);
    if (isHTTPS) {
        SSLManager.getInstance(); // ensure the manager is initialised
        // we don't currently need to do anything further, as this sets the default https protocol
    }

    Protocol protocol = Protocol.getProtocol(schema);

    String host = uri.getHost();
    int port = uri.getPort();

    /*
     *  We use the HostConfiguration as the key to retrieve the HttpClient,
     *  so need to ensure that any items used in its equals/hashcode methods are
     *  not changed after use, i.e.:
     *  host, port, protocol, localAddress, proxy
     *
    */
    HostConfiguration hc = new HostConfiguration();
    hc.setHost(host, port, protocol); // All needed to ensure re-usablility

    // Set up the local address if one exists
    final InetAddress inetAddr = getIpSourceAddress();
    if (inetAddr != null) {// Use special field ip source address (for pseudo 'ip spoofing')
        hc.setLocalAddress(inetAddr);
    } else {
        hc.setLocalAddress(localAddress); // null means use the default
    }

    final String proxyHost = getProxyHost();
    final int proxyPort = getProxyPortInt();

    boolean useStaticProxy = isStaticProxy(host);
    boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort);

    if (useDynamicProxy) {
        hc.setProxy(proxyHost, proxyPort);
        useStaticProxy = false; // Dynamic proxy overrules static proxy
    } else if (useStaticProxy) {
        if (log.isDebugEnabled()) {
            log.debug("Setting proxy: " + PROXY_HOST + ":" + PROXY_PORT);
        }
        hc.setProxy(PROXY_HOST, PROXY_PORT);
    }

    Map<HostConfiguration, HttpClient> map = httpClients.get();
    // N.B. HostConfiguration.equals() includes proxy settings in the compare.
    HttpClient httpClient = map.get(hc);

    if (httpClient != null && resetSSLContext && isHTTPS) {
        httpClient.getHttpConnectionManager().closeIdleConnections(-1000);
        httpClient = null;
        JsseSSLManager sslMgr = (JsseSSLManager) SSLManager.getInstance();
        sslMgr.resetContext();
        resetSSLContext = false;
    }

    if (httpClient == null) {
        httpClient = new HttpClient(new SimpleHttpConnectionManager());
        httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                new DefaultHttpMethodRetryHandler(RETRY_COUNT, false));
        if (log.isDebugEnabled()) {
            log.debug("Created new HttpClient: @" + System.identityHashCode(httpClient));
        }
        httpClient.setHostConfiguration(hc);
        map.put(hc, httpClient);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Reusing the HttpClient: @" + System.identityHashCode(httpClient));
        }
    }

    // Set up any required Proxy credentials
    if (useDynamicProxy) {
        String user = getProxyUser();
        if (user.length() > 0) {
            httpClient.getState().setProxyCredentials(
                    new AuthScope(proxyHost, proxyPort, null, AuthScope.ANY_SCHEME),
                    new NTCredentials(user, getProxyPass(), localHost, PROXY_DOMAIN));
        } else {
            httpClient.getState().clearProxyCredentials();
        }
    } else {
        if (useStaticProxy) {
            if (PROXY_USER.length() > 0) {
                httpClient.getState().setProxyCredentials(
                        new AuthScope(PROXY_HOST, PROXY_PORT, null, AuthScope.ANY_SCHEME),
                        new NTCredentials(PROXY_USER, PROXY_PASS, localHost, PROXY_DOMAIN));
            }
        } else {
            httpClient.getState().clearProxyCredentials();
        }
    }

    int rto = getResponseTimeout();
    if (rto > 0) {
        httpMethod.getParams().setSoTimeout(rto);
    }

    int cto = getConnectTimeout();
    if (cto > 0) {
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(cto);
    }

    // Allow HttpClient to handle the redirects:
    httpMethod.setFollowRedirects(getAutoRedirects());

    // a well-behaved browser is supposed to send 'Connection: close'
    // with the last request to an HTTP server. Instead, most browsers
    // leave it to the server to close the connection after their
    // timeout period. Leave it to the JMeter user to decide.
    if (getUseKeepAlive()) {
        httpMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION, HTTPConstants.KEEP_ALIVE);
    } else {
        httpMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION, HTTPConstants.CONNECTION_CLOSE);
    }

    setConnectionHeaders(httpMethod, u, getHeaderManager(), getCacheManager());
    String cookies = setConnectionCookie(httpMethod, u, getCookieManager());

    setConnectionAuthorization(httpClient, u, getAuthManager());

    if (res != null) {
        res.setCookies(cookies);
    }

    return httpClient;
}

From source file:com.cloud.utils.db.TransactionLegacy.java

/**
 * Returns the db connection./*w ww. j  av  a 2 s.  c  om*/
 *
 * Note: that you can call getConnection() but beaware that
 * all prepare statements from the Connection are not garbage
 * collected!
 *
 * @return DB Connection but make sure you understand that
 *         you are responsible for closing the PreparedStatement.
 * @throws SQLException
 */
public Connection getConnection() throws SQLException {
    if (_conn == null) {
        switch (_dbId) {
        case CLOUD_DB:
            if (s_ds != null) {
                _conn = s_ds.getConnection();
            } else {
                s_logger.warn("A static-initialized variable becomes null, process is dying?");
                throw new CloudRuntimeException("Database is not initialized, process is dying?");
            }
            break;
        case USAGE_DB:
            if (s_usageDS != null) {
                _conn = s_usageDS.getConnection();
            } else {
                s_logger.warn("A static-initialized variable becomes null, process is dying?");
                throw new CloudRuntimeException("Database is not initialized, process is dying?");
            }
            break;
        case SIMULATOR_DB:
            if (s_simulatorDS != null) {
                _conn = s_simulatorDS.getConnection();
            } else {
                s_logger.warn("A static-initialized variable becomes null, process is dying?");
                throw new CloudRuntimeException("Database is not initialized, process is dying?");
            }
            break;
        default:

            throw new CloudRuntimeException("No database selected for the transaction");
        }
        _conn.setAutoCommit(!_txn);

        //
        // MySQL default transaction isolation level is REPEATABLE READ,
        // to reduce chances of DB deadlock, we will use READ COMMITED isolation level instead
        // see http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html
        //
        _stack.push(new StackElement(CREATE_CONN, null));
        if (s_connLogger.isTraceEnabled()) {
            s_connLogger.trace("Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + " for "
                    + _dbId + ": dbconn" + System.identityHashCode(_conn) + ". Stack: " + buildName());
        }
    } else {
        s_logger.trace("conn: Using existing DB connection");
    }

    return _conn;
}

From source file:nz.co.senanque.rules.RuleSessionImpl.java

public boolean isUnbinding(ValidationObject validationObject) {
    return (m_unbinding.contains(System.identityHashCode(validationObject)));
}

From source file:org.rhq.plugins.jbossas5.ManagedComponentComponent.java

private static String toString(ManagedComponent managedComponent) {
    Map<String, ManagedProperty> properties = managedComponent.getProperties();
    return managedComponent.getClass().getSimpleName() + "@" + System.identityHashCode(managedComponent) + "["
            + "type=" + managedComponent.getType() + ", name=" + managedComponent.getName() + ", properties="
            + properties.getClass().getSimpleName() + "@" + System.identityHashCode(properties) + "]";
}

From source file:org.pentaho.reporting.engine.classic.core.function.AbstractElementFormatFunction.java

private String computeUniqueIdentifier() {
    return "need-eval-result:" + getClass().getName() + '@' + System.identityHashCode(this);
}

From source file:com.cloud.utils.db.Transaction.java

/**
 * Returns the db connection.// ww  w.j  a v a2  s. c  om
 * 
 * Note: that you can call getConnection() but beaware that
 * all prepare statements from the Connection are not garbage
 * collected!
 * 
 * @return DB Connection but make sure you understand that
 *         you are responsible for closing the PreparedStatement.
 * @throws SQLException
 */
public Connection getConnection() throws SQLException {
    if (_conn == null) {
        switch (_dbId) {
        case CLOUD_DB:
            if (s_ds != null) {
                _conn = s_ds.getConnection();
            } else {
                s_logger.warn("A static-initialized variable becomes null, process is dying?");
                throw new CloudRuntimeException("Database is not initialized, process is dying?");
            }
            break;
        case USAGE_DB:
            if (s_usageDS != null) {
                _conn = s_usageDS.getConnection();
            } else {
                s_logger.warn("A static-initialized variable becomes null, process is dying?");
                throw new CloudRuntimeException("Database is not initialized, process is dying?");
            }
            break;
        case AWSAPI_DB:
            if (s_awsapiDS != null) {
                _conn = s_awsapiDS.getConnection();
            } else {
                s_logger.warn("A static-initialized variable becomes null, process is dying?");
                throw new CloudRuntimeException("Database is not initialized, process is dying?");
            }
            break;

        case SIMULATOR_DB:
            if (s_simulatorDS != null) {
                _conn = s_simulatorDS.getConnection();
            } else {
                s_logger.warn("A static-initialized variable becomes null, process is dying?");
                throw new CloudRuntimeException("Database is not initialized, process is dying?");
            }
            break;
        default:

            throw new CloudRuntimeException("No database selected for the transaction");
        }
        _conn.setAutoCommit(!_txn);

        //
        // MySQL default transaction isolation level is REPEATABLE READ,
        // to reduce chances of DB deadlock, we will use READ COMMITED isolation level instead
        // see http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html
        //
        _stack.push(new StackElement(CREATE_CONN, null));
        if (s_connLogger.isTraceEnabled()) {
            s_connLogger.trace("Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + " for "
                    + _dbId + ": dbconn" + System.identityHashCode(_conn) + ". Stack: " + buildName());
        }
    } else {
        s_logger.trace("conn: Using existing DB connection");
    }

    return _conn;
}

From source file:org.gluu.oxtrust.action.ManageCertificateAction.java

public void removePublicCertificate(TrustStoreCertificate removeTrustStoreCertificate) {
    for (Iterator<TrustStoreCertificate> iterator = this.trustStoreCertificates.iterator(); iterator
            .hasNext();) {/*from  w w  w.  jav  a2  s . com*/
        TrustStoreCertificate trustStoreCertificate = iterator.next();
        if (System.identityHashCode(removeTrustStoreCertificate) == System
                .identityHashCode(trustStoreCertificate)) {
            iterator.remove();
            return;
        }
    }
}

From source file:org.apache.htrace.core.Tracer.java

/**
 * Get the hash code of a Tracer object.
 *
 * This hash code is based on object identity.
 * This is used in TracerPool to create a hash table of Tracers.
 *//*from w  ww .  j  a  v a  2 s  .c om*/
@Override
public int hashCode() {
    return System.identityHashCode(this);
}

From source file:org.apache.calcite.avatica.jdbc.JdbcMeta.java

public StatementHandle createStatement(ConnectionHandle ch) {
    try {//w  ww.  java  2s.  c om
        final Connection conn = getConnection(ch.id);
        final Statement statement = conn.createStatement();
        final int id = System.identityHashCode(statement);
        statementCache.put(id, new StatementInfo(statement));
        StatementHandle h = new StatementHandle(ch.id, id, null);
        if (LOG.isTraceEnabled()) {
            LOG.trace("created statement " + h);
        }
        return h;
    } catch (SQLException e) {
        throw propagate(e);
    }
}