Ejemplo n.º 1
0
  @Test
  public void multi() {
    Pipeline p = jedis.pipelined();
    p.multi();
    Response<Long> r1 = p.hincrBy("a", "f1", -1);
    Response<Long> r2 = p.hincrBy("a", "f1", -2);
    Response<List<Object>> r3 = p.exec();
    List<Object> result = p.syncAndReturnAll();

    assertEquals(new Long(-1), r1.get());
    assertEquals(new Long(-3), r2.get());

    assertEquals(4, result.size());

    assertEquals("OK", result.get(0));
    assertEquals("QUEUED", result.get(1));
    assertEquals("QUEUED", result.get(2));

    // 4th result is a list with the results from the multi
    @SuppressWarnings("unchecked")
    List<Object> multiResult = (List<Object>) result.get(3);
    assertEquals(new Long(-1), multiResult.get(0));
    assertEquals(new Long(-3), multiResult.get(1));

    assertEquals(new Long(-1), r3.get().get(0));
    assertEquals(new Long(-3), r3.get().get(1));
  }
Ejemplo n.º 2
0
 @Test
 public void pipelineWithPubSub() {
   Pipeline pipelined = jedis.pipelined();
   Response<Long> p1 = pipelined.publish("foo", "bar");
   Response<Long> p2 = pipelined.publish("foo".getBytes(), "bar".getBytes());
   pipelined.sync();
   assertEquals(0, p1.get().longValue());
   assertEquals(0, p2.get().longValue());
 }
Ejemplo n.º 3
0
 @Test
 public void testDiscardInPipeline() {
   Pipeline pipeline = jedis.pipelined();
   pipeline.multi();
   pipeline.set("foo", "bar");
   Response<String> discard = pipeline.discard();
   Response<String> get = pipeline.get("foo");
   pipeline.sync();
   discard.get();
   get.get();
 }
Ejemplo n.º 4
0
 @Test
 public void canRetrieveUnsetKey() {
   ShardedJedisPipeline p = jedis.pipelined();
   Response<String> shouldNotExist = p.get(UUID.randomUUID().toString());
   p.sync();
   assertNull(shouldNotExist.get());
 }
Ejemplo n.º 5
0
  /**
   * 获取上传地址,每次调用缓存延长24小时
   *
   * @param uuid
   * @return
   * @throws IOException
   */
  public static String getUploadFilePath(String uuid) {
    Jedis jedis = getJedis();
    Response<String> pathResponse;
    try {
      String key = CacheConstants.Redis_String_PhotoPath + uuid;

      // if(true)return jedis.get(key);
      Pipeline p = jedis.pipelined();
      pathResponse = p.get(key);
      p.expire(key, CacheConstants.Redis_String_PhotoPath_Expire);
      p.sync();
      p.close();
      //		    List<Object> results = p.syncAndReturnAll();
      String path = pathResponse.get();
      if (path != null) return path;
      List list =
          nSimpleHibernateDao
              .createSqlQuery("select path from fp_photo_item where uuid='" + uuid + "'")
              .list();

      if (list != null && list.size() > 0) {
        path = (String) list.get(0);
        setUploadFilePath(uuid, path);
      } else { // 防止暴力查数据库
        setUploadFilePath(uuid, "");
      }
      return path;
    } catch (Exception e) {
      //// e.printStackTrace();
      throw e;
    } finally {
      if (jedis != null) jedis.close();
    }
  }
Ejemplo n.º 6
0
  @Test
  public void testEvalKeyAndArg() {
    String key = "test";
    String arg = "3";
    String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";

    Pipeline p = jedis.pipelined();
    p.set(key, "0");
    Response<String> result0 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
    p.incr(key);
    Response<String> result1 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
    Response<String> result2 = p.get(key);
    p.sync();

    assertNull(result0.get());
    assertNull(result1.get());
    assertEquals("13", result2.get());
  }
