All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rpc.turbo.protocol.recycle.RecycleRequest Maven / Gradle / Ivy

The newest version!
package rpc.turbo.protocol.recycle;

import io.netty.util.Recycler;
import io.netty.util.Recycler.Handle;
import rpc.turbo.param.MethodParam;
import rpc.turbo.protocol.Request;
import rpc.turbo.recycle.Recycleable;
import rpc.turbo.trace.Tracer;

public class RecycleRequest extends Request implements Recycleable {

	private static final long serialVersionUID = -3074626856820884094L;

	private static final Recycler RECYCLER = new Recycler() {
		protected RecycleRequest newObject(Recycler.Handle handle) {
			return new RecycleRequest(handle);
		}
	};

	public static RecycleRequest newInstance() {
		return RECYCLER.get();
	}

	public static RecycleRequest newInstance(int requestId, int serviceId, Tracer tracer, MethodParam methodParam) {
		RecycleRequest recycleRequest = RECYCLER.get();

		recycleRequest.setRequestId(requestId);
		recycleRequest.setServiceId(serviceId);
		recycleRequest.setTracer(tracer);
		recycleRequest.setMethodParam(methodParam);

		return recycleRequest;
	}

	private final transient Recycler.Handle handle;

	private RecycleRequest(Handle handle) {
		this.handle = handle;
	}

	@Override
	public void recycle() {
		setMethodParam(null);// 加快垃圾回收
		setTracer(null);// 加快垃圾回收

		handle.recycle(this);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy