-
Notifications
You must be signed in to change notification settings - Fork 448
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
Optionally close connections when inactive #116
Changes from 7 commits
ef6763d
0fef77c
54d57a2
44356fa
b0a027c
e7576fa
6b39dde
8a67836
d08ad7a
d10f979
343c894
263aca7
7814c0f
67e1123
8667e84
e3507ae
dea9b7d
b3b6e31
2b4848d
f5ab059
10ede21
1d6e774
8d06356
2febe14
e85b249
524b9ec
2f64f36
5cf6ce1
afd937a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
public class ApnsConnectionConfiguration { | ||
|
||
private int sentNotificationBufferCapacity = ApnsConnection.DEFAULT_SENT_NOTIFICATION_BUFFER_CAPACITY; | ||
private Integer closeAfterInactivityTime = null; | ||
|
||
/** | ||
* Creates a new connection configuration object with all options set to their default values. | ||
|
@@ -22,6 +23,7 @@ public ApnsConnectionConfiguration() {} | |
*/ | ||
public ApnsConnectionConfiguration(final ApnsConnectionConfiguration configuration) { | ||
this.sentNotificationBufferCapacity = configuration.sentNotificationBufferCapacity; | ||
this.closeAfterInactivityTime = configuration.closeAfterInactivityTime; | ||
} | ||
|
||
/** | ||
|
@@ -42,27 +44,60 @@ public int getSentNotificationBufferCapacity() { | |
* @param sentNotificationBufferCapacity the sent notification buffer capacity for connections created with this | ||
* configuration | ||
*/ | ||
public void setSentNotificationBufferCapacity(int sentNotificationBufferCapacity) { | ||
public void setSentNotificationBufferCapacity(final int sentNotificationBufferCapacity) { | ||
this.sentNotificationBufferCapacity = sentNotificationBufferCapacity; | ||
} | ||
|
||
/** | ||
* Returns the time, in seconds, since the last push notification was sent after which connections created with this | ||
* configuration will be closed. If {@code null}, connections created with this configuration will never be closed | ||
* due to inactivity. | ||
* | ||
* @return the time, in seconds, since the last push notification was sent after which connections created with this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: A little rephrasing might make this clearer. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah -- that's way better. Done in 10ede21. |
||
* configuration will be closed | ||
*/ | ||
public Integer getCloseAfterInactivityTime() { | ||
return this.closeAfterInactivityTime; | ||
} | ||
|
||
/** | ||
* Sets the time, in seconds, since the last push notification was sent after which connections created with this | ||
* configuration will be closed. If {@code null} (the default), connections will never be closed due to inactivity. | ||
* | ||
* @param closeAfterInactivityTime the time, in seconds since the last push notification was sent, after which | ||
* connections will be closed | ||
*/ | ||
public void setCloseAfterInactivityTime(final Integer closeAfterInactivityTime) { | ||
this.closeAfterInactivityTime = closeAfterInactivityTime; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime | ||
* result | ||
+ ((closeAfterInactivityTime == null) ? 0 | ||
: closeAfterInactivityTime.hashCode()); | ||
result = prime * result + sentNotificationBufferCapacity; | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
public boolean equals(final Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
ApnsConnectionConfiguration other = (ApnsConnectionConfiguration) obj; | ||
final ApnsConnectionConfiguration other = (ApnsConnectionConfiguration) obj; | ||
if (closeAfterInactivityTime == null) { | ||
if (other.closeAfterInactivityTime != null) | ||
return false; | ||
} else if (!closeAfterInactivityTime | ||
.equals(other.closeAfterInactivityTime)) | ||
return false; | ||
if (sentNotificationBufferCapacity != other.sentNotificationBufferCapacity) | ||
return false; | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can
configuration
be null as well? If so, an extra null check for that as well would be great.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but I made that clearer in 2b4848d.
There's already a test to make sure constructing a connection fails with a
NullPointerException
, but that was happening by way of making an unchecked read to the given configuration object (we would try to blindly read the sent notification buffer size) rather than checking for null configurations directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops -- f5ab059, too.