This commit is contained in:
@@ -46,16 +46,12 @@ public class ApnsService implements Service {
|
|||||||
@Resource(name = "property.apns.buffersize") //
|
@Resource(name = "property.apns.buffersize") //
|
||||||
protected int apnsbuffersize = 4096;
|
protected int apnsbuffersize = 4096;
|
||||||
|
|
||||||
private final Object socketlock = new Object();
|
|
||||||
|
|
||||||
private boolean inited = false;
|
private boolean inited = false;
|
||||||
|
|
||||||
private final CountDownLatch cdl = new CountDownLatch(1);
|
private final CountDownLatch cdl = new CountDownLatch(1);
|
||||||
|
|
||||||
private SSLSocketFactory sslFactory;
|
private SSLSocketFactory sslFactory;
|
||||||
|
|
||||||
private Socket pushSocket;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(AnyValue conf) {
|
public void init(AnyValue conf) {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@@ -95,10 +91,6 @@ public class ApnsService implements Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy(AnyValue conf) {
|
public void destroy(AnyValue conf) {
|
||||||
try {
|
|
||||||
if (pushSocket != null) pushSocket.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Socket getPushSocket() throws IOException {
|
private Socket getPushSocket() throws IOException {
|
||||||
@@ -108,15 +100,8 @@ public class ApnsService implements Service {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.sslFactory == null) return null;
|
Socket pushSocket = sslFactory.createSocket(apnspushaddr, apnspushport);
|
||||||
if (pushSocket == null || pushSocket.isClosed()) {
|
pushSocket.setTcpNoDelay(true);
|
||||||
synchronized (socketlock) {
|
|
||||||
if (pushSocket == null || pushSocket.isClosed()) {
|
|
||||||
pushSocket = sslFactory.createSocket(apnspushaddr, apnspushport);
|
|
||||||
pushSocket.setTcpNoDelay(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pushSocket;
|
return pushSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +142,7 @@ public class ApnsService implements Service {
|
|||||||
|
|
||||||
Socket socket = getPushSocket();
|
Socket socket = getPushSocket();
|
||||||
socket.getOutputStream().write(buffer.array(), 0, buffer.remaining());
|
socket.getOutputStream().write(buffer.array(), 0, buffer.remaining());
|
||||||
|
socket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user