Tabnine Logo
JsonControlService
Code IndexAdd Tabnine to your IDE (free)

How to use
JsonControlService
in
org.apache.edgent.runtime.jsoncontrol

Best Java code snippets using org.apache.edgent.runtime.jsoncontrol.JsonControlService (Showing top 20 results out of 315)

origin: org.apache.edgent/edgent-runtime-jsoncontrol

/**
 * Handle a JSON control request.
 * 
 * The control action is executed directly
 * using the calling thread.
 * 
 * @param request the request
 * @return JSON response, JSON null if the request was not recognized.
 * @throws Exception on failure
 */
public JsonElement controlRequest(JsonObject request) throws Exception {
  if (request.has(OP_KEY))
    return controlOperation(request);
  return JsonNull.INSTANCE;
}
origin: org.apache.edgent/edgent-providers-iot

  /**
   * Submit the specified application previously registered
   * via {@link #registerTopology(String, BiConsumer) registerTopology}.
   * @param appName name of registered application
   * @param config See {@link #submit(Topology, JsonObject) submit}. May be null.
   * 
   * @throws Exception on failure starting applications.
   */
  private void submitApplication(String appName, JsonObject config) throws Exception {
   if (systemApps.contains(appName)) {
    throw new IllegalArgumentException("appName");
   }
   ApplicationServiceMXBean bean = getControlService().getControl(ApplicationServiceMXBean.TYPE,
     ApplicationService.ALIAS, ApplicationServiceMXBean.class);
   bean.submit(appName, config==null ? null : config.toString());
  }
}
origin: org.apache.edgent/edgent-runtime-jsoncontrol

@Override
public <T> String getControlId(String type, String alias, Class<T> controlInterface) {
  String controlId = getControlId(type, null, alias);
  return getControlMBean(controlId, controlInterface) != null ? controlId : null;
}
origin: apache/incubator-edgent

