use of io.joynr.capabilities.GlobalDiscoveryEntryPersisted in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryEjb method lookup.
@Override
public GlobalDiscoveryEntry lookup(String participantId) {
logger.debug("Looking up global discovery entry for participant ID {}", participantId);
GlobalDiscoveryEntryPersisted queryResult = entityManager.find(GlobalDiscoveryEntryPersisted.class, participantId);
logger.debug("Found entry {}", queryResult);
return queryResult == null ? null : new GlobalDiscoveryEntry(queryResult);
}
use of io.joynr.capabilities.GlobalDiscoveryEntryPersisted in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryEjb method touch.
@Override
public void touch(String clusterControllerId) {
logger.debug("Touch called. Updating discovery entries from cluster controller with id: " + clusterControllerId);
String queryString = "select gdep from GlobalDiscoveryEntryPersisted gdep where gdep.clusterControllerId = :clusterControllerId";
long now = System.currentTimeMillis();
TypedQuery<GlobalDiscoveryEntryPersisted> query = entityManager.createQuery(queryString, GlobalDiscoveryEntryPersisted.class);
query.setParameter("clusterControllerId", clusterControllerId);
for (GlobalDiscoveryEntryPersisted globalDiscoveryEntryPersisted : query.getResultList()) {
globalDiscoveryEntryPersisted.setLastSeenDateMs(now);
}
}
use of io.joynr.capabilities.GlobalDiscoveryEntryPersisted in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryEjbTest method testAddAndLookupSingleDiscoveryEntryByParticipantId.
@Test
public void testAddAndLookupSingleDiscoveryEntryByParticipantId() {
GlobalDiscoveryEntry resultBeforeAdd = subject.lookup(testParticpantId);
assertNull(resultBeforeAdd);
subject.add(testGlobalDiscoveryEntry);
entityManager.flush();
entityManager.clear();
GlobalDiscoveryEntry result = subject.lookup(testParticpantId);
assertNotNull(result);
assertTrue(result instanceof GlobalDiscoveryEntry);
assertFalse(result instanceof GlobalDiscoveryEntryPersisted);
GlobalDiscoveryEntry persisted = (GlobalDiscoveryEntry) result;
assertEquals(testGlobalDiscoveryEntry.getInterfaceName(), persisted.getInterfaceName());
assertEquals(testGlobalDiscoveryEntry.getDomain(), persisted.getDomain());
}
use of io.joynr.capabilities.GlobalDiscoveryEntryPersisted in project joynr by bmwcarit.
the class CapabilitiesDirectoryImpl method add.
@Override
public Promise<DeferredVoid> add(GlobalDiscoveryEntry globalDiscoveryEntry) {
DeferredVoid deferred = new DeferredVoid();
Promise<DeferredVoid> promise = new Promise<DeferredVoid>(deferred);
Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
String clusterControllerId;
if (address instanceof MqttAddress) {
clusterControllerId = ((MqttAddress) address).getTopic();
} else if (address instanceof ChannelAddress) {
clusterControllerId = ((ChannelAddress) address).getChannelId();
} else {
deferred.reject(new ProviderRuntimeException(""));
return promise;
}
GlobalDiscoveryEntryPersisted discoveryEntry = new GlobalDiscoveryEntryPersisted(globalDiscoveryEntry, clusterControllerId);
logger.debug("registered discovery entry: {}", discoveryEntry);
discoveryEntryStore.add(discoveryEntry);
deferred.resolve();
return promise;
}
use of io.joynr.capabilities.GlobalDiscoveryEntryPersisted in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryEjb method add.
@Override
public void add(GlobalDiscoveryEntry globalDiscoveryEntry) {
logger.debug("Adding global discovery entry {}", globalDiscoveryEntry);
Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
String clusterControllerId;
if (address instanceof MqttAddress) {
clusterControllerId = ((MqttAddress) address).getTopic();
} else if (address instanceof ChannelAddress) {
clusterControllerId = ((ChannelAddress) address).getChannelId();
} else {
clusterControllerId = String.valueOf(address);
}
GlobalDiscoveryEntryPersisted entity = new GlobalDiscoveryEntryPersisted(globalDiscoveryEntry, clusterControllerId);
GlobalDiscoveryEntryPersisted persisted = entityManager.find(GlobalDiscoveryEntryPersisted.class, entity.getParticipantId());
if (persisted == null) {
entityManager.persist(entity);
} else {
entityManager.merge(entity);
}
}
Aggregations