Search in sources :

Example 36 with DeferredVoid

use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.

the class MyRadioProvider method shuffleStations.

@Override
public Promise<DeferredVoid> shuffleStations() {
    final DeferredVoid deferred = new DeferredVoid();
    // actions that take longer must be run in an appliction thread.
    // DO NOT block joynr threads
    executorService.schedule(new Runnable() {

        @Override
        public void run() {
            RadioStation oldStation = currentStation;
            currentStationIndex++;
            currentStationIndex = currentStationIndex % stationsList.size();
            currentStation = stationsList.get(currentStationIndex);
            currentStationChanged(currentStation);
            LOG.info(PRINT_BORDER + "shuffleStations: " + oldStation + " -> " + currentStation + PRINT_BORDER);
            deferred.resolve();
        }
    }, DELAY_MS, TimeUnit.MILLISECONDS);
    // Promise is returned immediately. Deferred is resolved later
    return new Promise<DeferredVoid>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid) RadioStation(joynr.vehicle.RadioStation)

Example 37 with DeferredVoid

use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.

the class CapabilitiesDirectoryImpl method touch.

@Override
public Promise<DeferredVoid> touch(String clusterControllerId) {
    DeferredVoid deferred = new DeferredVoid();
    discoveryEntryStore.touch(clusterControllerId);
    deferred.resolve();
    return new Promise<DeferredVoid>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid)

Example 38 with DeferredVoid

use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.

the class CapabilitiesDirectoryImpl method remove.

@Override
public Promise<DeferredVoid> remove(String[] participantIds) {
    DeferredVoid deferred = new DeferredVoid();
    discoveryEntryStore.remove(Arrays.asList(participantIds));
    deferred.resolve();
    return new Promise<DeferredVoid>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid)

Example 39 with DeferredVoid

use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryTest method addGlobalCapFails_NextAddShallAddGlobalAgain.

@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void addGlobalCapFails_NextAddShallAddGlobalAgain() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.GLOBAL);
    String participantId = LocalCapabilitiesDirectoryTest.class.getName() + ".addLocalAndThanGlobalShallWork";
    String domain = "testDomain";
    final DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
    Mockito.doAnswer(createAddAnswerWithError()).when(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
    Promise<DeferredVoid> promise = localCapabilitiesDirectory.add(discoveryEntry);
    promise.then(new PromiseListener() {

        @Override
        public void onFulfillment(Object... values) {
            verify(globalDiscoveryEntryCacheMock, never()).add(eq(globalDiscoveryEntry));
            verify(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
            reset(globalCapabilitiesClient);
            localCapabilitiesDirectory.add(discoveryEntry);
            verify(globalCapabilitiesClient, timeout(200)).add(any(Callback.class), eq(globalDiscoveryEntry));
        }

        @Override
        public void onRejection(JoynrException error) {
        }
    });
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) PromiseListener(io.joynr.provider.PromiseListener) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) JoynrException(io.joynr.exceptions.JoynrException) Matchers.anyString(org.mockito.Matchers.anyString) DeferredVoid(io.joynr.provider.DeferredVoid) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 40 with DeferredVoid

use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryImpl method add.

/**
 * Adds local capability to local and (depending on SCOPE) the global directory
 */
@Override
public Promise<DeferredVoid> add(final DiscoveryEntry discoveryEntry) {
    final DeferredVoid deferred = new DeferredVoid();
    if (localDiscoveryEntryStore.hasDiscoveryEntry(discoveryEntry)) {
        if (discoveryEntry.getQos().getScope().equals(ProviderScope.LOCAL) || globalDiscoveryEntryCache.lookup(discoveryEntry.getParticipantId(), DiscoveryQos.NO_MAX_AGE) != null) {
            // in this case, no further need for global registration is required. Registration completed.
            deferred.resolve();
            return new Promise<>(deferred);
        }
    // in the other case, the global registration needs to be done
    } else {
        localDiscoveryEntryStore.add(discoveryEntry);
        notifyCapabilityAdded(discoveryEntry);
    }
    if (discoveryEntry.getQos().getScope().equals(ProviderScope.GLOBAL)) {
        registerGlobal(discoveryEntry, deferred);
    } else {
        deferred.resolve();
    }
    return new Promise<>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DeferredVoid(io.joynr.provider.DeferredVoid)

Aggregations

DeferredVoid (io.joynr.provider.DeferredVoid)41 Promise (io.joynr.provider.Promise)36 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)7 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)5 MapStringString (joynr.interlanguagetest.namedTypeCollection2.MapStringString)4 JoynrException (io.joynr.exceptions.JoynrException)3 Deferred (io.joynr.provider.Deferred)2 PromiseListener (io.joynr.provider.PromiseListener)2 ApplicationException (joynr.exceptions.ApplicationException)2 StructWithStringArray (joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray)2 DiscoveryEntry (joynr.types.DiscoveryEntry)2 AbstractModule (com.google.inject.AbstractModule)1 TypeLiteral (com.google.inject.TypeLiteral)1 GlobalDiscoveryEntryPersisted (io.joynr.capabilities.GlobalDiscoveryEntryPersisted)1 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)1 JoynrMessageScopeModule (io.joynr.context.JoynrMessageScopeModule)1 MultiReturnValuesContainer (io.joynr.dispatcher.rpc.MultiReturnValuesContainer)1 RequestCaller (io.joynr.dispatching.RequestCaller)1 RequestCallerFactory (io.joynr.dispatching.RequestCallerFactory)1 RequestInterpreter (io.joynr.dispatching.rpc.RequestInterpreter)1