本文整理汇总了Java中com.notnoop.apns.ApnsNotification类的典型用法代码示例。如果您正苦于以下问题:Java ApnsNotification类的具体用法?Java ApnsNotification怎么用?Java ApnsNotification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApnsNotification类属于com.notnoop.apns包,在下文中一共展示了ApnsNotification类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: ApnsConnectionImpl
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public ApnsConnectionImpl(SocketFactory factory, String host,
int port, Proxy proxy,
ReconnectPolicy reconnectPolicy, ApnsDelegate delegate,
boolean errorDetection, int cacheLength, boolean autoAdjustCacheLength) {
this.factory = factory;
this.host = host;
this.port = port;
this.reconnectPolicy = reconnectPolicy;
this.delegate = delegate == null ? ApnsDelegate.EMPTY : delegate;
this.proxy = proxy;
this.errorDetection = errorDetection;
this.cacheLength = cacheLength;
this.autoAdjustCacheLength = autoAdjustCacheLength;
cachedNotifications = new ConcurrentLinkedQueue<ApnsNotification>();
notificationsBuffer = new ConcurrentLinkedQueue<ApnsNotification>();
}
开发者ID:East196,项目名称:maker,代码行数:17,代码来源:ApnsConnectionImpl.java
示例2: push
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
@Override
public void push(ApnsNotification message) throws NetworkIOException {
if (batch.isEmpty()) {
firstMessageArrivedTime = System.nanoTime();
}
long sincFirstMessageSec = (System.nanoTime() - firstMessageArrivedTime) / 1000 / 1000 / 1000;
if (taskFuture != null && sincFirstMessageSec < maxBatchWaitTimeInSec) {
taskFuture.cancel(false);
}
batch.add(message);
if (taskFuture == null || taskFuture.isDone()) {
taskFuture = scheduleService.schedule(batchRunner, batchWaitTimeInSec, TimeUnit.SECONDS);
}
}
开发者ID:East196,项目名称:maker,代码行数:19,代码来源:BatchApnsService.java
示例3: pushSimpleMessage
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
/**
* Push simple (text only) message to client.
*
* @param roleName
* @param deviceToken
* @param text
* @return
*/
public final boolean pushSimpleMessage(final String roleName,
final String deviceToken, final String text, int expireSeconds) {
boolean success = true;
if ( StringUtil.checkNotEmpty(deviceToken) && iosApnService != null ) {
GameContext.getInstance().runSmallTask(new Runnable() {
public void run() {
//ios device
PayloadBuilder builder = PayloadBuilder.newPayload();
builder.badge(1);
builder.alertBody(text);
ApnsNotification notif = iosApnService.push(deviceToken, builder.build());
}
});
logger.debug("Push message '{}' to ios device", text);
} else {
//android devices
String offlineBox = getOfflineboxName(roleName);
pushValueInList(offlineBox, text, 10, expireSeconds);
logger.debug("Push message '{}' to android device", text);
}
return success;
}
开发者ID:wangqi,项目名称:gameserver,代码行数:31,代码来源:MailMessageManager.java
示例4: start
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public void start() {
if (started.getAndSet(true)) {
// I prefer if we throw a runtime IllegalStateException here,
// but I want to maintain semantic backward compatibility.
// So it is returning immediately here
return;
}
service.start();
shouldContinue = true;
thread = new Thread() {
public void run() {
while (shouldContinue) {
try {
ApnsNotification msg = queue.take();
service.push(msg);
} catch (InterruptedException e) {
}
}
}
};
thread.start();
}
开发者ID:wangqi,项目名称:gameserver,代码行数:24,代码来源:QueuedApnsService.java
示例5: ApnsConnectionImpl
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public ApnsConnectionImpl(SocketFactory factory, String host, int port, Proxy proxy, String proxyUsername, String proxyPassword,
ReconnectPolicy reconnectPolicy, ApnsDelegate delegate, boolean errorDetection, ThreadFactory tf, int cacheLength,
boolean autoAdjustCacheLength, int readTimeout, int connectTimeout) {
this.factory = factory;
this.host = host;
this.port = port;
this.reconnectPolicy = reconnectPolicy;
this.delegate = delegate == null ? ApnsDelegate.EMPTY : delegate;
this.proxy = proxy;
this.errorDetection = errorDetection;
this.threadFactory = tf == null ? defaultThreadFactory() : tf;
this.cacheLength = cacheLength;
this.autoAdjustCacheLength = autoAdjustCacheLength;
this.readTimeout = readTimeout;
this.connectTimeout = connectTimeout;
this.proxyUsername = proxyUsername;
this.proxyPassword = proxyPassword;
cachedNotifications = new ConcurrentLinkedQueue<ApnsNotification>();
notificationsBuffer = new ConcurrentLinkedQueue<ApnsNotification>();
}
开发者ID:dzh,项目名称:jframe,代码行数:21,代码来源:ApnsConnectionImpl.java
示例6: sendMessage
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public void sendMessage(final ApnsNotification m) throws NetworkIOException {
Future<Void> future = executors.submit(new Callable<Void>() {
public Void call() throws Exception {
uniquePrototype.get().sendMessage(m);
return null;
}
});
try {
future.get();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
} catch (ExecutionException ee) {
if (ee.getCause() instanceof NetworkIOException) {
throw (NetworkIOException) ee.getCause();
}
}
}
开发者ID:dzh,项目名称:jframe,代码行数:18,代码来源:ApnsPooledConnection.java
示例7: push
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
@Override
public void push(ApnsNotification message) throws NetworkIOException {
if (batch.isEmpty()) {
firstMessageArrivedTime = System.nanoTime();
}
long sinceFirstMessageSec = (System.nanoTime() - firstMessageArrivedTime) / 1000 / 1000 / 1000;
if (taskFuture != null && sinceFirstMessageSec < maxBatchWaitTimeInSec) {
taskFuture.cancel(false);
}
batch.add(message);
if (taskFuture == null || taskFuture.isDone()) {
taskFuture = scheduleService.schedule(batchRunner, batchWaitTimeInSec, TimeUnit.SECONDS);
}
}
开发者ID:dzh,项目名称:jframe,代码行数:19,代码来源:BatchApnsService.java
示例8: simpleBatchWait_one
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
@Test
public void simpleBatchWait_one() throws IOException, InterruptedException {
// send message
ApnsNotification message = service.push("1234", "{}");
// make sure no message was send yet
verify(prototype, times(0)).copy();
verify(prototype, times(0)).sendMessage(message);
verify(prototype, times(0)).close();
Thread.sleep(delayTimeInSec_millis + /* for sure */250);
// verify batch sends and close the connection
verify(prototype, times(1)).copy();
verify(prototype, times(1)).sendMessage(message);
verify(prototype, times(1)).close();
}
开发者ID:leancloud,项目名称:java-apns,代码行数:18,代码来源:BatchApnsServiceTest.java
示例9: notify
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
private void notify(Exchange exchange) throws ApnsException {
MessageType messageType = getHeaderMessageType(exchange, MessageType.STRING);
if (messageType == MessageType.APNS_NOTIFICATION) {
ApnsNotification apnsNotification = exchange.getIn().getBody(ApnsNotification.class);
getEndpoint().getApnsService().push(apnsNotification);
} else {
constructNotificationAndNotify(exchange, messageType);
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:ApnsProducer.java
示例10: sendMessage
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public synchronized void sendMessage(ApnsNotification m, boolean fromBuffer) throws NetworkIOException {
int attempts = 0;
while (true) {
try {
attempts++;
Socket socket = socket();
socket.getOutputStream().write(m.marshall());
socket.getOutputStream().flush();
cacheNotification(m);
delegate.messageSent(m, fromBuffer);
logger.debug("Message \"{}\" sent", m);
attempts = 0;
drainBuffer();
break;
} catch (Exception e) {
Utilities.close(socket);
socket = null;
if (attempts >= RETRIES) {
logger.error("Couldn't send message after " + RETRIES + " retries." + m, e);
delegate.messageSendFailed(m, e);
Utilities.wrapAndThrowAsRuntimeException(e);
}
// The first failure might be due to closed connection
// don't delay quite yet
if (attempts != 1) {
// Do not spam the log files when the APNS server closed the socket (due to a
// bad token, for example), only log when on the second retry.
logger.info("Failed to send message " + m + "... trying again after delay", e);
Utilities.sleep(DELAY_IN_MS);
}
}
}
}
开发者ID:East196,项目名称:maker,代码行数:38,代码来源:ApnsConnectionImpl.java
示例11: cacheNotification
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
private void cacheNotification(ApnsNotification notification) {
cachedNotifications.add(notification);
while (cachedNotifications.size() > cacheLength) {
cachedNotifications.poll();
logger.debug("Removing notification from cache " + notification);
}
}
开发者ID:East196,项目名称:maker,代码行数:8,代码来源:ApnsConnectionImpl.java
示例12: sendMessage
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public void sendMessage(final ApnsNotification m) throws NetworkIOException {
executors.execute(new Runnable() {
public void run() {
uniquePrototype.get().sendMessage(m);
}
});
}
开发者ID:East196,项目名称:maker,代码行数:8,代码来源:ApnsPooledConnection.java
示例13: run
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public void run() {
ApnsConnection newConnection = prototype.copy();
try {
ApnsNotification msg = null;
while ((msg = batch.poll()) != null) {
try {
newConnection.sendMessage(msg);
} catch (NetworkIOException e) {
continue;
}
}
} finally {
Utilities.close(newConnection);
}
}
开发者ID:East196,项目名称:maker,代码行数:16,代码来源:BatchApnsService.java
示例14: push
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
@Override
public void push(ApnsNotification msg) {
if (!started.get()) {
throw new IllegalStateException("service hasn't be started or was closed");
}
queue.add(msg);
}
开发者ID:East196,项目名称:maker,代码行数:8,代码来源:QueuedApnsService.java
示例15: start
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public void start() {
if (started.getAndSet(true)) {
// I prefer if we throw a runtime IllegalStateException here,
// but I want to maintain semantic backward compatibility.
// So it is returning immediately here
return;
}
service.start();
shouldContinue = true;
thread = new Thread() {
public void run() {
while (shouldContinue) {
try {
ApnsNotification msg = queue.take();
service.push(msg);
} catch (InterruptedException e) {
// ignore
} catch (NetworkIOException e) {
// ignore: failed connect...
} catch (Exception e) {
// weird if we reached here - something wrong is happening, but we shouldn't stop the service anyway!
logger.warn("Unexpected message caught... Shouldn't be here", e);
}
}
}
};
thread.start();
}
开发者ID:East196,项目名称:maker,代码行数:30,代码来源:QueuedApnsService.java
示例16: messageSendFailed
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
@Override
public void messageSendFailed(ApnsNotification message, Throwable e) {
LOGGER.error("APNS Message delivery failed for key:{}", key, e);
if (message != null) {
byte[] tokenByte = message.getDeviceToken();
String deviceToken = Utilities.encodeHex(tokenByte);
LOGGER.error("APNS Message delivery failed for key:{}", key, e);
//TODO : Revisit failure handling. Commented on 12/17/2015
// invalidateToken(deviceToken);
// byte[] payload = message.getPayload();
// String payloadString = fromBytes(payload);
// if (payloadString != null) {
// APNSPayloadInfo info = APNSPayloadInfo.parse(payloadString);
// if (info != null && info.getMessageId() != null) {
// Integer errorCode = null;
// if (e instanceof ApnsDeliveryErrorException) {
// errorCode = Integer.valueOf(((ApnsDeliveryErrorException) e).getDeliveryError().code());
// }
// //mark push message state as error
// updatePushMessageState(info.getMessageId(), errorCode);
// }
// }
} else {
LOGGER.error("APNS Message delivery failed but ApnsNotification message is null and hence can't invalidate the token");
}
}
开发者ID:magnetsystems,项目名称:message-server,代码行数:28,代码来源:MMXAPNSDelegate.java
示例17: sendMessage
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public synchronized void sendMessage(ApnsNotification m) throws NetworkIOException {
int attempts = 0;
while (true) {
try {
attempts++;
Socket socket = socket();
socket.getOutputStream().write(m.marshall());
socket.getOutputStream().flush();
delegate.messageSent(m);
logger.debug("Message \"{}\" sent", m);
attempts = 0;
break;
} catch (Exception e) {
if (attempts >= RETRIES) {
logger.error("Couldn't send message " + m, e);
delegate.messageSendFailed(m, e);
Utilities.wrapAndThrowAsRuntimeException(e);
}
logger.warn("Failed to send message " + m + "... trying again", e);
// The first failure might be due to closed connection
// don't delay quite yet
if (attempts != 1)
Utilities.sleep(DELAY_IN_MS);
Utilities.close(socket);
socket = null;
}
}
}
开发者ID:wangqi,项目名称:gameserver,代码行数:31,代码来源:ApnsConnectionImpl.java
示例18: sendMessage
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
private synchronized void sendMessage(ApnsNotification m, boolean fromBuffer) throws NetworkIOException {
logger.debug("sendMessage {} fromBuffer: {}", m, fromBuffer);
int attempts = 0;
while (true) {
try {
attempts++;
Socket socket = getOrCreateSocket();
socket.getOutputStream().write(m.marshall());
socket.getOutputStream().flush();
cacheNotification(m);
delegate.messageSent(m, fromBuffer);
//logger.debug("Message \"{}\" sent", m);
attempts = 0;
break;
} catch (IOException e) {
Utilities.close(socket);
if (attempts >= RETRIES) {
logger.error("Couldn't send message after " + RETRIES + " retries." + m, e);
delegate.messageSendFailed(m, e);
Utilities.wrapAndThrowAsRuntimeException(e);
}
// The first failure might be due to closed connection (which in turn might be caused by
// a message containing a bad token), so don't delay for the first retry.
//
// Additionally we don't want to spam the log file in this case, only after the second retry
// which uses the delay.
if (attempts != 1) {
logger.info("Failed to send message " + m + "... trying again after delay", e);
Utilities.sleep(DELAY_IN_MS);
}
}
}
}
开发者ID:dzh,项目名称:jframe,代码行数:38,代码来源:ApnsConnectionImpl.java
示例19: run
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public void run() {
ApnsConnection newConnection = prototype.copy();
try {
ApnsNotification msg;
while ((msg = batch.poll()) != null) {
try {
newConnection.sendMessage(msg);
} catch (NetworkIOException e) {
logger.warn("Network exception sending message msg "+ msg.getIdentifier(), e);
}
}
} finally {
Utilities.close(newConnection);
}
}
开发者ID:dzh,项目名称:jframe,代码行数:16,代码来源:BatchApnsService.java
示例20: QueuedApnsService
import com.notnoop.apns.ApnsNotification; //导入依赖的package包/类
public QueuedApnsService(ApnsService service, final ThreadFactory tf) {
super(null);
this.service = service;
this.queue = new LinkedBlockingQueue<ApnsNotification>();
this.threadFactory = tf == null ? Executors.defaultThreadFactory() : tf;
this.thread = null;
}
开发者ID:dzh,项目名称:jframe,代码行数:8,代码来源:QueuedApnsService.java
注:本文中的com.notnoop.apns.ApnsNotification类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论