Ejemplo n.º 7
0
  @Test(expected = JedisDataException.class)
  public void pipelineResponseWithinPipeline() {
    jedis.set("string", "foo");

    ShardedJedisPipeline p = jedis.pipelined();
    Response<String> string = p.get("string");
    string.get();
    p.sync();
  }
Ejemplo n.º 8
0
  @Test
  public void pipelineResponseWithData() {
    jedis.zadd("zset", 1, "foo");

    Pipeline p = jedis.pipelined();
    Response<Double> score = p.zscore("zset", "foo");
    p.sync();

    assertNotNull(score.get());
  }
Ejemplo n.º 9
0
  @Test
  public void testEval() {
    String script = "return 'success!'";

    Pipeline p = jedis.pipelined();
    Response<String> result = p.eval(script);
    p.sync();

    assertEquals("success!", result.get());
  }
Ejemplo n.º 10
0
  @Test
  public void multiWithSync() {
    jedis.set("foo", "314");
    jedis.set("bar", "foo");
    jedis.set("hello", "world");
    Pipeline p = jedis.pipelined();
    Response<String> r1 = p.get("bar");
    p.multi();
    Response<String> r2 = p.get("foo");
    p.exec();
    Response<String> r3 = p.get("hello");
    p.sync();

    // before multi
    assertEquals("foo", r1.get());
    // It should be readable whether exec's response was built or not
    assertEquals("314", r2.get());
    // after multi
    assertEquals("world", r3.get());
  }
Ejemplo n.º 11
0
  @Test
  public void pipelineResponse() {
    jedis.set("string", "foo");
    jedis.lpush("list", "foo");
    jedis.hset("hash", "foo", "bar");
    jedis.zadd("zset", 1, "foo");
    jedis.sadd("set", "foo");
    jedis.setrange("setrange", 0, "0123456789");
    byte[] bytesForSetRange = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    jedis.setrange("setrangebytes".getBytes(), 0, bytesForSetRange);

    Pipeline p = jedis.pipelined();
    Response<String> string = p.get("string");
    Response<String> list = p.lpop("list");
    Response<String> hash = p.hget("hash", "foo");
    Response<Set<String>> zset = p.zrange("zset", 0, -1);
    Response<String> set = p.spop("set");
    Response<Boolean> blist = p.exists("list");
    Response<Double> zincrby = p.zincrby("zset", 1, "foo");
    Response<Long> zcard = p.zcard("zset");
    p.lpush("list", "bar");
    Response<List<String>> lrange = p.lrange("list", 0, -1);
    Response<Map<String, String>> hgetAll = p.hgetAll("hash");
    p.sadd("set", "foo");
    Response<Set<String>> smembers = p.smembers("set");
    Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0, -1);
    Response<String> getrange = p.getrange("setrange", 1, 3);
    Response<byte[]> getrangeBytes = p.getrange("setrangebytes".getBytes(), 6, 8);
    p.sync();

    assertEquals("foo", string.get());
    assertEquals("foo", list.get());
    assertEquals("bar", hash.get());
    assertEquals("foo", zset.get().iterator().next());
    assertEquals("foo", set.get());
    assertEquals(false, blist.get());
    assertEquals(Double.valueOf(2), zincrby.get());
    assertEquals(Long.valueOf(1), zcard.get());
    assertEquals(1, lrange.get().size());
    assertNotNull(hgetAll.get().get("foo"));
    assertEquals(1, smembers.get().size());
    assertEquals(1, zrangeWithScores.get().size());
    assertEquals("123", getrange.get());
    byte[] expectedGetRangeBytes = {6, 7, 8};
    assertArrayEquals(expectedGetRangeBytes, getrangeBytes.get());
  }
Ejemplo n.º 12
0
  @Test
  public void testEvalsha() {
    String script = "return 'success!'";
    String sha1 = jedis.scriptLoad(script);

    assertTrue(jedis.scriptExists(sha1));

    Pipeline p = jedis.pipelined();
    Response<String> result = p.evalsha(sha1);
    p.sync();

    assertEquals("success!", result.get());
  }
