Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Resurrect Channel.id() #1810

Closed
trustin opened this Issue · 12 comments

6 participants

@trustin
Owner

If we don't insist the type of Channel.id() to be an integer, I think we might be able to make it unique for sure. For example, it could be hashCode + identityHashCode + nanoTime + sequence. Practically, this should never collide.

@normanmaurer
Collaborator

@trustin good idea... will you work on this ?

@fredericBregier
Collaborator

Just a proposal : why not using uuid (real one) such that unicity is provable ?

@fredericBregier
Collaborator

Note: not uuid from jvm but another implementation...

@trustin
Owner

Yeah, we can do that, too. 3.x had to work with Java 5 which did not have access to the hardware address of the network interface, but the minimum requirement of 4.x is Java 6, so we can definitely do that.

@trustin
Owner

I think we can even use the UUID from JDK as long as we feed all the fields by ourselves.

@normanmaurer
Collaborator

@trustin you will take care?

@hepin1989

the id can be everything,Long or String ,I think there is no need to insist it as an Integer

@fredericBregier
Collaborator

From my own research, what I've found on various implementation as probably the best is the following combination in UUID:

  • partial MAC address (to ensure difference between 2 hosts), set statically at the beginning of the JVM
  • a JVM PID (to ensure difference between 2 JVM on the same host), set statically at the beginning of the JVM
  • partial timestamp in ms (since nano is not always implemented and so last bytes are just 0, and since most of the front bytes are 0)
  • and finally a counter to prevent 2 same values on the same ms (as AtomicLong) (this is the tricker part I've found that ensures that 2 immediate consecutive or simultaneous demands of UUID are still different)

My 2 cents...

@matlach

like hepin1989 said, id should be anything,

to me:

  • channel.id() should return an java.lang.Object (or maybe a T to avoid cast ?)
  • it should be allowed for user to provide a certain implementation for a "ChannelIdGenerator" interface with a given "public Object generateId(Channel channel)" method to implements
  • the default proposed netty channel id strategy should implement this interface

As for the implementation detail of the id, I think fredericBregier have a good point.
Maybe also looking on how jgroups and/or infinispan generate their unique cluster id could be helpful ?

@darionyaphet

@trustin @normanmaurer

UUID maybe human unreadable .....

@normanmaurer
Collaborator
@hepin1989

mostly,we using the channel as a key for the map,why should it be human readable?

@trustin trustin closed this issue from a commit
@trustin trustin Resurrect Channel.id() with global uniqueness
- Fixes #1810
- Add a new interface ChannelId and its default implementation which generates globally unique channel ID.
- Replace AbstractChannel.hashCode with ChannelId.hashCode() and ChannelId.shortValue()
- Add variants of ByteBuf.hexDump() which accept byte[] instead of ByteBuf.
2235873
@trustin trustin closed this in 2235873
@trustin trustin was assigned
@trustin trustin referenced this issue from a commit
@trustin trustin Resurrect Channel.id() with global uniqueness
- Fixes #1810
- Add a new interface ChannelId and its default implementation which generates globally unique channel ID.
- Replace AbstractChannel.hashCode with ChannelId.hashCode() and ChannelId.shortValue()
- Add variants of ByteBuf.hexDump() which accept byte[] instead of ByteBuf.
99aa9ea
@trustin trustin referenced this issue from a commit
@trustin trustin Resurrect Channel.id() with global uniqueness
- Fixes #1810
- Add a new interface ChannelId and its default implementation which generates globally unique channel ID.
- Replace AbstractChannel.hashCode with ChannelId.hashCode() and ChannelId.shortValue()
- Add variants of ByteBuf.hexDump() which accept byte[] instead of ByteBuf.
40003ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.