Motivation: HTTP is a plaintext protocol which means that someone may be able to eavesdrop the data. To prevent this, HTTPS should be used whenever possible. However, maintaining using https:// in all URLs may be difficult. The nohttp tool can help here. The tool scans all the files in a repository and reports where http:// is used. Modifications: - Added nohttp (via checkstyle) into the build process. - Suppressed findings for the websites that don't support HTTPS or that are not reachable Result: - Prevent using HTTP in the future. - Encourage users to use HTTPS when they follow the links they found in the code.
96 lines
2.9 KiB
Java
96 lines
2.9 KiB
Java
/*
|
|
* Copyright 2013 The Netty Project
|
|
*
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
* with the License. You may obtain a copy of the License at:
|
|
*
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
* License for the specific language governing permissions and limitations
|
|
* under the License.
|
|
*/
|
|
package io.netty.util;
|
|
|
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
|
|
|
import io.netty.util.internal.ReferenceCountUpdater;
|
|
|
|
/**
|
|
* Abstract base class for classes wants to implement {@link ReferenceCounted}.
|
|
*/
|
|
public abstract class AbstractReferenceCounted implements ReferenceCounted {
|
|
private static final long REFCNT_FIELD_OFFSET =
|
|
ReferenceCountUpdater.getUnsafeOffset(AbstractReferenceCounted.class, "refCnt");
|
|
private static final AtomicIntegerFieldUpdater<AbstractReferenceCounted> AIF_UPDATER =
|
|
AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCounted.class, "refCnt");
|
|
|
|
private static final ReferenceCountUpdater<AbstractReferenceCounted> updater =
|
|
new ReferenceCountUpdater<AbstractReferenceCounted>() {
|
|
@Override
|
|
protected AtomicIntegerFieldUpdater<AbstractReferenceCounted> updater() {
|
|
return AIF_UPDATER;
|
|
}
|
|
@Override
|
|
protected long unsafeOffset() {
|
|
return REFCNT_FIELD_OFFSET;
|
|
}
|
|
};
|
|
|
|
// Value might not equal "real" reference count, all access should be via the updater
|
|
@SuppressWarnings("unused")
|
|
private volatile int refCnt = updater.initialValue();
|
|
|
|
@Override
|
|
public int refCnt() {
|
|
return updater.refCnt(this);
|
|
}
|
|
|
|
/**
|
|
* An unsafe operation intended for use by a subclass that sets the reference count of the buffer directly
|
|
*/
|
|
protected final void setRefCnt(int refCnt) {
|
|
updater.setRefCnt(this, refCnt);
|
|
}
|
|
|
|
@Override
|
|
public ReferenceCounted retain() {
|
|
return updater.retain(this);
|
|
}
|
|
|
|
@Override
|
|
public ReferenceCounted retain(int increment) {
|
|
return updater.retain(this, increment);
|
|
}
|
|
|
|
@Override
|
|
public ReferenceCounted touch() {
|
|
return touch(null);
|
|
}
|
|
|
|
@Override
|
|
public boolean release() {
|
|
return handleRelease(updater.release(this));
|
|
}
|
|
|
|
@Override
|
|
public boolean release(int decrement) {
|
|
return handleRelease(updater.release(this, decrement));
|
|
}
|
|
|
|
private boolean handleRelease(boolean result) {
|
|
if (result) {
|
|
deallocate();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Called once {@link #refCnt()} is equals 0.
|
|
*/
|
|
protected abstract void deallocate();
|
|
}
|