Reputation: 6227
I need to have a unique ID for each of my SelectionKey
. Can I use some internal id from the SelectionKeyImpl
? I could use the FD for example, but I am not confident I will be always unique per SelectionKey
.
Upvotes: 0
Views: 201
Reputation: 4357
You could use your own ids (such as java.util.UUID) and attach them to the keys via SelectionKey.attach(Object) or when registering the channel with the Selector
Upvotes: 1
Reputation: 311023
There is no FD in a SelectionKey. There is an FD you can reach via the underlying Channel but a channel may have several SelectionKeys so that's no use to you. All you have is the SelectionKey's own identity.
Upvotes: 1