@Override public void close() { resultSet.close(); } }
@Override public Object next() { Object obj = resultSet.row; more = resultSet.next(); return obj; }
public KeyRecordIterator(String namespace, ResultSet resultSet) { this(namespace); this.resultSet = resultSet; this.resultSetIterator = resultSet.iterator(); }
@Override public void write(LuaValue source) { Object target = LuaUtil.luaToObject(source); if (target != null) { resultSet.put(target); } }
@Override protected void sendCancel() { // Clear lua input queue to ensure cancel is accepted. inputQueue.clear(); resultSet.abort(); // Send end command to lua input queue. // It's critical that the end offer succeeds. while (! inputQueue.offer(LuaValue.NIL)) { // Queue must be full. Remove one item to make room. if (inputQueue.poll() == null) { // Can't offer or poll. Nothing further can be done. if (Log.debugEnabled()) { Log.debug("Lua input queue " + statement.taskId + " both offer and poll failed on abort"); } break; } } }
public QueryAggregateExecutor(Cluster cluster, QueryPolicy policy, Statement statement, Node node) throws AerospikeException { super(cluster, policy, statement, node); inputQueue = new ArrayBlockingQueue<LuaValue>(500); resultSet = new ResultSet(this, policy.recordQueueSize); // Work around luaj LuaInteger static initialization bug. // Calling LuaInteger.valueOf(long) is required because LuaValue.valueOf() does not have // a method that takes in a long parameter. The problem is directly calling // LuaInteger.valueOf(long) results in a static initialization error. // // If LuaValue.valueOf() is called before any luaj calls, then the static initializer in // LuaInteger will be initialized properly. LuaValue.valueOf(0); // Retrieve lua instance from cache. lua = LuaCache.getInstance(); try { // Initialize threads, but do not run yet. initializeThreads(); // Start Lua thread which reads from a queue, applies aggregate function and // writes to a result set. threadPool.execute(this); } catch (RuntimeException re) { // Put the lua instance back if thread creation fails. LuaCache.putInstance(lua); throw re; } }
@Override public void write(LuaValue source) { Object target = LuaUtil.luaToObject(source); if (target != null) { resultSet.put(target); } }
@Override protected void sendCancel() { // Clear lua input queue to ensure cancel is accepted. inputQueue.clear(); resultSet.abort(); // Send end command to lua input queue. // It's critical that the end offer succeeds. while (! inputQueue.offer(LuaValue.NIL)) { // Queue must be full. Remove one item to make room. if (inputQueue.poll() == null) { // Can't offer or poll. Nothing further can be done. if (Log.debugEnabled()) { Log.debug("Lua input queue " + statement.taskId + " both offer and poll failed on abort"); } break; } } }
public QueryAggregateExecutor(Cluster cluster, QueryPolicy policy, Statement statement, Node node) throws AerospikeException { super(cluster, policy, statement, node); inputQueue = new ArrayBlockingQueue<LuaValue>(500); resultSet = new ResultSet(this, policy.recordQueueSize);
@Override public void close() { resultSet.close(); } }
@Override public Object next() { Object obj = resultSet.row; more = resultSet.next(); return obj; }
public void runThreads() throws AerospikeException { try { // Start thread queries to each node. startThreads(); lua.loadPackage(statement); LuaValue[] args = new LuaValue[4 + statement.getFunctionArgs().length]; args[0] = lua.getFunction(statement.getFunctionName()); args[1] = LuaInteger.valueOf(2); args[2] = new LuaInputStream(inputQueue); args[3] = new LuaOutputStream(resultSet); int count = 4; for (Value value : statement.getFunctionArgs()) { args[count++] = value.getLuaValue(lua); } lua.call("apply_stream", args); } finally { // Send end command to user's result set. // If query was already cancelled, this put will be ignored. resultSet.put(ResultSet.END); } }
/** * Put object on the queue. */ public final boolean put(Object object) { if (! valid) { return false; } try { // This put will block if queue capacity is reached. queue.put(object); return true; } catch (InterruptedException ie) { if (Log.debugEnabled()) { Log.debug("ResultSet " + executor.statement.taskId + " put interrupted"); } // Valid may have changed. Check again. if (valid) { abort(); } return false; } }
@Override public void close() throws IOException { synchronized (closeLock) { if (recordSet != null) recordSet.close(); if (resultSet != null) resultSet.close(); if (singleRecord != null) singleRecord = null; } }
ResultSetIterator(ResultSet resultSet) { this.resultSet = resultSet; more = this.resultSet.next(); }
public void runThreads() throws AerospikeException { try { // Start thread queries to each node. startThreads(); lua.loadPackage(statement); LuaValue[] args = new LuaValue[4 + statement.getFunctionArgs().length]; args[0] = lua.getFunction(statement.getFunctionName()); args[1] = LuaInteger.valueOf(2); args[2] = new LuaInputStream(inputQueue); args[3] = new LuaOutputStream(resultSet); int count = 4; for (Value value : statement.getFunctionArgs()) { args[count++] = value.getLuaValue(lua); } lua.call("apply_stream", args); } finally { // Send end command to user's result set. // If query was already cancelled, this put will be ignored. resultSet.put(ResultSet.END); } }