Ejemplo n.º 13
0
 @Test
 public void piplineWithError() {
   Pipeline p = jedis.pipelined();
   p.set("foo", "bar");
   Response<Set<String>> error = p.smembers("foo");
   Response<String> r = p.get("foo");
   p.sync();
   try {
     error.get();
     fail();
   } catch (JedisDataException e) {
     // that is fine we should be here
   }
   assertEquals(r.get(), "bar");
 }
Ejemplo n.º 14
0
 @Aop("redis")
 public List<TopicTag> fetchTopTags() {
   Set<String> names = jedis().zrevrangeByScore(RKEY_TOPIC_TAG_COUNT, Long.MAX_VALUE, 0, 0, 20);
   List<TopicTag> tags = new ArrayList<>();
   List<Response<Double>> tmps = new ArrayList<>();
   Pipeline pipe = jedis().pipelined();
   for (String name : names) {
     tmps.add(pipe.zscore(RKEY_TOPIC_TAG_COUNT, name));
     tags.add(new TopicTag(name, 0));
   }
   pipe.sync();
   Iterator<TopicTag> it = tags.iterator();
   for (Response<Double> response : tmps) {
     it.next().setCount(response.get().intValue());
   }
   return tags;
 }
Ejemplo n.º 15
0
 private void compareClassificationResults(
     OWLOntology ontology, OWLReasoner reasoner, Jedis resultStore, Jedis idReader)
     throws Exception {
   Set<OWLClass> classes = ontology.getClassesInSignature();
   Pipeline resultPipeline = resultStore.pipelined();
   double classCount = 0;
   int multiplier = 1;
   double totalCount = 0;
   for (OWLClass cl : classes) {
     classCount++;
     double classProgress = (classCount / classes.size()) * 100;
     Set<OWLClass> reasonerSuperclasses = reasoner.getSuperClasses(cl, false).getFlattened();
     // add cl itself to S(X) computed by reasoner. That is missing
     // in its result.
     reasonerSuperclasses.add(cl);
     // adding equivalent classes -- they are not considered if asked for superclasses
     Iterator<OWLClass> iterator = reasoner.getEquivalentClasses(cl).iterator();
     while (iterator.hasNext()) reasonerSuperclasses.add(iterator.next());
     String classToCheckID = conceptToID(cl.toString(), idReader);
     List<Response<Double>> responseList = new ArrayList<Response<Double>>();
     for (OWLClass scl : reasonerSuperclasses) {
       String key = conceptToID(scl.toString(), idReader);
       responseList.add(resultPipeline.zscore(key, classToCheckID));
     }
     resultPipeline.sync();
     double hitCount = 0;
     for (Response<Double> response : responseList) {
       if (response.get() != null) hitCount++;
     }
     totalCount += (hitCount / reasonerSuperclasses.size());
     if (classProgress >= (5 * multiplier)) {
       System.out.println(
           "% of no. of classes looked at: "
               + classProgress
               + "\tProgress %: "
               + (totalCount / classCount) * 100);
       multiplier++;
     }
   }
   double progress = totalCount / classes.size();
   System.out.println("\nProgress %: " + (progress * 100));
 }
