Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add partial reset() method #183

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions agrona/src/main/java/org/agrona/nio/NioSelectedKeySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ public void reset()
size = 0;
}

/**
* Reset for next iteration, having only processed a subset of the selection keys.
*
* The <code>NioSelectedKeySet</code> will still contain the keys representing IO events after
* the numberOfProcessedKeys and these events can be processed in a future iteration.
*
* @param numberOfProcessedKeys the number of keys that have been processed.
*/
public void reset(final int numberOfProcessedKeys)
{
final SelectionKey[] keys = this.keys;
final int initialSize = this.size;
final int newSize = initialSize - numberOfProcessedKeys;

System.arraycopy(keys, numberOfProcessedKeys, keys, 0, newSize);

this.size = newSize;
}

/**
* Iterate over the key set and apply the given function.
*
Expand Down