use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.
the class Plc4xNamespace method onDataItemsCreated.
@Override
public void onDataItemsCreated(List<DataItem> dataItems) {
for (DataItem item : dataItems) {
plc4xServer.addField(item);
if (plc4xServer.getDriverManager() == null) {
plc4xServer.removeField(item);
plc4xServer.setDriverManager(new PooledPlcDriverManager());
}
}
subscriptionModel.onDataItemsCreated(dataItems);
}
use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.
the class ScraperTest method real_stuff.
@Test
@Disabled
void real_stuff() throws InterruptedException {
PlcDriverManager driverManager = new PooledPlcDriverManager(pooledPlcConnectionFactory -> {
GenericKeyedObjectPoolConfig<PlcConnection> config = new GenericKeyedObjectPoolConfig<>();
config.setJmxEnabled(true);
config.setMaxWaitMillis(-1);
config.setMaxTotal(3);
config.setMinIdlePerKey(0);
config.setBlockWhenExhausted(true);
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
return new GenericKeyedObjectPool<>(pooledPlcConnectionFactory, config);
});
Scraper scraper = new ScraperImpl((j, a, m) -> {
}, driverManager, Arrays.asList(new ScrapeJobImpl("job1", 10, Collections.singletonMap("tim", CONN_STRING_TIM), Collections.singletonMap("distance", FIELD_STRING_TIM)), new ScrapeJobImpl("job2", 10, Collections.singletonMap("chris", CONN_STRING_CH), Collections.singletonMap("counter", FIELD_STRING_CH))));
Thread.sleep(30_000_000);
}
use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.
the class TriggeredScraperRunnerModbus method main.
/**
* testing of TriggeredScraper vs real device (Modbus)
*/
public static void main(String[] args) throws IOException, ScraperException {
ScraperConfiguration configuration = ScraperConfiguration.fromFile("plc4j/utils/scraper/src/test/resources/example_triggered_scraper_modbus.yml", ScraperConfigurationTriggeredImpl.class);
PlcDriverManager plcDriverManager = new PooledPlcDriverManager();
TriggeredScraperImpl scraper = new TriggeredScraperImpl(configuration, plcDriverManager, (j, a, m) -> {
LOGGER.info("Results from {}/{}: {}", j, a, m);
for (Map.Entry<String, Object> entry : m.entrySet()) {
for (Object object : (List<Object>) entry.getValue()) {
LOGGER.info("{}", object);
}
}
}, new TriggerCollectorImpl(plcDriverManager));
scraper.start();
}
use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.
the class ManualS7PlcDriverMT method simpleLoop.
// public static final String CONN_STRING = "s7://10.10.64.20/0/1";
// public static final String FIELD_STRING = "%DB3:DBD32:DINT";
@Test
public void simpleLoop() {
PlcDriverManager plcDriverManager = new PooledPlcDriverManager();
DescriptiveStatistics statistics = new DescriptiveStatistics();
for (int i = 1; i <= 1000; i++) {
double timeNs = runSingleRequest(plcDriverManager);
statistics.addValue(timeNs);
}
printStatistics(statistics);
}
use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.
the class ManualS7PlcDriverMT method scheduledCancellingLoop.
@ParameterizedTest
@MethodSource("periodAndRus")
public void scheduledCancellingLoop(int period, int numberOfRuns) throws InterruptedException, PlcConnectionException {
System.out.println("Starting iteration with period " + period + " and " + numberOfRuns + " runs.");
PlcDriverManager plcDriverManager = new PooledPlcDriverManager();
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
DescriptiveStatistics statistics = new DescriptiveStatistics();
AtomicInteger counter = new AtomicInteger(0);
// Warmup
plcDriverManager.getConnection(CONN_STRING);
Runnable iteration = new Runnable() {
@Override
public void run() {
// System.out.println("Setting a request / guard...");
CompletableFuture<Double> requestFuture = CompletableFuture.supplyAsync(() -> ManualS7PlcDriverMT.this.runSingleRequest(plcDriverManager));
executorService.schedule(() -> {
if (!requestFuture.isDone()) {
requestFuture.cancel(true);
System.out.print("!");
} else {
System.out.print(".");
try {
statistics.addValue(requestFuture.get());
} catch (InterruptedException | ExecutionException e) {
// do nothing...
}
}
if (counter.getAndIncrement() >= numberOfRuns) {
executorService.shutdown();
}
}, period, TimeUnit.MILLISECONDS);
}
};
executorService.scheduleAtFixedRate(iteration, 0, period, TimeUnit.MILLISECONDS);
executorService.awaitTermination(100, TimeUnit.SECONDS);
// Print statistics
ManualS7PlcDriverMT.this.printStatistics(statistics);
}
Aggregations