@Override
 @Before
 public void init() throws IncQueryBaseException {
   super.init();
   if (!navigationHelper.isInWildcardMode()) {
     navigationHelper.registerObservedTypes(
         Collections.singleton(SchoolPackage.eINSTANCE.getStudent()),
         Collections.singleton(EcorePackage.eINSTANCE.getEString()),
         Collections.singleton((EStructuralFeature) SchoolPackage.eINSTANCE.getStudent_Name()));
   }
   Set<EReference> refs = new HashSet<EReference>();
   refs.add(SchoolPackage.eINSTANCE.getStudent_FriendsWith());
   transitiveClosureHelper =
       IncQueryBaseFactory.getInstance()
           .createTransitiveClosureHelper(this.navigationHelper, refs);
   aStudent =
       (Student)
           navigationHelper.findByAttributeValue("Abel Hegedus").iterator().next().getEObject();
   bStudent =
       (Student)
           navigationHelper.findByAttributeValue("Gabor Bergmann").iterator().next().getEObject();
   cStudent =
       (Student)
           navigationHelper.findByAttributeValue("Zoltan Ujhelyi").iterator().next().getEObject();
 }
Пример #2
0
 /**
  * This is the constructor of the callback class. It got an IoTSystem from the MIDL created model
  * and use it to initialize the IncQuery Base Indexer.
  *
  * @param system
  */
 public Callback(IoTSystem system) {
   this.system = system;
   try {
     navigationHelper =
         IncQueryBaseFactory.getInstance().createNavigationHelper(this.system, true, null);
   } catch (IncQueryBaseException e) {
     LOGGER.error(e.getMessage());
   }
 }
Пример #3
0
  @Override
  public void messageArrived(String topic, MqttMessage message) {
    try {

      Stopwatch sw = Stopwatch.createStarted();

      String msg = new String(message.getPayload());
      JsonParser parser = new JsonParser();
      JsonObject object = parser.parse(msg).getAsJsonObject();

      // XXX: workaround for demo!!!!
      String sensorId = topic;
      String[] segments = topic.split("/");
      if (segments.length > 2) {
        sensorId = segments[1] + segments[2];
      }

      long elapsed = sw.elapsed(TimeUnit.MILLISECONDS);
      if (elapsed > 5) {
        System.out.println("Phase parse: " + elapsed);
      }
      sw.reset();

      // Use IncQuery Base Indexer to find the sensor
      Sensor selectedSensor =
          (Sensor) navigationHelper.findByAttributeValue(sensorId).iterator().next().getEObject();

      elapsed = sw.elapsed(TimeUnit.MILLISECONDS);
      if (elapsed > 10) {
        System.out.println("Phase indexer: " + elapsed);
      }

      Payload sensorPayload = selectedSensor.getLastReceivedPayload();

      NavigationHelper paramNavHelper =
          IncQueryBaseFactory.getInstance().createNavigationHelper(sensorPayload, true, null);
      // Get parameters from model using the JSON file content
      for (Entry<String, JsonElement> parameter : object.entrySet()) {
        // Use IncQuery Base Indexer to find parameter
        Set<Setting> settings = paramNavHelper.findByAttributeValue(parameter.getKey());
        if (settings.isEmpty()) continue;

        DataParameter paramValue = (DataParameter) settings.iterator().next().getEObject();
        // Get the parameter new value from the message
        JsonElement newValue = parameter.getValue();
        // Find parameter type, and set the new value
        if (paramValue.getType().equals("int")) {
          ((IntParameter) paramValue).setValue(newValue.getAsInt());
        } else if (paramValue.getType().equals("double")) {
          ((DoubleParameter) paramValue).setValue(newValue.getAsDouble());
        } else if (paramValue.getType().equals("string")) {
          ((StringParameter) paramValue).setValue(newValue.getAsString());
        } else if (paramValue.getType().equals("boolean")) {
          ((BooleanParameter) paramValue).setValue(newValue.getAsBoolean());
        } else if (paramValue.getType().equals("long")) {
          ((LongParameter) paramValue).setValue(newValue.getAsLong());
        }
      }

      elapsed = sw.elapsed(TimeUnit.MILLISECONDS);
      if (elapsed > 10) {
        System.out.println("Phase update: " + elapsed);
      }

    } catch (Exception e) {
      LOGGER.error(e.getMessage());
    }
  }