Example usage for io.netty.buffer ByteBuf hashCode

List of usage examples for io.netty.buffer ByteBuf hashCode

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf hashCode.

Prototype

@Override
public abstract int hashCode();

Source Link

Document

Returns a hash code which was calculated from the content of this buffer.

Usage

From source file:com.github.milenkovicm.kafka.DefaultPartitioner.java

License:Apache License

@Override
public int partition(ByteBuf key, int numberOfPartitions) {
    return key == null ? 0 : Math.abs(key.hashCode() % numberOfPartitions);
}

From source file:org.ebayopensource.scc.cache.RequestKeyGenerator.java

License:Apache License

private String getRequestHash(FullHttpRequest request) {
    HttpHeaders headers = request.headers();
    String requestURI = getRequestURI(request);
    HttpMethod requestMethod = request.getMethod();
    Set<String> skipHeaders = m_skipHeaders;
    boolean skipRequestContent = m_uriMatchEnabled && WildcardMatcher.isPatternCanBeMatchedIn(m_uriMatchOnly,
            new CacheDecisionObject(requestURI, requestMethod.name()));
    if (skipRequestContent) {
        skipHeaders = new HashSet<>(m_skipHeaders);
        skipHeaders.add(HttpHeaders.Names.CONTENT_LENGTH.toUpperCase());
    }//from  w  w  w  . j  a v a 2  s .  com

    int uriHashcode = requestURI.hashCode();
    int methodHashCode = requestMethod.hashCode();
    List<Entry<String, String>> entries = headers.entries();
    List<String> hashList = new ArrayList<>();
    for (Iterator<Entry<String, String>> it = entries.iterator(); it.hasNext();) {
        Entry<String, String> entry = it.next();
        if (skipHeaders.contains(entry.getKey().toUpperCase())) {
            continue;
        }
        hashList.add(entry.getKey());
        hashList.add(entry.getValue());
    }

    int headersHashcode = hashList.hashCode();

    StringBuilder sb = new StringBuilder(4);
    sb.append(uriHashcode).append(methodHashCode).append(headersHashcode);

    if (!skipRequestContent) {
        ByteBuf content = request.content();
        sb.append(content.hashCode());
    }

    return Checksum.checksum(sb.toString());
}