use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.
the class KNXBinding method connectionEstablished.
/*
* (non-Javadoc)
*
* @see org.openhab.binding.knx.internal.connection.KNXConnectionListener#connectionEstablished()
*/
@Override
public void connectionEstablished() {
logger.trace("connectionEstablished() msg received. Initializing readable DPs.");
mKNXConnectionEstablished = true;
for (KNXBindingProvider knxProvider : providers) {
for (Datapoint datapoint : knxProvider.getReadableDatapoints()) {
mKNXBusReaderScheduler.readOnce(datapoint);
int autoRefreshTimeInSecs = knxProvider.getAutoRefreshTime(datapoint);
if (autoRefreshTimeInSecs > 0) {
if (!mKNXBusReaderScheduler.scheduleRead(datapoint, autoRefreshTimeInSecs)) {
logger.warn("Couldn't add to KNX bus reader scheduler (connectionEstablished, datapoint='{}')", datapoint);
}
}
}
}
}
use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.
the class KNXBusReaderScheduler method scheduleRead.
/**
* Schedules a <code>Datapoint</code> to be cyclicly read. When parameter
* <code>autoRefreshTimeInSecs</code> is 0 then calling ths method is equal
* to calling <link>readOnce</link>. This function will return true if the <code>Datapoint</code>
* was added or if it was already scheduled with an identical <code>autoRefreshTimeInSecs</code>.
*
* @param datapoint
* the <code>Datapoint</code> to be read
* @param autoRefreshTimeInSecs
* time in seconds specifying the reading cycle. 0 is equal to
* calling <link>readOnce</link>
* @return true if the Datapoint was scheduled for reading, false in all
* other cases
*/
public synchronized boolean scheduleRead(Datapoint datapoint, int autoRefreshTimeInSecs) {
if (datapoint == null) {
sLogger.error("Argument datapoint cannot be null");
return false;
}
if (autoRefreshTimeInSecs < 0) {
sLogger.error("AutoRefreshTimeInSecs must be >= 0 for datapoint '{}'", datapoint.getName());
return false;
}
if (autoRefreshTimeInSecs == 0) {
return readOnce(datapoint);
}
if (mReadQueue.size() > KNXConnection.getMaxRefreshQueueEntries()) {
sLogger.error("Maximum number of permissible reading queue entries reached ('{}'). Ignoring new entries.", KNXConnection.getMaxRefreshQueueEntries());
return false;
}
// Check if datapoint is already present in another list and if so, remove it
int oldListNumber = getAutoRefreshTimeInSecs(datapoint);
if (oldListNumber > 0) {
if (oldListNumber == autoRefreshTimeInSecs) {
sLogger.debug("Datapoint '{}' was already in auto refresh list {}", datapoint.getName(), autoRefreshTimeInSecs);
return true;
}
List<Datapoint> oldList = mScheduleMap.get(oldListNumber);
synchronized (oldList) {
sLogger.debug("Datapoint '{}' already present in different list: {}, removing", datapoint.getName(), oldListNumber);
for (Iterator<Datapoint> iterator = oldList.iterator(); iterator.hasNext(); ) {
Datapoint dp = iterator.next();
if (dp.toString().equals(datapoint.toString())) {
iterator.remove();
}
}
}
}
// Check if we have a list for autoRefreshTimeInSecs. If not create it.
if (!mScheduleMap.containsKey(autoRefreshTimeInSecs)) {
sLogger.debug("Creating auto refresh list: {}.", autoRefreshTimeInSecs);
mScheduleMap.put(autoRefreshTimeInSecs, new LinkedList<Datapoint>());
if (mIsRunning) {
// Start scheduled task for the new time
sLogger.debug("Starting auto refresh cycle {}", autoRefreshTimeInSecs);
mScheduledExecutorService.scheduleAtFixedRate(new AutoRefreshTask(autoRefreshTimeInSecs), autoRefreshTimeInSecs, autoRefreshTimeInSecs, TimeUnit.SECONDS);
}
}
// Add the datapoint to the list
List<Datapoint> dpList = mScheduleMap.get(autoRefreshTimeInSecs);
synchronized (dpList) {
sLogger.debug("Adding datapoint '{}' to auto refresh list {}.", datapoint.getName(), autoRefreshTimeInSecs);
return dpList.add(datapoint);
}
}
use of tuwien.auto.calimero.datapoint.Datapoint in project openhab1-addons by openhab.
the class KNXBusReaderSchedulerTest method testLargeNumberOfDPs.
@Test
public void testLargeNumberOfDPs() throws KNXFormatException {
kNXBindingAutoRefreshScheduler.start();
assertTrue(kNXBindingAutoRefreshScheduler.isRunning());
Datapoint datapoint = createDP("1.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 1));
datapoint = createDP("1.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 1));
datapoint = createDP("1.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 1));
datapoint = createDP("1.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 1));
datapoint = createDP("2.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 2));
datapoint = createDP("2.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 2));
datapoint = createDP("2.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 2));
datapoint = createDP("2.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 2));
datapoint = createDP("2.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 10));
datapoint = createDP("2.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 11));
datapoint = createDP("2.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 12));
datapoint = createDP("2.001");
assertTrue(kNXBindingAutoRefreshScheduler.scheduleRead(datapoint, 13));
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
e.printStackTrace();
}
kNXBindingAutoRefreshScheduler.clear();
kNXBindingAutoRefreshScheduler.stop();
assertFalse(kNXBindingAutoRefreshScheduler.isRunning());
}
Aggregations