package org.kne.cloud.network; import java.io.IOException; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.kne.cloud.network.klalb.KLALBPacket; import org.kne.debug.TimeDebugger; public abstract class NetworkPacket implements Comparable{ private static final boolean debugPassport=false; public static final ByteBufferAllocator bufferAllocator=new ByteBufferAllocator(true); //public static final ByteArrayPool dataarraypool_65535=new ByteArrayPool(10000, 65535); //public static final ByteBufferPool databufferpool_65535=new ByteBufferPool(10000, 65535,false); //public static final ByteBufferPool databufferpool_2048=new ByteBufferPool(10000, 2048,false); //public static final ByteBufferPool databufferpool_40=new ByteBufferPool(10000, 40,false); private final TimeDebugger passport; { if(debugPassport) { passport=new TimeDebugger(); passport.putTime(getClass().getSimpleName()+ "_create"); }else { passport=null; } } public final void putTimePassport(String label) { if(passport!=null) { passport.putTime(label); } } public final void printPassport() { if(passport!=null) { passport.printWithTimeFilter(100000000L); } } public abstract long getTotalLength(); public long getPriority() { return priority; } public void setPriority(long priority) { this.priority = priority; } public long getSendseq() { return sendseq; } private long priority; private long sendseq; private static final AtomicLong seqgen=new AtomicLong(); @Override public int compareTo(NetworkPacket o) { if(priority>o.priority) { return 1; }else if(priorityo.sendseq) { return 1; }else if(sendseq