@Test
public void test1ArgString() throws Exception {
  JsonControlService control = new JsonControlService();
  assertNull(cb2.getDoneS());
  control.registerControl("myb", "1s", null, MyBean.class, cb1);
  control.registerControl("myb", "2s", null, MyBean.class, cb2);
  args.add(new JsonPrimitive("ABC"));       
  req.add(JsonControlService.ARGS_KEY, args);
  control.controlRequest(req);
  args.add(new JsonPrimitive("DEF"));       
  req.add(JsonControlService.ARGS_KEY, args);
  control.controlRequest(req);
origin: apache/incubator-edgent

@Test
//@Ignore("This test relies on an existing war in a given location ... need to refactor this")
public void testAppServiceJar() throws Exception {
  
  DirectProvider provider = new DirectProvider();
  
  JsonControlService control = new JsonControlService();
  provider.getServices().addService(ControlService.class, control);        
  AppService.createAndRegister(provider, provider);
  File testAppsJar = getServerJar();
  assertNotNull(testAppsJar);
  assertTrue(testAppsJar.exists());
  System.out.println("Using server jar at: " + testAppsJar.toString());
  URL testAppsJarURL = testAppsJar.toURI().toURL();
  JsonObject registerJar = newRegisterJarRequest(testAppsJarURL.toExternalForm());       
  JsonElement crr = control.controlRequest(registerJar);    
  assertTrue(crr.getAsBoolean());
  
  Thread.sleep(500);
  
  JsonObject submitAppTwo = newSubmitRequest("SecondJarApp");        
  crr = control.controlRequest(submitAppTwo);      
  assertTrue(crr.getAsBoolean());
  
  Thread.sleep(500);
}

origin: apache/incubator-edgent

final String type = request.get(TYPE_KEY).getAsString();
String alias = request.get(ALIAS_KEY).getAsString();
final String controlId = getControlId(type, null, alias);
Method method = findMethod(mbean.getControlInterface(), methodName, argumentCount);
executeMethod(method, mbean.getControl(), getArguments(method, args));
origin: org.apache.edgent/edgent-providers-iot

/**
 * Create application connects {@code edgentControl} device commands
 * to the control service.
 * 
 * Subscribes to device
 * commands of type {@link Commands#CONTROL_SERVICE}
 * and sends the payload into the JSON control service
 * to invoke the control operation.
 */
protected void createIotCommandToControlApp() {
     this.registerTopology(CONTROL_APP_NAME, (iotDevice, config) -> {
    TStream<JsonObject> controlCommands = iotDevice.commands(Commands.CONTROL_SERVICE);
    controlCommands.sink(cmd -> {                
      try {
        getControlService().controlRequest(cmd.getAsJsonObject(IotDevice.CMD_PAYLOAD));
      } catch (Exception re) {
        // If the command fails then don't stop this application,
        // just process the next command.
        LoggerFactory.getLogger(ControlService.class).error("Control request failed: {}", cmd, re);
      }
    });
  });
  systemApps.add(CONTROL_APP_NAME);
}

origin: org.apache.edgent/edgent-providers-direct

public DirectProvider() {
  this.services = new ServiceContainer();
  
  getServices().addService(ControlService.class, new JsonControlService());
}
origin: org.apache.edgent/edgent-runtime-jsoncontrol

/**
 * {@inheritDoc}
 * <P>
 * All control service MBeans must be valid according
 * to {@link Controls#isControlServiceMBean(Class)}.
 * </P>
 * 
 * @see Controls#isControlServiceMBean(Class)
 */
@Override
public synchronized <T> String registerControl(String type, String id, String alias, Class<T> controlInterface,
    T control) {
  if (!Controls.isControlServiceMBean(controlInterface))
    throw new IllegalArgumentException();
  
  final String controlId = getControlId(type, id, alias);
  if (mbeans.containsKey(controlId)) {
    logger.error("Control id: {} already exists", controlId);
    throw new IllegalStateException();
  }
  logger.trace("Register control id: {}", controlId);
  mbeans.put(controlId, new ControlMBean<T>(controlInterface, control));
  return controlId;
}
origin: apache/incubator-edgent

@Test
public void test1ArgInt() throws Exception {
  JsonControlService control = new JsonControlService();
  assertEquals(0, cb2.getDoneI());
  control.registerControl("myb", "1i", null, MyBean.class, cb1);
  control.registerControl("myb", "2i", null, MyBean.class, cb2);
  args.add(new JsonPrimitive(726));       
  req.add(JsonControlService.ARGS_KEY, args);
  control.controlRequest(req);
  args.add(new JsonPrimitive(2924));       
  req.add(JsonControlService.ARGS_KEY, args);
  control.controlRequest(req);
origin: apache/incubator-edgent

@Test
public void testAppService() throws Exception {
  
  DirectProvider provider = new DirectProvider();
  
  JsonControlService control = new JsonControlService();
  provider.getServices().addService(ControlService.class, control);        
  AppService.createAndRegister(provider, provider);
  
  IotTestApps.registerApplications(provider);       
  
  JsonObject submitAppOne = newSubmitRequest("AppOne");        
  JsonElement crr = control.controlRequest(submitAppOne);      
  assertTrue(crr.getAsBoolean());
}

origin: org.apache.edgent/edgent-runtime-jsoncontrol

final String type = request.get(TYPE_KEY).getAsString();
String alias = request.get(ALIAS_KEY).getAsString();
final String controlId = getControlId(type, null, alias);
Method method = findMethod(mbean.getControlInterface(), methodName, argumentCount);
executeMethod(method, mbean.getControl(), getArguments(method, args));
origin: apache/incubator-edgent

/**
 * Create application connects {@code edgentControl} device commands
 * to the control service.
 * 
 * Subscribes to device
 * commands of type {@link Commands#CONTROL_SERVICE}
 * and sends the payload into the JSON control service
 * to invoke the control operation.
 */
protected void createIotCommandToControlApp() {
     this.registerTopology(CONTROL_APP_NAME, (iotDevice, config) -> {
    TStream<JsonObject> controlCommands = iotDevice.commands(Commands.CONTROL_SERVICE);
    controlCommands.sink(cmd -> {                
      try {
        getControlService().controlRequest(cmd.getAsJsonObject(IotDevice.CMD_PAYLOAD));
      } catch (Exception re) {
        // If the command fails then don't stop this application,
        // just process the next command.
        LoggerFactory.getLogger(ControlService.class).error("Control request failed: {}", cmd, re);
      }
    });
  });
  systemApps.add(CONTROL_APP_NAME);
}

origin: apache/incubator-edgent

public DirectProvider() {
  this.services = new ServiceContainer();
  
  getServices().addService(ControlService.class, new JsonControlService());
}
origin: apache/incubator-edgent

/**
 * {@inheritDoc}
 * <P>
 * All control service MBeans must be valid according
 * to {@link Controls#isControlServiceMBean(Class)}.
 * </P>
 * 
 * @see Controls#isControlServiceMBean(Class)
 */
@Override
public synchronized <T> String registerControl(String type, String id, String alias, Class<T> controlInterface,
    T control) {
  if (!Controls.isControlServiceMBean(controlInterface))
    throw new IllegalArgumentException();
  
  final String controlId = getControlId(type, id, alias);
  if (mbeans.containsKey(controlId)) {
    logger.error("Control id: {} already exists", controlId);
    throw new IllegalStateException();
  }
  logger.trace("Register control id: {}", controlId);
  mbeans.put(controlId, new ControlMBean<T>(controlInterface, control));
  return controlId;
}
origin: apache/incubator-edgent

@Test
public void testNoArg() throws Exception {
  JsonControlService control = new JsonControlService();
  MyBeanImpl cb1 = new MyBeanImpl();
  MyBeanImpl cb2 = new MyBeanImpl();
  assertFalse(cb1.isDoneIt());
  assertFalse(cb2.isDoneIt());
  control.registerControl("myb", "1", null, MyBean.class, cb1);
  control.registerControl("myb", "2", null, MyBean.class, cb2);
  assertFalse(cb1.isDoneIt());
  assertFalse(cb2.isDoneIt());
  JsonObject req = new JsonObject();
  req.addProperty(JsonControlService.TYPE_KEY, "myb");
  req.addProperty(JsonControlService.ALIAS_KEY, "1");
  req.addProperty(JsonControlService.OP_KEY, "doIt");
  control.controlRequest(req);
  assertTrue(cb1.isDoneIt());
  assertFalse(cb2.isDoneIt());
  req = new JsonObject();
  req.addProperty(JsonControlService.TYPE_KEY, "myb");
  req.addProperty(JsonControlService.ALIAS_KEY, "2");
  req.addProperty(JsonControlService.OP_KEY, "doIt");
  control.controlRequest(req);
  assertTrue(cb1.isDoneIt());
  assertTrue(cb2.isDoneIt());
}
origin: apache/incubator-edgent

assertEquals(Job.State.RUNNING, jobMbean.getCurrentState());
jsc.controlRequest(closeJob);
origin: apache/incubator-edgent

@Override
public <T> String getControlId(String type, String alias, Class<T> controlInterface) {
  String controlId = getControlId(type, null, alias);
  return getControlMBean(controlId, controlInterface) != null ? controlId : null;
}
origin: apache/incubator-edgent

  /**
   * Submit the specified application previously registered
   * via {@link #registerTopology(String, BiConsumer) registerTopology}.
   * @param appName name of registered application
   * @param config See {@link #submit(Topology, JsonObject) submit}. May be null.
   * 
   * @throws Exception on failure starting applications.
   */
  private void submitApplication(String appName, JsonObject config) throws Exception {
   if (systemApps.contains(appName)) {
    throw new IllegalArgumentException("appName");
   }
   ApplicationServiceMXBean bean = getControlService().getControl(ApplicationServiceMXBean.TYPE,
     ApplicationService.ALIAS, ApplicationServiceMXBean.class);
   bean.submit(appName, config==null ? null : config.toString());
  }
}
origin: apache/incubator-edgent

/**
 * Handle a JSON control request.
 * 
 * The control action is executed directly
 * using the calling thread.
 * 
 * @param request the request
 * @return JSON response, JSON null if the request was not recognized.
 * @throws Exception on failure
 */
public JsonElement controlRequest(JsonObject request) throws Exception {
  if (request.has(OP_KEY))
    return controlOperation(request);
  return JsonNull.INSTANCE;
}
org.apache.edgent.runtime.jsoncontrolJsonControlService

Javadoc

Control service that accepts control instructions as JSON objects.
A JSON object representing a control request can be passed to #controlRequest(JsonObject) to invoke a control operation (method) on a registered MBean.

Most used methods

  • <init>
  • controlRequest
    Handle a JSON control request. The control action is executed directly using the calling thread.
  • controlOperation
    Handle a control operation. An operation maps to a void method.
  • executeMethod
  • findMethod
  • getArguments
  • getControl
  • getControlId
  • getControlMBean
  • registerControl
    All control service MBeans must be valid according to Controls#isControlServiceMBean(Class).

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getApplicationContext (Context)
  • getExternalFilesDir (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now