public Map<CharSequence, Set<Cookie>> getCachedCookies() {
		if (!STATE.compareAndSet(this, NOT_READ, READING)) {
			for (; ; ) {
				if (state == READ) {
					return cachedCookies;
				}
			}
		}

		List<String> allCookieHeaders = nettyHeaders.getAll(cookiesHeaderName);
		Map<String, Set<Cookie>> cookies = new HashMap<>();
		for (String aCookieHeader : allCookieHeaders) {
			Set<Cookie> decode;
			if (isClientChannel) {
				final Cookie c = ((ClientCookieDecoder) decoder).decode(aCookieHeader);
				Set<Cookie> existingCookiesOfName = cookies.get(c.name());
				if (null == existingCookiesOfName) {
					existingCookiesOfName = new HashSet<>();
					cookies.put(c.name(), existingCookiesOfName);
				}
				existingCookiesOfName.add(c);
			}
			else {
				decode = ((ServerCookieDecoder) decoder).decode(aCookieHeader);
				for (Cookie cookie : decode) {
					Set<Cookie> existingCookiesOfName = cookies.get(cookie.name());
					if (null == existingCookiesOfName) {
						existingCookiesOfName = new HashSet<>();
						cookies.put(cookie.name(), existingCookiesOfName);
					}
					existingCookiesOfName.add(cookie);
				}
			}
		}
		cachedCookies = Collections.unmodifiableMap(cookies);
		state = READ;
		return cachedCookies;
	}
public Map < CharSequence , Set < Cookie > > getCachedCookies ( ) { if ( ! STATE . compareAndSet ( this , NOT_READ , READING ) ) { for ( ; ; ) { if ( state == READ ) { return cachedCookies ; } } } List < String > allCookieHeaders = nettyHeaders . getAll ( cookiesHeaderName ) ; Map < String , Set < Cookie > > cookies = new HashMap < > ( ) ; for ( String aCookieHeader : allCookieHeaders ) { Set < Cookie > decode ; if ( isClientChannel ) { final Cookie c = ( ( ClientCookieDecoder ) decoder ) . decode ( aCookieHeader ) ; Set < Cookie > existingCookiesOfName = cookies . get ( c . name ( ) ) ; if ( null == existingCookiesOfName ) { existingCookiesOfName = new HashSet < > ( ) ; cookies . put ( c . name ( ) , existingCookiesOfName ) ; } existingCookiesOfName . add ( c ) ; } else { decode = ( ( ServerCookieDecoder ) decoder ) . decode ( aCookieHeader ) ; for ( Cookie cookie : decode ) { Set < Cookie > existingCookiesOfName = cookies . get ( cookie . name ( ) ) ; if ( null == existingCookiesOfName ) { existingCookiesOfName = new HashSet < > ( ) ; cookies . put ( cookie . name ( ) , existingCookiesOfName ) ; } existingCookiesOfName . add ( cookie ) ; } } } cachedCookies = Collections . unmodifiableMap ( cookies ) ; state = READ ; return cachedCookies ; }
Wait for the cookies to become available, cache them and subsequently return the
cached map of cookies.