use of com.robo4j.core.configuration.Configuration in project robo4j by Robo4J.
the class RaspistillUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
Map<String, String> parameters = new HashMap<>();
parameters.put(KEY_WIDTH, configuration.getString(KEY_WIDTH, "320"));
parameters.put(KEY_HEIGHT, configuration.getString(KEY_HEIGHT, "240"));
parameters.put(KEY_EXPOSURE, configuration.getString(KEY_EXPOSURE, "sport"));
parameters.put(KEY_BRIGHTNESS, configuration.getString(KEY_BRIGHTNESS, null));
parameters.put(KEY_SHARPNESS, configuration.getString(KEY_SHARPNESS, null));
parameters.put(KEY_CONTRAST, configuration.getString(KEY_CONTRAST, null));
parameters.put(KEY_TIMEOUT, configuration.getString(KEY_TIMEOUT, "1"));
parameters.put(KEY_TIMELAPSE, configuration.getString(KEY_TIMELAPSE, "100"));
parameters.put(KEY_ROTATION, configuration.getString(KEY_ROTATION, null));
//@formatter:off
cameraCommand = new StringBuilder().append(RaspistillUtils.RASPISTILL_COMMAND).append(Constants.UTF8_SPACE).append(parameters.entrySet().stream().filter(p -> Objects.nonNull(p.getValue())).map(e -> {
StringBuilder c = new StringBuilder();
if (RaspistillUtils.isOption(e.getKey())) {
return c.append(RaspistillUtils.getOption(e.getKey())).append(Constants.UTF8_SPACE).append(e.getValue()).toString();
}
return null;
}).filter(Objects::nonNull).collect(Collectors.joining(Constants.UTF8_SPACE))).append(Constants.UTF8_SPACE).append(DEFAULT_IMAGE_SETUP).toString();
SimpleLoggingUtil.print(getClass(), "cameraCommand:" + cameraCommand);
//@formatter:on
targetOut = configuration.getString("targetOut", null);
String tmpClient = configuration.getString("client", null);
if (tmpClient == null || targetOut == null) {
throw ConfigurationException.createMissingConfigNameException("targetOut, client");
}
storeTarget = configuration.getString("storeTarget", null);
try {
InetAddress inetAddress = InetAddress.getByName(tmpClient);
String clientPort = configuration.getString("clientPort", null);
client = clientPort == null ? inetAddress.getHostAddress() : inetAddress.getHostAddress().concat(":").concat(clientPort);
clientUri = configuration.getString("clientUri", Constants.EMPTY_STRING);
} catch (UnknownHostException e) {
SimpleLoggingUtil.error(getClass(), "unknown ip address", e);
throw ConfigurationException.createMissingConfigNameException("unknown ip address");
}
}
use of com.robo4j.core.configuration.Configuration in project robo4j by Robo4J.
the class HttpClientUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
setState(LifecycleState.UNINITIALIZED);
String confAddress = configuration.getString("address", null);
int confPort = configuration.getInteger("port", RoboHttpUtils._DEFAULT_PORT);
responseUnit = configuration.getString("responseUnit", null);
responseSize = configuration.getInteger("responseSize", null);
final Configuration targetUnits = configuration.getChildConfiguration(RoboHttpUtils.HTTP_TARGET_UNITS);
if (confAddress == null || targetUnits == null) {
throw ConfigurationException.createMissingConfigNameException("address, path, commands...");
}
address = new InetSocketAddress(confAddress, confPort);
setState(LifecycleState.INITIALIZED);
}
use of com.robo4j.core.configuration.Configuration in project robo4j by Robo4J.
the class HttpServerUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
setState(LifecycleState.UNINITIALIZED);
/* target is always initiated as the list */
target = Arrays.asList(configuration.getString("target", Constants.EMPTY_STRING).split(DELIMITER));
port = configuration.getInteger("port", _DEFAULT_PORT);
String packages = configuration.getString("packages", null);
if (validatePackages(packages)) {
CODEC_REGISTRY.scan(Thread.currentThread().getContextClassLoader(), packages.split(","));
}
//@formatter:off
final Configuration targetUnits = configuration.getChildConfiguration("targetUnits");
if (targetUnits == null) {
SimpleLoggingUtil.error(getClass(), "no targetUnits");
} else {
for (Iterator<String> it = targetUnits.getValueNames().iterator(); it.hasNext(); ) {
final String key = it.next();
final String value = targetUnits.getString(key, RoboHttpUtils._EMPTY_STRING);
HttpUriRegister.getInstance().addNote(key, value);
}
}
//@formatter:on
setState(LifecycleState.INITIALIZED);
}
use of com.robo4j.core.configuration.Configuration in project robo4j by Robo4J.
the class TestClientImageController method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
SimpleLoggingUtil.print(getClass(), "camera client init");
Map<String, String> parameters = new HashMap<>();
//64
parameters.put(KEY_WIDTH, configuration.getString(KEY_WIDTH, "320"));
//45
parameters.put(KEY_HEIGHT, configuration.getString(KEY_HEIGHT, "240"));
StringBuilder sb = new StringBuilder(RASPI_CAMERA).append(SPACE).append(parameters.entrySet().stream().map(e -> {
StringBuilder c = new StringBuilder();
if (raspistillProperties.containsKey(e.getKey())) {
return c.append(raspistillProperties.get(e.getKey())).append(SPACE).append(e.getValue()).toString();
}
return null;
}).filter(Objects::nonNull).collect(Collectors.joining(SPACE))).append(SPACE).append(DEFAULT_SETUP);
cameraCommand = sb.toString();
SimpleLoggingUtil.print(getClass(), "camera cameraCommand: " + cameraCommand);
targetOut = configuration.getString("targetOut", null);
String tmpClient = configuration.getString("client", null);
if (tmpClient == null || targetOut == null) {
throw ConfigurationException.createMissingConfigNameException("targetOut, client");
}
try {
InetAddress inetAddress = InetAddress.getByName(tmpClient);
String clientPort = configuration.getString("clientPort", null);
client = clientPort == null ? inetAddress.getHostAddress() : inetAddress.getHostAddress().concat(":").concat(clientPort);
clientUri = configuration.getString("clientUri", Constants.EMPTY_STRING);
} catch (UnknownHostException e) {
SimpleLoggingUtil.error(getClass(), "unknown ip address", e);
throw ConfigurationException.createMissingConfigNameException("unknown ip address");
}
}
use of com.robo4j.core.configuration.Configuration in project robo4j by Robo4J.
the class RoboUnitTests method testSystem.
@Test
public void testSystem() throws Exception {
RoboSystem system = new RoboSystem();
Assert.assertEquals(system.getState(), LifecycleState.UNINITIALIZED);
StringProducer producer = new StringProducer(system, "producer");
Configuration config = ConfigurationFactory.createEmptyConfiguration();
config.setString("target", "consumer");
producer.initialize(config);
StringConsumer consumer = new StringConsumer(system, "consumer");
system.addUnits(producer, consumer);
Assert.assertEquals(system.getState(), LifecycleState.UNINITIALIZED);
system.start();
Assert.assertTrue(system.getState() == LifecycleState.STARTING || system.getState() == LifecycleState.STARTED);
for (int i = 0; i < 10; i++) {
producer.sendRandomMessage();
}
system.shutdown();
Assert.assertEquals(10, consumer.getReceivedMessages().size());
}
Aggregations