com.creditease.ns.log.NsLog Java Examples

The following examples show how to use com.creditease.ns.log.NsLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultBufferManager.java    From ns4_frame with Apache License 2.0 6 votes vote down vote up
@Override
public ServiceMessage getFromReceiveBuffer(String queueName, boolean isSync) throws InterruptedException, Exception {
    long startTime = System.currentTimeMillis();
    ServiceMessage mqMessage = null;
    handlerLog.debug("# 获取接收缓存中的消息对象 queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime);
    try {
        if (isSync) {
            mqMessage = queueNameToReceiveBuffer.get(queueName).take();
        } else {
            mqMessage = queueNameToReceiveBuffer.get(queueName).poll();
        }
    } catch (InterruptedException e) {
        handlerLog.debug("# 获取接收缓存中对象 失败 线程中断 queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime);
        throw e;
    }

    NsLog.setMsgId(mqMessage.getHeader().getMessageID());
    handlerLog.trace("# messageHeader:{} #", mqMessage.getHeader());
    handlerLog.info("# 获取接收缓存中的消息对象 OK queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime);
    return mqMessage;
}
 
Example #2
Source File: PrintUtil.java    From ns4_frame with Apache License 2.0 6 votes vote down vote up
public static void printDateStamp(NsLog log, String[] mes){
    if (log != null){
        log.info("┌                                        ┐");
        log.info("  Time:    "+new Date());
        for (int i=0;i<mes.length;i++){
            log.info("  "+i+": "+mes[i]);
        }
        log.info("└                                        ┘");
    } else {
        System.out.println("┌                                        ┐");
        System.out.println("  Time:    "+new Date());
        for (int i=0;i<mes.length;i++){
            System.out.println("  "+i+": "+mes[i]);
        }
        System.out.println("└                                        ┘");
    }
}
 
Example #3
Source File: PrintUtil.java    From ns4_frame with Apache License 2.0 6 votes vote down vote up
public static void printDateStamp(NsLog log, List<String> mes){
    if (log != null){
        log.info("┌                                                ┐");
        log.info("  Time:    "+new Date());
        for (int i=0;i<mes.size();i++){
            log.info("  "+i+": "+mes.get(i));
        }
        log.info("└                                                ┘");
    } else {
        System.out.println("┌                                                ┐");
        System.out.println("  Time:    "+new Date());
        for (int i=0;i<mes.size();i++){
            System.out.println("  "+i+": "+mes.get(i));
        }
        System.out.println("└                                                ┘");
    }
}
 
Example #4
Source File: MonitorDataFrame.java    From ns4_gear_watchdog with Apache License 2.0 5 votes vote down vote up
public Object getData(MessageType messageType) {
    //TODO 转成json
    if(null != monitorDataMap.get(messageType) && monitorDataMap.get(messageType).size()>0){
        NsLog.getFramLog().info("收到监控消息 {}", JSON.toJSONString(monitorDataMap.get(messageType)));
        return monitorDataMap.get(messageType).getFirst();
    }else {
        return null;
    }
}
 
Example #5
Source File: MonitorDataFrame.java    From ns4_gear_watchdog with Apache License 2.0 5 votes vote down vote up
public Object pollData(MessageType messageType) {
    //TODO 转成json
    if(null != monitorDataMap.get(messageType) && monitorDataMap.get(messageType).size()>0){
        NsLog.getFramLog().info("收到监控消息 {}", JSON.toJSONString(monitorDataMap.get(messageType)));
        return monitorDataMap.get(messageType).poll();
    }else {
        return null;
    }
}
 
Example #6
Source File: DefaultHandler.java    From ns4_frame with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    frameLog.debug("{} {} 开始运行", Thread.currentThread().getName(), queueName);
    while (!isStop && !Thread.interrupted()) {
        handle();
        NsLog.removeMsgId();
    }
}
 
Example #7
Source File: DefaultBufferManager.java    From ns4_frame with Apache License 2.0 5 votes vote down vote up
/**
 * 这里不需要考虑put的线程安全性,原因如下:
 * 1.线程不安全的情况下,最危险的情况可能会是放入缓存中消息的顺序,但是在我们这种场景下,消息顺序并不重要
 * 2.当前只有一个线程会进行进入队列的缓存存放
 * 3.底层是线程安全的
 */
@Override
public void putInReceiveBuffer(String queueName, ServiceMessage message) throws Exception {
    long startTime = System.currentTimeMillis();
    fetchLog.debug("# 将消息对象放入接收缓存中 queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime);
    queueNameToReceiveBuffer.get(queueName).put(message);
    fetchLog.trace("# messageHeader:{} #", message.getHeader());
    fetchLog.info("# 将消息对象放入接收缓存中 OK queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime);
    NsLog.removeMsgId();
}
 
Example #8
Source File: DefaultBufferManager.java    From ns4_frame with Apache License 2.0 5 votes vote down vote up
@Override
public void putInSendBuffer(String queueName, ServiceMessage message)
        throws Exception {
    long startTime = System.currentTimeMillis();
    handlerLog.debug("# 将消息对象放入发送缓存 queueName:{} sendbuffersize:{} cost:{}ms #", queueName, queueNameToSendBuffer.get(queueName).size(), System.currentTimeMillis() - startTime);
    ((BlockingQueue<ServiceMessage>) queueNameToSendBuffer.get(queueName)).put(message);
    handlerLog.trace("# messageHeader:{} #", message.getHeader());
    handlerLog.info("# 将消息对象放入发送缓存 OK queueName:{} sendbuffersize:{} cost:{}ms #", queueName, queueNameToSendBuffer.get(queueName).size(), System.currentTimeMillis() - startTime);
    NsLog.removeMsgId();
}
 
Example #9
Source File: PrintUtil.java    From ns4_frame with Apache License 2.0 5 votes vote down vote up
/**
* @Title: printDateStamp 
* @Description: 打印时间戳 
* @param @param log 
* @param @param mes   
* @return void     
* @throws
 */
public static void printDateStamp(NsLog log, String mes){
    if (log != null){
        log.info("┌                                        ┐");
        log.info("  Time:    "+new Date());
        log.info("  Message: "+mes);
        log.info("└                                        ┘");
    } else {
        System.out.println("┌                                        ┐");
        System.out.println("  Time:    "+new Date());
        System.out.println("  Message: "+mes);
        System.out.println("└                                        ┘");
    }
}
 
Example #10
Source File: NSLogForNetty.java    From ns4_frame with Apache License 2.0 4 votes vote down vote up
NSLogForNetty() {
    super("Netty框架");
    logger = NsLog.getFramLog("Dispatcher", "Netty框架");
}
 
Example #11
Source File: JinChengESBDecoder.java    From ns4_frame with Apache License 2.0 4 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msgIn, List<Object> out) {
    //小于8个字节直接舍弃
    if (msgIn.readableBytes() < 8) {
        return;
    }
    //初始可读标志位
    int beginIndex = msgIn.readerIndex();
    byte[] pkgLenBytes = new byte[8];
    msgIn.readBytes(pkgLenBytes);
    Integer length = Integer.valueOf(new String(pkgLenBytes, Charsets.UTF_8));

    if ((msgIn.readableBytes() + 8) < length) {
        msgIn.readerIndex(beginIndex);
        return;
    }

    ByteBuf contentBytes = msgIn.readBytes(length);

    byte[] headerBytes = new byte[124];
    System.arraycopy(pkgLenBytes, 0, headerBytes, 0, 8);
    byte[] otherHeaderBytes = new byte[116];
    contentBytes.readBytes(otherHeaderBytes);
    System.arraycopy(otherHeaderBytes, 0, headerBytes, 8, 116);

    byte[] prcscd = new byte[8];
    System.arraycopy(headerBytes, 44, prcscd, 0, 8);
    int xmlLength = contentBytes.readableBytes();
    byte[] xmlBytes = new byte[xmlLength];
    contentBytes.getBytes(contentBytes.readerIndex(), xmlBytes);

    TcpContext tcpContext = new TcpContext();
    tcpContext.setId(UUID.randomUUID().toString());
    NsLog.setMsgId(tcpContext.getId());
    tcpContext.getRequest().setServerName(new String(prcscd, Charsets.UTF_8).trim());
    tcpContext.getRequest().setAccessTimeStamp(System.currentTimeMillis());
    ((TcpRequest) tcpContext.getRequest()).setHeadMessage(new String(headerBytes, Charsets.UTF_8));
    ((TcpRequest) tcpContext.getRequest()).setXMLContent(new String(xmlBytes, Charsets.UTF_8));

    out.add(tcpContext);
}
 
Example #12
Source File: NsLogger.java    From ns4_gear_idgen with Apache License 2.0 4 votes vote down vote up
public static NsLog getLog(String key) {
    return log.get(key);
}
 
Example #13
Source File: NsLogger.java    From ns4_gear_watchdog with Apache License 2.0 votes vote down vote up
public static NsLog getWatchdogLogger() {
        return getLogger(LoggerType.LOG_WATCHDOG);
    } 
Example #14
Source File: NsLogger.java    From ns4_gear_watchdog with Apache License 2.0 votes vote down vote up
public static NsLog getWatchdogPluginLogger() {
        return getLogger(LoggerType.LOG_WATCHDOG_PLUGIN);
    } 
Example #15
Source File: NsLogger.java    From ns4_gear_watchdog with Apache License 2.0 votes vote down vote up
public static NsLog getWatchdogCollectLogger() {
        return getLogger(LoggerType.LOG_WATCHDOG_COLLECT);
    } 
Example #16
Source File: NsLogger.java    From ns4_gear_watchdog with Apache License 2.0 votes vote down vote up
public static NsLog getLogger(LoggerType key) {
        return NsLog.getLog(key.getValue());
    }