class SingleThreadAsyncCallback<T> extends AsyncCallback<T> {

    private AsyncHandler<AsyncResult<T>> completeHandler;
    private AsyncHandler<T> successHandler;
    private AsyncHandler<Throwable> failureHandler;
    private AsyncResult<T> asyncResult;

    public SingleThreadAsyncCallback() {
    }

    @Override
    public void setDbException(DbException e, boolean cancel) {
        setAsyncResult(e);
    }

    @Override
    public void run(NetInputStream in) {
        try {
            runInternal(in);
        } catch (Throwable t) {
            setAsyncResult(t);
        }
    }

    @Override
    protected T await(long timeoutMillis) {<FILL_FUNCTION_BODY>}

    @Override
    public Future<T> onSuccess(AsyncHandler<T> handler) {
        successHandler = handler;
        if (asyncResult != null && asyncResult.isSucceeded()) {
            handler.handle(asyncResult.getResult());
        }
        return this;
    }

    @Override
    public Future<T> onFailure(AsyncHandler<Throwable> handler) {
        failureHandler = handler;
        if (asyncResult != null && asyncResult.isFailed()) {
            handler.handle(asyncResult.getCause());
        }
        return this;
    }

    @Override
    public Future<T> onComplete(AsyncHandler<AsyncResult<T>> handler) {
        completeHandler = handler;
        if (asyncResult != null) {
            handler.handle(asyncResult);
        }
        return this;
    }

    @Override
    public void setAsyncResult(AsyncResult<T> asyncResult) {
        this.asyncResult = asyncResult;
        if (completeHandler != null)
            completeHandler.handle(asyncResult);

        if (successHandler != null && asyncResult != null && asyncResult.isSucceeded())
            successHandler.handle(asyncResult.getResult());

        if (failureHandler != null && asyncResult != null && asyncResult.isFailed())
            failureHandler.handle(asyncResult.getCause());
    }
}

        Scheduler scheduler = SchedulerThread.currentScheduler();
        if (scheduler != null) {
            scheduler.executeNextStatement();
            // 如果被锁住了，需要重试
            if (asyncResult == null) {
                while (asyncResult == null) {
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                    }
                    scheduler.executeNextStatement();
                }
            }

            if (asyncResult.isSucceeded())
                return asyncResult.getResult();
            else
                throw DbException.convert(asyncResult.getCause());
        } else {
            throw DbException.getInternalError();
        }
    
<methods>public void <init>() ,public void checkTimeout(long) ,public static AsyncCallback<T> create(boolean) ,public static AsyncCallback<T> createConcurrentCallback() ,public static AsyncCallback<T> createSingleThreadCallback() ,public T get() ,public T get(long) ,public int getNetworkTimeout() ,public long getStartTime() ,public Future<T> onComplete(AsyncHandler<AsyncResult<T>>) ,public Future<T> onFailure(AsyncHandler<java.lang.Throwable>) ,public Future<T> onSuccess(AsyncHandler<T>) ,public void run(com.lealone.net.NetInputStream) ,public void setAsyncResult(java.lang.Throwable) ,public void setAsyncResult(T) ,public void setAsyncResult(AsyncResult<T>) ,public void setDbException(com.lealone.common.exceptions.DbException, boolean) ,public void setNetworkTimeout(int) ,public void setPacket(com.lealone.server.protocol.Packet) ,public void setStartTime(long) <variables>private int networkTimeout,private com.lealone.server.protocol.Packet packet,private long startTime