Ejemplo n.º 16
0
  @Test
  public void pipelineResponse() {
    jedis.set("string", "foo");
    jedis.lpush("list", "foo");
    jedis.hset("hash", "foo", "bar");
    jedis.zadd("zset", 1, "foo");
    jedis.sadd("set", "foo");

    ShardedJedisPipeline p = jedis.pipelined();
    Response<String> string = p.get("string");
    Response<String> list = p.lpop("list");
    Response<String> hash = p.hget("hash", "foo");
    Response<Set<String>> zset = p.zrange("zset", 0, -1);
    Response<String> set = p.spop("set");
    Response<Boolean> blist = p.exists("list");
    Response<Double> zincrby = p.zincrby("zset", 1, "foo");
    Response<Long> zcard = p.zcard("zset");
    p.lpush("list", "bar");
    Response<List<String>> lrange = p.lrange("list", 0, -1);
    Response<Map<String, String>> hgetAll = p.hgetAll("hash");
    p.sadd("set", "foo");
    Response<Set<String>> smembers = p.smembers("set");
    Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0, -1);
    p.sync();

    assertEquals("foo", string.get());
    assertEquals("foo", list.get());
    assertEquals("bar", hash.get());
    assertEquals("foo", zset.get().iterator().next());
    assertEquals("foo", set.get());
    assertFalse(blist.get());
    assertEquals(new Double(2), zincrby.get());
    assertEquals(new Long(1), zcard.get());
    assertEquals(1, lrange.get().size());
    assertNotNull(hgetAll.get().get("foo"));
    assertEquals(1, smembers.get().size());
    assertEquals(1, zrangeWithScores.get().size());
  }
  /*WARNING: everything related to matlab should be taken carefully, except for return value from function method any
  other matlab array object such as from new should be disposed explicitly. And set method of matlab array normally
  copy the element especially the element is a matlab array! If these array are not explicitly disposed they will
  not be collected by GC either thus your memory will be drained very quickly!!*/
  @Override
  public int runTask(String caseid, List<String> zoneids, String taskName) throws TException {
    int retcode = 0;
    String field = SeUtils.MW.WORKER.STRUCT_ARRAY_VALUE_FIELD;
    try (Jedis jedis = jedisPool.getResource()) {
      jedis.auth(pass);
      for (String zoneid : zoneids) {
        if (!jedis.exists(mkByteKey(caseid, SeUtils.REDIS.KEYS.ZONES, zoneid))) {
          retcode = -2;
        }
      }
      if (retcode >= 0) {
        Pipeline p = jedis.pipelined();
        Response<String> tol =
            p.hget(mkKey(caseid, SeUtils.REDIS.KEYS.OPTIONS_EST), SeUtils.OPTIONS.KEYS.OPT_EST_TOL);
        p.sync();
        double toldbl = Double.parseDouble(tol.get());
        int nz = zoneids.size();
        if (taskName.equals(SeUtils.MW.WORKER.ESTIMATE_TASK)) {
          List<Response<byte[]>> zoneDataByteList = new ArrayList<>();
          List<Response<byte[]>> HHByteList = new ArrayList<>();
          List<Response<byte[]>> WWInvByteList = new ArrayList<>();
          List<Response<byte[]>> ddelzByteList = new ArrayList<>();
          List<Response<byte[]>> vvByteList = new ArrayList<>();

          List<Response<List<String>>> busIdsList = new ArrayList<>();
          List<Response<List<String>>> outBusIdsList = new ArrayList<>();
          List<Response<List<String>>> brIdsList = new ArrayList<>();

          for (int i = 0; i < nz; i++) {
            String zoneid = zoneids.get(i);

            byte[] HHkey = mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE_HH);
            byte[] WWInvKey = mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE_WWINV);
            byte[] ddelzKey = mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE_DDELZ);
            byte[] vvKey =
                mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE, SeUtils.REDIS.KEYS.STATE_VV);
            byte[] zoneDataKey = mkByteKey(caseid, SeUtils.REDIS.KEYS.ZONES, zoneid);

            zoneDataByteList.add(p.get(zoneDataKey));
            HHByteList.add(p.get(HHkey));
            WWInvByteList.add(p.get(WWInvKey));
            ddelzByteList.add(p.get(ddelzKey));
            vvByteList.add(p.get(vvKey));

            String busIdsKey =
                mkKey(caseid, SeUtils.REDIS.KEYS.ZONES, zoneid, SeUtils.REDIS.KEYS.BUS_NUM_OUT);
            String outBusIdsKey =
                mkKey(caseid, SeUtils.REDIS.KEYS.ZONES, zoneid, SeUtils.REDIS.KEYS.OUT_BUS_NUM_OUT);
            String brIdsKey =
                mkKey(caseid, SeUtils.REDIS.KEYS.ZONES, zoneid, SeUtils.REDIS.KEYS.BRANCH_IDS);

            busIdsList.add(p.lrange(busIdsKey, 0, -1));
            outBusIdsList.add(p.lrange(outBusIdsKey, 0, -1));
            brIdsList.add(p.lrange(brIdsKey, 0, -1));
          }

          p.sync();

          String[] fields = {field};
          MWStructArray zonesData = new MWStructArray(nz, 1, fields);
          MWStructArray HHsData = new MWStructArray(nz, 1, fields);
          MWStructArray WWInvsData = new MWStructArray(nz, 1, fields);
          MWStructArray ddelzsData = new MWStructArray(nz, 1, fields);
          MWStructArray vvsData = new MWStructArray(nz, 1, fields);
          MWArray zoneMat, HHMat, WWInvMat, ddelzMat, vvMat;
          for (int i = 0; i < nz; i++) {
            zoneMat = MWStructArray.deserialize(zoneDataByteList.get(i).get());
            zonesData.set(field, i + 1, zoneMat);
            HHMat = MWNumericArray.deserialize(HHByteList.get(i).get());
            HHsData.set(field, i + 1, HHMat);
            WWInvMat = MWNumericArray.deserialize(WWInvByteList.get(i).get());
            WWInvsData.set(field, i + 1, WWInvMat);
            ddelzMat = MWNumericArray.deserialize(ddelzByteList.get(i).get());
            ddelzsData.set(field, i + 1, ddelzMat);
            vvMat = MWNumericArray.deserialize(vvByteList.get(i).get());
            vvsData.set(field, i + 1, vvMat);
            disposeMatArrays(zoneMat, HHMat, WWInvMat, ddelzMat, vvMat);
          }

          //                get measurement and voltages
          List<Response<List<String>>> vaEstList = new ArrayList<>();
          List<Response<List<String>>> vmEstList = new ArrayList<>();
          List<Response<List<String>>> vaExtList = new ArrayList<>();
          List<Response<List<String>>> vmExtList = new ArrayList<>();

          List<Response<List<String>>> zpfList = new ArrayList<>();
          List<Response<List<String>>> zptList = new ArrayList<>();
          List<Response<List<String>>> zqfList = new ArrayList<>();
          List<Response<List<String>>> zqtList = new ArrayList<>();
          List<Response<List<String>>> pbusList = new ArrayList<>();
          List<Response<List<String>>> qbusList = new ArrayList<>();
          List<Response<List<String>>> vamList = new ArrayList<>();
          List<Response<List<String>>> vmmList = new ArrayList<>();

          for (int i = 0; i < nz; i++) {
            List<String> busIdsLst = busIdsList.get(i).get();
            List<String> outBusIdsLst = outBusIdsList.get(i).get();
            List<String> bridsLst = brIdsList.get(i).get();

            vaEstList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.VA_EST_HASH),
                    busIdsLst.toArray(new String[busIdsLst.size()])));
            vmEstList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.VM_EST_HASH),
                    busIdsLst.toArray(new String[busIdsLst.size()])));
            vaExtList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.VA_EST_HASH),
                    outBusIdsLst.toArray(new String[outBusIdsLst.size()])));
            vmExtList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.VM_EST_HASH),
                    outBusIdsLst.toArray(new String[outBusIdsLst.size()])));

            zpfList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.MEASURE, SeUtils.MEASURE.TYPE.PF),
                    bridsLst.toArray(new String[bridsLst.size()])));
            zptList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.MEASURE, SeUtils.MEASURE.TYPE.PT),
                    bridsLst.toArray(new String[bridsLst.size()])));
            zqfList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.MEASURE, SeUtils.MEASURE.TYPE.QF),
                    bridsLst.toArray(new String[bridsLst.size()])));
            zqtList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.MEASURE, SeUtils.MEASURE.TYPE.QT),
                    bridsLst.toArray(new String[bridsLst.size()])));
            pbusList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.MEASURE, SeUtils.MEASURE.TYPE.PBUS),
                    busIdsLst.toArray(new String[busIdsLst.size()])));
            qbusList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.MEASURE, SeUtils.MEASURE.TYPE.QBUS),
                    busIdsLst.toArray(new String[busIdsLst.size()])));
            vamList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.MEASURE, SeUtils.MEASURE.TYPE.VA),
                    busIdsLst.toArray(new String[busIdsLst.size()])));
            vmmList.add(
                p.hmget(
                    mkKey(caseid, SeUtils.REDIS.KEYS.MEASURE, SeUtils.MEASURE.TYPE.VM),
                    busIdsLst.toArray(new String[busIdsLst.size()])));
          }
          p.sync();

          MWStructArray vasEstData = new MWStructArray(nz, 1, fields);
          MWStructArray vmsEstData = new MWStructArray(nz, 1, fields);
          MWStructArray vasExtData = new MWStructArray(nz, 1, fields);
          MWStructArray vmsExtData = new MWStructArray(nz, 1, fields);
          MWStructArray zsData = new MWStructArray(nz, 1, fields);
          MWArray vaestMat, vmestMat, vaextMat, vmextMat, zMat;
          for (int i = 0; i < nz; i++) {
            vaestMat = new MWNumericArray(vaEstList.get(i).get().toArray(), MWClassID.DOUBLE);
            vmestMat = new MWNumericArray(vmEstList.get(i).get().toArray(), MWClassID.DOUBLE);
            vaextMat = new MWNumericArray(vaExtList.get(i).get().toArray(), MWClassID.DOUBLE);
            vmextMat = new MWNumericArray(vmExtList.get(i).get().toArray(), MWClassID.DOUBLE);

            vasEstData.set(field, i + 1, vaestMat);
            vmsEstData.set(field, i + 1, vmestMat);
            vasExtData.set(field, i + 1, vaextMat);
            vmsExtData.set(field, i + 1, vmextMat);

            List<String> z = new ArrayList<>();
            z.addAll(zpfList.get(i).get());
            z.addAll(zptList.get(i).get());
            z.addAll(pbusList.get(i).get());
            z.addAll(vamList.get(i).get());
            z.addAll(zqfList.get(i).get());
            z.addAll(zqtList.get(i).get());
            z.addAll(qbusList.get(i).get());
            z.addAll(vmmList.get(i).get());
            zMat = new MWNumericArray(z.toArray(), MWClassID.DOUBLE);
            zsData.set(field, i + 1, zMat);

            disposeMatArrays(vaestMat, vmestMat, vaextMat, vmextMat, zMat);
          }

          Object[] res = null;
          MWStructArray delz = null,
              normF = null,
              ddelz = null,
              VVa = null,
              VVm = null,
              step = null,
              success = null;

          try {
            res =
                estimator.api_estimateOnce_batch(
                    7,
                    HHsData,
                    WWInvsData,
                    ddelzsData,
                    vvsData,
                    vasEstData,
                    vmsEstData,
                    vasExtData,
                    vmsExtData,
                    zsData,
                    zonesData);
            disposeMatArrays(
                zonesData,
                zsData,
                vasEstData,
                vmsEstData,
                vasExtData,
                vmsExtData,
                HHsData,
                WWInvsData,
                ddelzsData,
                vvsData);
          } catch (MWException e) {
            e.printStackTrace();
          }

          if (res != null) {
            VVa = (MWStructArray) res[0];
            VVm = (MWStructArray) res[1];
            delz = (MWStructArray) res[2];
            ddelz = (MWStructArray) res[3];
            normF = (MWStructArray) res[4];
            step = (MWStructArray) res[5];
            success = (MWStructArray) res[6];

            if (!isSuccess(success)) {
              logger.warn(
                  "Case {} estimation not success, may be caused by too many bad data drops!",
                  caseid);
            }

            for (int i = 0; i < nz; i++) {
              List<String> busids = busIdsList.get(i).get();
              //                      update state
              MWNumericArray va = (MWNumericArray) VVa.getField(field, i + 1);
              MWNumericArray vm = (MWNumericArray) VVm.getField(field, i + 1);
              double[][] vaArr = (double[][]) va.toArray();
              double[][] vmArr = (double[][]) vm.toArray();
              Map<String, String> vaMap = new HashMap<>();
              Map<String, String> vmMap = new HashMap<>();
              for (int j = 0; j < busids.size(); j++) {
                vaMap.put(busids.get(j), String.valueOf(vaArr[j][0]));
                vmMap.put(busids.get(j), String.valueOf(vmArr[j][0]));
              }
              p.hmset(mkKey(caseid, SeUtils.REDIS.KEYS.VA_EST_BUFFER_HASH), vaMap);
              p.hmset(mkKey(caseid, SeUtils.REDIS.KEYS.VM_EST_BUFFER_HASH), vmMap);

              String zoneid = zoneids.get(i);
              MWNumericArray ddelzi = (MWNumericArray) ddelz.getField(field, i + 1);
              MWNumericArray delzi = (MWNumericArray) delz.getField(field, i + 1);
              p.set(mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE_DDELZ), ddelzi.serialize());
              p.set(
                  mkByteKey(
                      caseid, zoneid, SeUtils.REDIS.KEYS.STATE, SeUtils.REDIS.KEYS.STATE_DELZ),
                  delzi.serialize());
              //                estimated zones
              p.incr(mkKey(caseid, SeUtils.REDIS.KEYS.STATE_ESTIMATED_ZONES));
              //                iteration times
              //                TODO: record only one iteration number
              p.incr(mkKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE, SeUtils.REDIS.KEYS.STATE_IT));
              MWNumericArray stepimat = (MWNumericArray) step.getField(field, i + 1);
              double stepi = stepimat.getDouble();
              if (stepi < toldbl) {
                p.setbit(
                    mkKey(caseid, SeUtils.REDIS.KEYS.STATE_CONVERGED),
                    Long.parseLong(zoneid),
                    true);
              } else {
                p.setbit(
                    mkKey(caseid, SeUtils.REDIS.KEYS.STATE_CONVERGED),
                    Long.parseLong(zoneid),
                    false);
              }

              disposeMatArrays(va, vm, ddelzi, delzi, stepimat);
              //                debug
              //                        System.out.println("zone: " + zoneid + ";  step:" + stepi);
            }
            p.sync();
            disposeMatArrays(VVa, VVm, delz, ddelz, normF, success, step);
          }

        } else if (taskName.equals(SeUtils.MW.WORKER.BADRECOG_TASK)) {
          List<Response<byte[]>> WWByteList = new ArrayList<>();
          List<Response<byte[]>> HHByteList = new ArrayList<>();
          List<Response<byte[]>> WWInvByteList = new ArrayList<>();
          List<Response<byte[]>> ddelzByteList = new ArrayList<>();
          List<Response<byte[]>> vvByteList = new ArrayList<>();

          List<Response<String>> badthdList = new ArrayList<>();

          for (int i = 0; i < nz; i++) {
            String zoneid = zoneids.get(i);

            byte[] HHkey = mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE_HH);
            byte[] WWInvKey = mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE_WWINV);
            byte[] ddelzKey = mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE_DDELZ);
            byte[] vvKey =
                mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE, SeUtils.REDIS.KEYS.STATE_VV);
            byte[] WWKey = mkByteKey(caseid, zoneid, SeUtils.REDIS.KEYS.STATE_WW);

            WWByteList.add(p.get(WWKey));
            HHByteList.add(p.get(HHkey));
            WWInvByteList.add(p.get(WWInvKey));
            ddelzByteList.add(p.get(ddelzKey));
            vvByteList.add(p.get(vvKey));

            String thdKey =
                mkKey(
                    caseid,
                    SeUtils.REDIS.KEYS.ZONES,
                    zoneid,
                    SeUtils.REDIS.KEYS.BAD_RECOG_THRESHOLD);
            badthdList.add(p.get(thdKey));
          }

          p.sync();

          String[] fields = {field};
          MWStructArray WWsData = new MWStructArray(nz, 1, fields);
          MWStructArray HHsData = new MWStructArray(nz, 1, fields);
          MWStructArray WWInvsData = new MWStructArray(nz, 1, fields);
          MWStructArray ddelzsData = new MWStructArray(nz, 1, fields);
          MWStructArray vvsData = new MWStructArray(nz, 1, fields);
          MWStructArray badthdsData = new MWStructArray(nz, 1, fields);
          MWArray wwmat, hhmat, wwinvmat, ddelzmat, vvmat, badmat;
          for (int i = 0; i < nz; i++) {
            wwmat = MWNumericArray.deserialize(WWByteList.get(i).get());
            hhmat = MWNumericArray.deserialize(HHByteList.get(i).get());
            wwinvmat = MWNumericArray.deserialize(WWInvByteList.get(i).get());
            ddelzmat = MWNumericArray.deserialize(ddelzByteList.get(i).get());
            vvmat = MWNumericArray.deserialize(vvByteList.get(i).get());
            badmat = new MWNumericArray(badthdList.get(i).get(), MWClassID.DOUBLE);
            WWsData.set(field, i + 1, wwmat);
            HHsData.set(field, i + 1, hhmat);
            WWInvsData.set(field, i + 1, wwinvmat);
            ddelzsData.set(field, i + 1, ddelzmat);
            vvsData.set(field, i + 1, vvmat);
            badthdsData.set(field, i + 1, badmat);
            disposeMatArrays(wwmat, hhmat, wwinvmat, ddelzmat, vvmat, badmat);
          }

          MWStructArray vvNewMat = null, convergedMat = null;
          Object[] res = null;
          try {
            res =
                estimator.api_badDataRecognition_batch(
                    2, HHsData, WWsData, WWInvsData, vvsData, ddelzsData, badthdsData);
            disposeMatArrays(badthdsData, HHsData, WWInvsData, WWsData, ddelzsData);
          } catch (MWException e) {
            e.printStackTrace();
          }

          //            update state
          if (res != null) {
            vvNewMat = (MWStructArray) res[0];
            convergedMat = (MWStructArray) res[1];

            for (int i = 0; i < nz; i++) {
              byte[] vvKey =
                  mkByteKey(
                      caseid,
                      zoneids.get(i),
                      SeUtils.REDIS.KEYS.STATE,
                      SeUtils.REDIS.KEYS.STATE_VV);
              String convKey = mkKey(caseid, SeUtils.REDIS.KEYS.STATE_CONVERGED);
              MWNumericArray vviMat = (MWNumericArray) vvsData.getField(field, i + 1);
              MWNumericArray vvNewiMat = (MWNumericArray) vvNewMat.getField(field, i + 1);
              int nvvi = vviMat.getDimensions()[0];
              int nvvNewi = vvNewiMat.getDimensions()[0];

              if (nvvi != nvvNewi) {
                p.set(vvKey, vvNewiMat.serialize());
              }

              MWNumericArray convergediMat = (MWNumericArray) convergedMat.getField(field, i + 1);
              double converged = convergediMat.getDouble();
              if (!(converged < 0)) {
                p.setbit(convKey, Long.parseLong(zoneids.get(i)), false);
              }
              p.incr(mkKey(caseid, SeUtils.REDIS.KEYS.STATE_BADRECOG_ZONES));
              p.incr(
                  mkKey(
                      caseid,
                      zoneids.get(i),
                      SeUtils.REDIS.KEYS.STATE,
                      SeUtils.REDIS.KEYS.STATE_IBADREG));

              disposeMatArrays(vviMat, vvNewiMat, convergediMat);
            }

            p.sync();
            disposeMatArrays(vvsData, vvNewMat, convergedMat);
          }

        } else if (taskName.equals(testTask)) {
          p.set(testTask, System.currentTimeMillis() + "");
          p.sync();
          retcode = 10;
        } else {
          retcode = -3;
        }
      }
    }

    return retcode;
  }