예제 #1
0
  private void executeService(Context ctx, SERVICE service) {
    String ns = service.getNs();
    NSHandler handler = registry.lookup(ns);
    if (handler == null) {
      LOGGER.error("NS[" + ns + "] not found.");
      return;
    }

    handler.service(ctx, service);
  }
예제 #2
0
  public synchronized void startup() {
    if (hydra != null) {
      return;
    }

    if (registry.isEmpty()) {
      LOGGER.error("Not found NS handler was be registered");
      return;
    }

    HydraBuilder builder = new HydraBuilder();
    builder.bind(host).port(port).messageReceivedListener(this).threads(option.getThreads());
    hydra = builder.build();
    hydra.startup();
  }
/** Created by dempe on 14-6-12. */
public class BrowsingPagedetail extends BaseAction {

  private static Logger logger = Logger.getLogger(DailyReport.class);

  @Override
  public byte[] execute(ActionContext context, byte[] message, Map<String, List<String>> params) {
    String appkey = getParameter(params, "appkey");
    System.out.println("appkey:" + appkey);
    return sumDailyReport(appkey, params).toBytes();
  }

  /**
   * sum_daily report.
   *
   * <p><br>
   * url :
   * report?report_name=sum_daily&appkey=b5558eab134cf306fdcdc3a6746afa25&startDate=20140528&endDate=20140531
   *
   * @param _appkey
   * @return
   */
  private JSONArray sumDailyReport(String _appkey, Map<String, List<String>> params) {
    String _startDate = getParameter(params, "startDate");
    String _endDate = getParameter(params, "endDate");

    int _istartDate = Integer.parseInt(_startDate);
    int _iendDate = Integer.parseInt(_endDate);

    String _create_date = DateUtils.getDateRegx(_startDate, _endDate);

    String key = _appkey + Constants.SPLIT + _create_date;
    System.out.println(key);

    JSONArray jsonArray = new JSONArray();

    Jedis jedis = null;
    try {
      jedis = RedisUtil.getJedis();
      Set<String> hkeys = jedis.keys(key);
      Iterator<String> it = hkeys.iterator();
      Pipeline pipeline = jedis.pipelined();
      while (it.hasNext()) {
        JSON map = new JSON();
        String hkey = it.next();
        String[] cols = hkey.split(Constants.SPLIT);

        int createDate = Integer.parseInt(cols[1]);
        if (!(createDate >= _istartDate && createDate <= _iendDate)) {
          continue;
        }
        map.put("appkey", cols[0]);
        map.put("create_date", cols[1]);
        Response<List<String>> fieldValueResponse = pipeline.hmget(hkey, "run_num");
        pipeline.sync();
        List<String> fieldValues = fieldValueResponse.get();
        String run_num = fieldValues.get(0);
        map.put("run_num", run_num);
        jsonArray.add(map);
      }
    } finally {
      if (jedis != null) {
        RedisUtil.returnJedis(jedis);
      }
    }

    return jsonArray;
  }
}
예제 #4
0
public class Paladin implements MessageReceivedListener {
  private static final Logger LOGGER = Logger.getLogger(Paladin.class);
  private final NSRegistry registry = new NSRegistry();
  private final PaladinOption option = new PaladinOption();
  private final String host;
  private final int port;
  private Hydra hydra;

  public Paladin(String host, int port) {
    this.host = host;
    this.port = port;
  }

  public void setThreads(int threads) {
    option.setThreads(threads);
  }

  public void setPaladingSerializer(PaladinSerializer serializer) {
    this.option.setPaladinSerializer(serializer);
  }

  public void mappingNS(String packageName) throws Exception {
    option.setMappingNSPackage(packageName);
    registry.mappingPackage(packageName);
  }

  public synchronized void startup() {
    if (hydra != null) {
      return;
    }

    if (registry.isEmpty()) {
      LOGGER.error("Not found NS handler was be registered");
      return;
    }

    HydraBuilder builder = new HydraBuilder();
    builder.bind(host).port(port).messageReceivedListener(this).threads(option.getThreads());
    hydra = builder.build();
    hydra.startup();
  }

  public synchronized void shutdown() {
    if (hydra == null) {
      return;
    }
    hydra.shutdown();
    hydra = null;
  }

  private void executeService(Context ctx, SERVICE service) {
    String ns = service.getNs();
    NSHandler handler = registry.lookup(ns);
    if (handler == null) {
      LOGGER.error("NS[" + ns + "] not found.");
      return;
    }

    handler.service(ctx, service);
  }

  @Override
  public void onMessageReceived(Session session, Message message) {
    byte[] bytes = message.content();
    SERVICE service = this.option.getPaladinSerializer().decode(bytes);
    if (service == null) {
      return;
    }

    Context ctx = new Context(session, message, option.getPaladinSerializer());
    executeService(ctx, service);
  }
}