當前位置: 首頁>>代碼示例>>Java>>正文


Java Jsons類代碼示例

本文整理匯總了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();
}
 
開發者ID:mpusher,項目名稱:alloc,代碼行數:17,代碼來源:PushHandler.java

示例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());

}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:24,代碼來源:PushRequest.java

示例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);
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:19,代碼來源:HttpProxyDnsMappingManager.java

示例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);
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:23,代碼來源:GatewayPushListener.java

示例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);
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:24,代碼來源:GatewayPushListener.java

示例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);
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:22,代碼來源:GatewayPushListener.java

示例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);
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:24,代碼來源:GatewayPushListener.java

示例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);
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:24,代碼來源:GatewayPushListener.java

示例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);
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:24,代碼來源:GatewayPushListener.java

示例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={}");
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:22,代碼來源:ZKCacheListener.java

示例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());
                }
            })
    );
}
 
開發者ID:mpusher,項目名稱:alloc,代碼行數:29,代碼來源:PushHandler.java

示例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);
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:14,代碼來源:RouterChangeListener.java

示例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));
    }
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:9,代碼來源:ZKServiceRegistryAndDiscovery.java

示例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());
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:16,代碼來源:ZKServiceRegistryAndDiscovery.java

示例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;
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:12,代碼來源:FileCacheManger.java


注:本文中的com.mpush.tools.Jsons類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。