コード例 #1
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 public Handler getHandler(String name) {
   for (Handler handler : getHandlers()) {
     if (handler.getName().equals(name)) {
       return handler;
     }
   }
   return null;
 }
コード例 #2
0
  @Test
  public void testPutAndRetrieve() throws Exception {
    // @formatter:off
    Injector injector =
        Guice.createInjector(
            ClickWatchModuleUtil.newBuilder()
                .wClickSocketImpl(getTestClickSocket())
                .wLogger(getTestLogger())
                .build(),
            ClickWatchRecorderModuleUtil.newBuilder()
                .wDataBaseAdapterClass(HBaseDataBaseAdapter.class)
                .wSaveRecordFileDuringRecord(false)
                .build());
    // @formatter:on

    IDataBaseAdapter dataBaseAdapter = injector.getInstance(IDataBaseAdapter.class);
    Record record = DatabaseBuilders.newRecordBuilder().withName("test").build();
    dataBaseAdapter.initialize(record, true);

    // test put
    Node node =
        ModelBuilders.newNodeBuilder().withINetAddress("localhost").withPort("7777").build();
    NanoClock clock = injector.getInstance(NanoClock.class);
    long latest = 0;
    for (int i = 0; i < 1000; i++) {
      latest = clock.currentTimeNanos();
      Handler handler =
          injector.getInstance(IValueAdapter.class).create("test.test", latest, "testValue");
      dataBaseAdapter.record(node, handler);
    }
    dataBaseAdapter.close();

    Thread.sleep(200);

    // test retrieve all
    Handler handler = ModelBuilders.newHandlerBuilder().withName("test.test").build();
    dataBaseAdapter.initialize(record, false);
    for (int tryies = 0; tryies < 23; tryies++) {
      Iterator<Handler> iterator = dataBaseAdapter.retrieve(node, handler);
      int i = 0;
      while (iterator.hasNext()) {
        Handler currentHandler = (Handler) iterator.next();
        Assert.assertEquals("testValue", currentHandler.getValue());
        i++;
      }
      Assert.assertEquals(1000, i);
    }
    dataBaseAdapter.close();

    Thread.sleep(200);

    // test retrieve one
    dataBaseAdapter.initialize(record, false);
    Handler currentHandler = dataBaseAdapter.retrieve(node, handler, latest);
    Assert.assertEquals("testValue", currentHandler.getValue());
    dataBaseAdapter.close();
  }
コード例 #3
0
 @Override
 public String getValue(String element, String handlerName) {
   initialize();
   Handler handler = node.getHandler(element + "/" + handlerName);
   if (!handler.getMixed().isEmpty()) {
     return ((String) handler.getMixed().getValue(0)).trim();
   } else {
     return "";
   }
 }
コード例 #4
0
 @Override
 public HandlerInfo[] getHandler(String elementPath) {
   initialize();
   String[] elementPathItems = elementPath.split("/");
   Element element = null;
   for (int i = 0; i < elementPathItems.length; i++) {
     if (element == null) {
       element = node.getElement(elementPathItems[i]);
     } else {
       element = element.getChild(elementPathItems[i]);
     }
     if (element == null) {
       return new HandlerInfo[] {};
     }
   }
   EList<Handler> handlers = element.getHandlers();
   HandlerInfo[] result = new HandlerInfo[handlers.size()];
   int i = 0;
   for (Handler handler : handlers) {
     result[i++] =
         new HandlerInfo(elementPath, handler.getName(), handler.isCanRead(), handler.isCanRead());
   }
   return result;
 }
コード例 #5
0
ファイル: Recorder.java プロジェクト: markus1978/clickwatch
 @Override
 public void handlerReceived(Handler handler) {
   latestTime = handler.getTimestamp();
   dataBaseAdapter.record(node, handler);
   recordedHandler++;
 }