本文整理汇总了Java中com.mpush.tools.Jsons类的典型用法代码示例。如果您正苦于以下问题:Java Jsons类的具体用法?Java Jsons怎么用?Java Jsons使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Jsons类属于com.mpush.tools包,在下文中一共展示了Jsons类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import com.mpush.tools.Jsons; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String body = new String(readBody(httpExchange), Constants.UTF_8);
Map<String, Object> params = Jsons.fromJson(body, Map.class);
sendPush(params);
byte[] data = "服务已经开始推送,请注意查收消息".getBytes(Constants.UTF_8);
httpExchange.getResponseHeaders().set("Content-Type", "text/plain; charset=utf-8");
httpExchange.sendResponseHeaders(200, data.length);//200, content-length
OutputStream out = httpExchange.getResponseBody();
out.write(data);
out.close();
httpExchange.close();
}
示例2: build
import com.mpush.tools.Jsons; //导入依赖的package包/类
public static PushRequest build(MPushClient mPushClient, PushContext ctx) {
byte[] content = ctx.getContext();
PushMsg msg = ctx.getPushMsg();
if (msg != null) {
String json = Jsons.toJson(msg);
if (json != null) {
content = json.getBytes(Constants.UTF_8);
}
}
Objects.requireNonNull(content, "push content can not be null.");
return new PushRequest(mPushClient)
.setAckModel(ctx.getAckModel())
.setUserId(ctx.getUserId())
.setTags(ctx.getTags())
.setCondition(ctx.getCondition())
.setTaskId(ctx.getTaskId())
.setContent(content)
.setTimeout(ctx.getTimeout())
.setCallback(ctx.getCallback());
}
示例3: run
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void run() {
logger.debug("do dns mapping checkHealth ...");
Map<String, List<DnsMapping>> all = this.getAll();
Map<String, List<DnsMapping>> available = Maps.newConcurrentMap();
all.forEach((key, dnsMappings) -> {
List<DnsMapping> okList = Lists.newArrayList();
dnsMappings.forEach(dnsMapping -> {
if (checkHealth(dnsMapping.getIp(), dnsMapping.getPort())) {
okList.add(dnsMapping);
} else {
logger.warn("dns can not reachable:" + Jsons.toJson(dnsMapping));
}
});
available.put(key, okList);
});
this.update(available);
}
示例4: onSuccess
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void onSuccess(GatewayPushMessage message, Object[] timePoints) {
if (message.getConnection().isConnected()) {
pushCenter.addTask(new PushTask() {
@Override
public ScheduledExecutorService getExecutor() {
return message.getExecutor();
}
@Override
public void run() {
OkMessage
.from(message)
.setData(toJson(message, timePoints))
.sendRaw();
}
});
} else {
Logs.PUSH.warn("push message to client success, but gateway connection is closed, timePoints={}, message={}"
, Jsons.toJson(timePoints), message);
}
}
示例5: onAckSuccess
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void onAckSuccess(GatewayPushMessage message, Object[] timePoints) {
if (message.getConnection().isConnected()) {
pushCenter.addTask(new PushTask() {
@Override
public ScheduledExecutorService getExecutor() {
return message.getExecutor();
}
@Override
public void run() {
OkMessage
.from(message)
.setData(toJson(message, timePoints))
.sendRaw();
}
});
} else {
Logs.PUSH.warn("client ack success, but gateway connection is closed, timePoints={}, message={}"
, Jsons.toJson(timePoints), message);
}
}
示例6: onBroadcastComplete
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void onBroadcastComplete(GatewayPushMessage message, Object[] timePoints) {
if (message.getConnection().isConnected()) {
pushCenter.addTask(new PushTask() {
@Override
public ScheduledExecutorService getExecutor() {
return message.getExecutor();
}
@Override
public void run() {
OkMessage
.from(message)
.sendRaw();
}
});
} else {
Logs.PUSH.warn("broadcast to client finish, but gateway connection is closed, timePoints={}, message={}"
, Jsons.toJson(timePoints), message);
}
}
示例7: onFailure
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void onFailure(GatewayPushMessage message, Object[] timePoints) {
if (message.getConnection().isConnected()) {
pushCenter.addTask(new PushTask() {
@Override
public ScheduledExecutorService getExecutor() {
return message.getExecutor();
}
@Override
public void run() {
ErrorMessage
.from(message)
.setErrorCode(PUSH_CLIENT_FAILURE)
.setData(toJson(message, timePoints))
.sendRaw();
}
});
} else {
Logs.PUSH.warn("push message to client failure, but gateway connection is closed, timePoints={}, message={}"
, Jsons.toJson(timePoints), message);
}
}
示例8: onOffline
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void onOffline(GatewayPushMessage message, Object[] timePoints) {
if (message.getConnection().isConnected()) {
pushCenter.addTask(new PushTask() {
@Override
public ScheduledExecutorService getExecutor() {
return message.getExecutor();
}
@Override
public void run() {
ErrorMessage
.from(message)
.setErrorCode(OFFLINE)
.setData(toJson(message, timePoints))
.sendRaw();
}
});
} else {
Logs.PUSH.warn("push message to client offline, but gateway connection is closed, timePoints={}, message={}"
, Jsons.toJson(timePoints), message);
}
}
示例9: onRedirect
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void onRedirect(GatewayPushMessage message, Object[] timePoints) {
if (message.getConnection().isConnected()) {
pushCenter.addTask(new PushTask() {
@Override
public ScheduledExecutorService getExecutor() {
return message.getExecutor();
}
@Override
public void run() {
ErrorMessage
.from(message)
.setErrorCode(ROUTER_CHANGE)
.setData(toJson(message, timePoints))
.sendRaw();
}
});
} else {
Logs.PUSH.warn("push message to client redirect, but gateway connection is closed, timePoints={}, message={}"
, Jsons.toJson(timePoints), message);
}
}
示例10: childEvent
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void childEvent(CuratorFramework curator, TreeCacheEvent event) throws Exception {
ChildData data = event.getData();
if (data == null) return;
String dataPath = data.getPath();
if (Strings.isNullOrEmpty(dataPath)) return;
if (dataPath.startsWith(watchPath)) {
switch (event.getType()) {
case NODE_ADDED:
listener.onServiceAdded(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class));
break;
case NODE_REMOVED:
listener.onServiceRemoved(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class));
break;
case NODE_UPDATED:
listener.onServiceUpdated(dataPath, Jsons.fromJson(data.getData(), CommonServiceNode.class));
break;
}
Logs.RSD.info("ZK node data change={}, nodePath={}, watchPath={}, ns={}");
}
}
示例11: sendPush
import com.mpush.tools.Jsons; //导入依赖的package包/类
private void sendPush(Map<String, Object> params) {
String userId = (String) params.get("userId");
String hello = (String) params.get("hello");
Boolean broadcast = (Boolean) params.get("broadcast");
String condition = (String) params.get("condition");
NotificationDO notificationDO = new NotificationDO();
notificationDO.content = "MPush开源推送," + hello;
notificationDO.title = "MPUSH推送";
notificationDO.nid = idSeq.get() % 2 + 1;
notificationDO.ticker = "你有一条新的消息,请注意查收";
PushMsg pushMsg = PushMsg.build(MsgType.NOTIFICATION_AND_MESSAGE, Jsons.toJson(notificationDO));
pushMsg.setMsgId("msg_" + idSeq.incrementAndGet());
pushSender.send(PushContext
.build(pushMsg)
.setUserId(Strings.isBlank(userId) ? null : userId)
.setBroadcast(broadcast != null && broadcast)
.setCondition(Strings.isBlank(condition) ? null : condition)
.setCallback(new PushCallback() {
@Override
public void onResult(PushResult result) {
logger.info(result.toString());
}
})
);
}
示例12: receive
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void receive(String topic, Object message) {
if (getKickChannel().equals(topic)) {
KickRemoteMsg msg = Jsons.fromJson(message.toString(), MQKickRemoteMsg.class);
if (msg != null) {
onReceiveKickRemoteMsg(msg);
} else {
Logs.CONN.warn("receive an error kick message={}", message);
}
} else {
Logs.CONN.warn("receive an error redis channel={}", topic);
}
}
示例13: register
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public void register(ServiceNode node) {
if (node.isPersistent()) {
client.registerPersist(node.nodePath(), Jsons.toJson(node));
} else {
client.registerEphemeral(node.nodePath(), Jsons.toJson(node));
}
}
示例14: lookup
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public List<ServiceNode> lookup(String serviceName) {
List<String> childrenKeys = client.getChildrenKeys(serviceName);
if (childrenKeys == null || childrenKeys.isEmpty()) {
return Collections.emptyList();
}
return childrenKeys.stream()
.map(key -> serviceName + PATH_SEPARATOR + key)
.map(client::get)
.filter(Objects::nonNull)
.map(childData -> Jsons.fromJson(childData, CommonServiceNode.class))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
示例15: hgetAll
import com.mpush.tools.Jsons; //导入依赖的package包/类
@Override
public <T> Map<String, T> hgetAll(String key, Class<T> clazz) {
Map<String, Object> m = (Map) cache.get(key);
if (m == null || m.isEmpty()) return Collections.emptyMap();
Map<String, T> result = new HashMap<>();
for (Map.Entry<String, Object> o : m.entrySet()) {
result.put(o.getKey(), Jsons.fromJson(String.valueOf(o.getValue()), clazz));
}
return result;
}