Search in sources :

Example 1 with GlobalDiscoveryEntryPersisted

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);
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntryPersisted(io.joynr.capabilities.GlobalDiscoveryEntryPersisted)

Example 2 with GlobalDiscoveryEntryPersisted

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);
    }
}
Also used : GlobalDiscoveryEntryPersisted(io.joynr.capabilities.GlobalDiscoveryEntryPersisted)

Example 3 with GlobalDiscoveryEntryPersisted

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());
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntryPersisted(io.joynr.capabilities.GlobalDiscoveryEntryPersisted) Test(org.junit.Test)

Example 4 with GlobalDiscoveryEntryPersisted

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;
}
Also used : Promise(io.joynr.provider.Promise) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) DeferredVoid(io.joynr.provider.DeferredVoid) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) GlobalDiscoveryEntryPersisted(io.joynr.capabilities.GlobalDiscoveryEntryPersisted) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Example 5 with GlobalDiscoveryEntryPersisted

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);
    }
}
Also used : ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) GlobalDiscoveryEntryPersisted(io.joynr.capabilities.GlobalDiscoveryEntryPersisted) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Aggregations

GlobalDiscoveryEntryPersisted (io.joynr.capabilities.GlobalDiscoveryEntryPersisted)6 Address (joynr.system.RoutingTypes.Address)2 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)2 MqttAddress (joynr.system.RoutingTypes.MqttAddress)2 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)2 Test (org.junit.Test)2 DeferredVoid (io.joynr.provider.DeferredVoid)1 Promise (io.joynr.provider.Promise)1 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)1