package org.couchbase.mock.memcached;
import org.couchbase.mock.memcached.protocol.BinaryResponse;
import org.couchbase.mock.memcached.protocol.BinaryCommand;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.util.LinkedList;
import java.util.Queue;
import org.couchbase.mock.memcached.protocol.CommandFactory;
private BinaryProtocolHandler protocolHandler;
private final byte header[];
private BinaryCommand command;
private final ByteBuffer input;
private final Queue<ByteBuffer> output;
private boolean authenticated;
private boolean closed;
closed = false;
if (server.getBucket().getPassword().length() > 0) {
authenticated = false;
} else {
authenticated = true;
}
header = new byte[24];
input = ByteBuffer.wrap(header);
protocolHandler = server.getProtocolHandler();
output = new LinkedList<ByteBuffer>();
}
public void step()
throws IOException {
if (closed) {
throw new ClosedChannelException();
}
if (input.position() == header.length) {
if (command == null) {
command = CommandFactory.create(input);
}
if (command.complete()) {
protocolHandler.execute(command, this);
command = null;
input.rewind();
}
}
}
output.add(response.getBuffer());
}
return !output.isEmpty();
}
if (command == null) {
return input;
} else {
return command.getInputBuffer();
}
}
if (output.isEmpty()) {
return null;
} else {
return output.remove();
}
}
closed = true;
}
return closed;
}
authenticated = state;
}
return authenticated;
}
}