Package com.dianping.cat.message

Examples of com.dianping.cat.message.MessageProducer

or logs event or heartbeat in one shot, for example:

@author Frankie Wu

        break;
      }
    }

    buildClasspath();
    MessageProducer cat = Cat.getProducer();
    Transaction reboot = cat.newTransaction("System", "Reboot");

    reboot.setStatus(Message.SUCCESS);
    cat.logEvent("Reboot", NetworkInterfaceManager.INSTANCE.getLocalHostAddress(), Message.SUCCESS, null);
    reboot.complete();

    while (m_active) {
      long start = MilliSecondTimer.currentTimeMillis();

      if (m_manager.isCatEnabled()) {
        Transaction t = cat.newTransaction("System", "Status");
        Heartbeat h = cat.newHeartbeat("Heartbeat", m_ipAddress);
        StatusInfo status = new StatusInfo();

        t.addData("dumpLocked", m_manager.isDumpLocked());
        try {
          StatusInfoCollector statusInfoCollector = new StatusInfoCollector(m_statistics, m_jars);

          status.accept(statusInfoCollector.setDumpLocked(m_manager.isDumpLocked()));

          buildExtensionData(status);
          h.addData(status.toString());
          h.setStatus(Message.SUCCESS);
        } catch (Throwable e) {
          h.setStatus(e);
          cat.logError(e);
        } finally {
          h.complete();
        }
        t.setStatus(Message.SUCCESS);
        t.complete();
View Full Code Here


    }
  }

  @Override
  public MessageTree loadMessage(String messageId) throws IOException {
    MessageProducer cat = Cat.getProducer();
    Transaction t = cat.newTransaction("BucketService", getClass().getSimpleName());

    t.setStatus(Message.SUCCESS);

    try {
      MessageId id = MessageId.parse(messageId);
      final String path = m_pathBuilder.getPath(new Date(id.getTimestamp()), "");
      final File dir = new File(m_baseDir, path);
      final String key = id.getDomain() + '-' + id.getIpAddress();
      final List<String> paths = new ArrayList<String>();

      Scanners.forDir().scan(dir, new FileMatcher() {
        @Override
        public Direction matches(File base, String name) {
          if (name.contains(key) && !name.endsWith(".idx")) {
            paths.add(path + name);
          }
          return Direction.NEXT;
        }
      });

      for (String dataFile : paths) {
        LocalMessageBucket bucket = m_buckets.get(dataFile);

        if (bucket != null) {
          MessageBlock block = bucket.flushBlock();

          if (block != null) {
            m_messageBlocks.offer(block);

            LockSupport.parkNanos(200 * 1000 * 1000L); // wait 50 ms
          }
          MessageTree tree = bucket.findByIndex(id.getIndex());

          if (tree != null && tree.getMessageId().equals(messageId)) {
            t.addData("path", dataFile);
            return tree;
          }
        } else {
          File file = new File(m_baseDir, dataFile);

          if (file.exists()) {
            try {
              bucket = (LocalMessageBucket) lookup(MessageBucket.class, LocalMessageBucket.ID);
              bucket.setBaseDir(m_baseDir);
              bucket.initialize(dataFile);

              MessageTree tree = bucket.findByIndex(id.getIndex());

              if (tree != null && tree.getMessageId().equals(messageId)) {
                t.addData("path", dataFile);
                return tree;
              }
            } catch (Exception e) {
              Cat.logError(e);
            } finally {
              bucket.close();
              release(bucket);
            }
          }
        }
      }

      return null;
    } catch (IOException e) {
      t.setStatus(e);
      cat.logError(e);
      throw e;
    } catch (RuntimeException e) {
      t.setStatus(e);
      cat.logError(e);
      throw e;
    } catch (Error e) {
      t.setStatus(e);
      cat.logError(e);
      throw e;
    } finally {
      t.complete();
    }
  }
View Full Code Here

TOP

Related Classes of com.dianping.cat.message.MessageProducer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.