-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from blakesmith/unsubscribe_v2
LIS-9781: Introduce SubscriptionId for unique subscription identifiers
- Loading branch information
Showing
4 changed files
with
126 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.sproutsocial.nsq; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* Represents a unique subscription that's returned from a call to {@link Subscriber#subscribe}. | ||
* Can be passed to methods such as {@link Subscriber#unsubscribe} to remove a subscription. | ||
*/ | ||
public class SubscriptionId { | ||
private final long id; | ||
|
||
protected SubscriptionId(final long id) { | ||
this.id = id; | ||
} | ||
|
||
static SubscriptionId fromCounter(final AtomicLong counter) { | ||
return new SubscriptionId(counter.getAndIncrement()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { return true; } | ||
if (!(other instanceof SubscriptionId)) { return false; } | ||
SubscriptionId that = (SubscriptionId)other; | ||
return id == that.id; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SubscriptionId { " + id + " }"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters