Search in sources :

Example 1 with SuppressWarnings

use of edu.umd.cs.findbugs.annotations.SuppressWarnings in project geode by apache.

the class BaseCommand method handleKVSingleton.

/**
   * Handles both RR and PR cases
   */
@SuppressWarnings(value = "NP_NULL_PARAM_DEREF", justification = "Null value handled in sendNewRegisterInterestResponseChunk()")
private static void handleKVSingleton(LocalRegion region, Object entryKey, boolean serializeValues, ServerConnection servConn) throws IOException {
    VersionedObjectList values = new VersionedObjectList(MAXIMUM_CHUNK_SIZE, true, region == null || region.getAttributes().getConcurrencyChecksEnabled(), serializeValues);
    if (region != null) {
        if (region.containsKey(entryKey) || region.containsTombstone(entryKey)) {
            VersionTagHolder versionHolder = createVersionTagHolder();
            ClientProxyMembershipID id = servConn == null ? null : servConn.getProxyID();
            // From Get70.getValueAndIsObject()
            Object data = region.get(entryKey, null, true, true, true, id, versionHolder, true);
            VersionTag vt = versionHolder.getVersionTag();
            updateValues(values, entryKey, data, vt);
        }
    }
    // Send the last chunk (the only chunk for individual and list keys)
    // always send it back, even if the list is of zero size.
    sendNewRegisterInterestResponseChunk(region, entryKey, values, true, servConn);
}
Also used : VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Example 2 with SuppressWarnings

use of edu.umd.cs.findbugs.annotations.SuppressWarnings in project joynr by bmwcarit.

the class MyRadioConsumerApplication method run.

@SuppressWarnings("checkstyle:methodlength")
@Override
public void run() {
    DiscoveryQos discoveryQos = new DiscoveryQos();
    // As soon as the arbitration QoS is set on the proxy builder, discovery of suitable providers
    // is triggered. If the discovery process does not find matching providers within the
    // arbitration timeout duration it will be terminated and you will get an arbitration exception.
    discoveryQos.setDiscoveryTimeoutMs(10000);
    discoveryQos.setDiscoveryScope(discoveryScope);
    // Provider entries in the global capabilities directory are cached locally. Discovery will
    // consider entries in this cache valid if they are younger as the max age of cached
    // providers as defined in the QoS. All valid entries will be processed by the arbitrator when searching
    // for and arbitrating the "best" matching provider.
    // NOTE: Valid cache entries might prevent triggering a lookup in the global capabilities
    // directory. Therefore, not all providers registered with the global capabilities
    // directory might be taken into account during arbitration.
    discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
    // The discovery process outputs a list of matching providers. The arbitration strategy then
    // chooses one or more of them to be used by the proxy.
    discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
    // The provider will maintain at least a minimum interval idle time in milliseconds between
    // successive notifications, even if on-change notifications are enabled and the value changes more
    // often. This prevents the consumer from being flooded by updated values. The filtering happens on
    // the provider's side, thus also preventing excessive network traffic.
    int minInterval_ms = 0;
    // The provider will send notifications every maximum interval in milliseconds, even if the value didn't
    // change. It will send notifications more often if on-change notifications are enabled,
    // the value changes more often, and the minimum interval QoS does not prevent it. The maximum interval
    // can thus be seen as a sort of heart beat.
    int maxInterval_ms = 10000;
    // The provider will send notifications until the end date is reached. The consumer will not receive any
    // notifications (neither value notifications nor missed publication notifications) after
    // this date.
    long validityMs = 60000;
    // If no notification was received within the last alert interval, a missed publication
    // notification will be raised.
    int alertAfterInterval_ms = 20000;
    // Notification messages will be sent with this time-to-live. If a notification message can not be
    // delivered within its TTL, it will be deleted from the system.
    // NOTE: If a notification message is not delivered due to an expired TTL, it might raise a
    // missed publication notification (depending on the value of the alert interval QoS).
    int publicationTtl_ms = 5000;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos();
    subscriptionQos.setMinIntervalMs(minInterval_ms).setMaxIntervalMs(maxInterval_ms).setValidityMs(validityMs);
    subscriptionQos.setAlertAfterIntervalMs(alertAfterInterval_ms).setPublicationTtlMs(publicationTtl_ms);
    ProxyBuilder<RadioProxy> proxyBuilder = runtime.getProxyBuilder(providerDomain, RadioProxy.class);
    try {
        // getting an attribute
        radioProxy = proxyBuilder.setMessagingQos(new MessagingQos()).setDiscoveryQos(discoveryQos).build();
        RadioStation currentStation = radioProxy.getCurrentStation();
        LOG.info(PRINT_BORDER + "ATTRIBUTE GET: current station: " + currentStation + PRINT_BORDER);
        // subscribe to an attribute
        subscriptionFutureCurrentStation = radioProxy.subscribeToCurrentStation(new AttributeSubscriptionAdapter<RadioStation>() {

            @Override
            public void onReceive(RadioStation value) {
                LOG.info(PRINT_BORDER + "ATTRIBUTE SUBSCRIPTION: current station: " + value + PRINT_BORDER);
            }

            @Override
            public void onError(JoynrRuntimeException error) {
                LOG.info(PRINT_BORDER + "ATTRIBUTE SUBSCRIPTION: " + error + PRINT_BORDER);
            }
        }, subscriptionQos);
        // broadcast subscription
        // The provider will send a notification whenever the value changes.
        MulticastSubscriptionQos weakSignalBroadcastSubscriptionQos;
        // The consumer will be subscribed to the multicast until the end date is reached, after which the
        // consumer will be automatically unsubscribed, and will not receive any further notifications
        // this date.
        long wsbValidityMs = 60 * 1000;
        weakSignalBroadcastSubscriptionQos = new MulticastSubscriptionQos();
        weakSignalBroadcastSubscriptionQos.setValidityMs(wsbValidityMs);
        weakSignalFuture = subscribeToWeakSignal(weakSignalBroadcastSubscriptionQos);
        // susbcribe to weak signal with partition "GERMANY"
        weakSignalWithPartitionFuture = subscribeToWeakSignal(weakSignalBroadcastSubscriptionQos, "GERMANY");
        // selective broadcast subscription
        OnChangeSubscriptionQos newStationDiscoveredBroadcastSubscriptionQos;
        int nsdbMinIntervalMs = 2 * 1000;
        long nsdbValidityMs = 180 * 1000;
        int nsdbPublicationTtlMs = 5 * 1000;
        newStationDiscoveredBroadcastSubscriptionQos = new OnChangeSubscriptionQos();
        newStationDiscoveredBroadcastSubscriptionQos.setMinIntervalMs(nsdbMinIntervalMs).setValidityMs(nsdbValidityMs).setPublicationTtlMs(nsdbPublicationTtlMs);
        NewStationDiscoveredBroadcastFilterParameters newStationDiscoveredBroadcastFilterParams = new NewStationDiscoveredBroadcastFilterParameters();
        newStationDiscoveredBroadcastFilterParams.setHasTrafficService("true");
        // Munich
        GeoPosition positionOfInterest = new GeoPosition(48.1351250, 11.5819810);
        String positionOfInterestJson = null;
        try {
            positionOfInterestJson = objectMapper.writeValueAsString(positionOfInterest);
        } catch (JsonProcessingException e1) {
            LOG.error("Unable to write position of interest filter parameter to JSON", e1);
        }
        newStationDiscoveredBroadcastFilterParams.setPositionOfInterest(positionOfInterestJson);
        // 200 km
        newStationDiscoveredBroadcastFilterParams.setRadiusOfInterestArea("200000");
        radioProxy.subscribeToNewStationDiscoveredBroadcast(new RadioBroadcastInterface.NewStationDiscoveredBroadcastAdapter() {

            @Override
            public void onReceive(RadioStation discoveredStation, GeoPosition geoPosition) {
                LOG.info(PRINT_BORDER + "BROADCAST SUBSCRIPTION: new station discovered: " + discoveredStation + " at " + geoPosition + PRINT_BORDER);
            }
        }, newStationDiscoveredBroadcastSubscriptionQos, newStationDiscoveredBroadcastFilterParams);
        boolean success;
        try {
            // add favorite radio station
            RadioStation favoriteStation = new RadioStation("99.3 The Fox Rocks", false, Country.CANADA);
            success = radioProxy.addFavoriteStation(favoriteStation);
            LOG.info(PRINT_BORDER + "METHOD: added favorite station: " + favoriteStation + ": " + success + PRINT_BORDER);
            success = radioProxy.addFavoriteStation(favoriteStation);
        } catch (ApplicationException exception) {
            AddFavoriteStationErrorEnum error = exception.getError();
            switch(error) {
                case DUPLICATE_RADIOSTATION:
                    LOG.info(PRINT_BORDER + "METHOD: addFavoriteStation failed with the following excpected error: " + error);
                    break;
                default:
                    LOG.error(PRINT_BORDER + "METHOD: addFavoriteStation failed with an unexpected error: " + error);
                    break;
            }
        }
        try {
            // add favorite radio station
            RadioStation favoriteStation = new RadioStation("", false, Country.GERMANY);
            success = radioProxy.addFavoriteStation(favoriteStation);
            LOG.info(PRINT_BORDER + "METHOD: addFavoriteStation completed unexpected with the following output: " + success);
        } catch (ApplicationException exception) {
            String errorName = exception.getError().name();
            LOG.info(PRINT_BORDER + "METHOD: addFavoriteStation failed with the following unexpected ApplicationExcecption: " + errorName);
        } catch (ProviderRuntimeException exception) {
            String errorName = exception.getMessage();
            String expectation = errorName.equals(MyRadioProvider.MISSING_NAME) ? "expected" : "unexpected";
            LOG.info(PRINT_BORDER + "METHOD: addFavoriteStation failed with the following " + expectation + " exception: " + errorName);
        }
        // shuffle the stations
        radioProxy.shuffleStations();
        currentStation = radioProxy.getCurrentStation();
        LOG.info(PRINT_BORDER + "The current radio station after shuffling is: " + currentStation + PRINT_BORDER);
        // add favorite radio station async
        RadioStation radioStation = new RadioStation("99.4 AFN", false, Country.GERMANY);
        Future<Boolean> future = radioProxy.addFavoriteStation(new CallbackWithModeledError<Boolean, AddFavoriteStationErrorEnum>() {

            @Override
            public void onSuccess(Boolean result) {
                LOG.info(PRINT_BORDER + "ASYNC METHOD: added favorite station: callback onSuccess" + PRINT_BORDER);
            }

            @Override
            public void onFailure(JoynrRuntimeException error) {
                LOG.info(PRINT_BORDER + "ASYNC METHOD: added favorite station: callback onFailure: " + error.getMessage() + PRINT_BORDER);
            }

            @Override
            public void onFailure(AddFavoriteStationErrorEnum errorEnum) {
                switch(errorEnum) {
                    case DUPLICATE_RADIOSTATION:
                        LOG.info(PRINT_BORDER + "ASYNC METHOD: added favorite station failed: Duplicate Station!" + PRINT_BORDER);
                        break;
                    default:
                        LOG.error(PRINT_BORDER + "ASYNC METHOD: added favorite station failed: unknown errorEnum:" + errorEnum + PRINT_BORDER);
                        break;
                }
                LOG.info(PRINT_BORDER + "ASYNC METHOD: added favorite station: callback onFailure: " + errorEnum + PRINT_BORDER);
            }
        }, radioStation);
        try {
            long timeoutInMilliseconds = 8000;
            Boolean reply = future.get(timeoutInMilliseconds);
            LOG.info(PRINT_BORDER + "ASYNC METHOD: added favorite station: " + radioStation + ": " + reply + PRINT_BORDER);
        } catch (InterruptedException | JoynrRuntimeException | ApplicationException e) {
            LOG.info(PRINT_BORDER + "ASYNC METHOD: added favorite station: " + radioStation + ": " + e.getClass().getSimpleName() + "!");
        }
        ConsoleReader console;
        try {
            console = new ConsoleReader();
            int key;
            while ((key = console.readCharacter()) != 'q') {
                switch(key) {
                    case 's':
                        radioProxy.shuffleStations();
                        LOG.info("called shuffleStations");
                        break;
                    case 'm':
                        GetLocationOfCurrentStationReturned locationOfCurrentStation = radioProxy.getLocationOfCurrentStation();
                        LOG.info("called getLocationOfCurrentStation. country: " + locationOfCurrentStation.country + ", location: " + locationOfCurrentStation.location);
                        break;
                    default:
                        LOG.info("\n\nUSAGE press\n" + " q\tto quit\n" + " s\tto shuffle stations\n");
                        break;
                }
            }
        } catch (IOException e) {
            LOG.error("error reading input from console", e);
        }
    } catch (DiscoveryException e) {
        LOG.error("No provider found", e);
    } catch (JoynrCommunicationException e) {
        LOG.error("The message was not sent: ", e);
    }
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) GetLocationOfCurrentStationReturned(joynr.vehicle.RadioSync.GetLocationOfCurrentStationReturned) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) RadioProxy(joynr.vehicle.RadioProxy) RadioStation(joynr.vehicle.RadioStation) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) RadioBroadcastInterface(joynr.vehicle.RadioBroadcastInterface) MessagingQos(io.joynr.messaging.MessagingQos) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) AddFavoriteStationErrorEnum(joynr.vehicle.Radio.AddFavoriteStationErrorEnum) NewStationDiscoveredBroadcastFilterParameters(joynr.vehicle.RadioBroadcastInterface.NewStationDiscoveredBroadcastFilterParameters) ApplicationException(joynr.exceptions.ApplicationException) GeoPosition(joynr.vehicle.GeoPosition) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Example 3 with SuppressWarnings

use of edu.umd.cs.findbugs.annotations.SuppressWarnings in project joynr by bmwcarit.

the class ConsumerApplication method run.

@SuppressWarnings("checkstyle:methodlength")
@Override
public void run() {
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryTimeoutMs(10000);
    discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
    discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
    ProxyBuilder<SystemIntegrationTestProxy> proxyBuilder = runtime.getProxyBuilder(providerDomain, SystemIntegrationTestProxy.class);
    boolean success = false;
    try {
        systemIntegrationTestProxy = proxyBuilder.setMessagingQos(new MessagingQos(10000)).setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<SystemIntegrationTestProxy>() {

            @Override
            public void onProxyCreationFinished(SystemIntegrationTestProxy result) {
                LOG.info("proxy created");
                proxyCreated.release();
            }

            @Override
            public void onProxyCreationError(JoynrRuntimeException error) {
                LOG.error("error creating proxy");
            }
        });
        try {
            if (proxyCreated.tryAcquire(11000, TimeUnit.MILLISECONDS) == false) {
                throw new DiscoveryException("proxy not created in time");
            }
        } catch (InterruptedException e) {
            throw new DiscoveryException("proxy not created in time");
        }
        try {
            int addendA = 3333333;
            int addendB = 4444444;
            Integer sum = systemIntegrationTestProxy.add(addendA, addendB);
            if (sum != null && sum == (addendA + addendB)) {
                LOG.info("SIT RESULT success: Java consumer -> " + providerDomain + " (" + addendA + " + " + addendB + " =  " + sum + ")");
                success = true;
            }
        } catch (Exception e) {
        // fallthrough
        }
    } catch (DiscoveryException | JoynrCommunicationException e) {
    // fallthrough
    }
    if (!success) {
        LOG.info("SIT RESULT error: Java consumer -> " + providerDomain);
    }
    System.exit((success) ? 0 : 1);
}
Also used : SystemIntegrationTestProxy(joynr.test.SystemIntegrationTestProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) DiscoveryException(io.joynr.exceptions.DiscoveryException) IOException(java.io.IOException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) MessagingQos(io.joynr.messaging.MessagingQos) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) DiscoveryException(io.joynr.exceptions.DiscoveryException) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Example 4 with SuppressWarnings

use of edu.umd.cs.findbugs.annotations.SuppressWarnings in project joynr by bmwcarit.

the class IltConsumerFilteredBroadcastSubscriptionTest method callSubscribeBroadcastWithFiltering.

@SuppressWarnings("checkstyle:methodlength")
@Test
public void callSubscribeBroadcastWithFiltering() {
    Future<String> subscriptionIdFuture;
    String subscriptionId;
    int minIntervalMs = 0;
    int maxIntervalMs = 10000;
    long validityMs = 60000;
    int alertAfterIntervalMs = 20000;
    int publicationTtlMs = 5000;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(minIntervalMs).setMaxIntervalMs(maxIntervalMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertAfterIntervalMs).setPublicationTtlMs(publicationTtlMs);
    boolean result;
    LOG.info(name.getMethodName() + "");
    try {
        BroadcastWithFilteringBroadcastFilterParameters filterParameters = new BroadcastWithFilteringBroadcastFilterParameters();
        String stringOfInterst = "fireBroadcast";
        filterParameters.setStringOfInterest(stringOfInterst);
        String[] stringArrayOfInterest = IltUtil.createStringArray();
        String json;
        try {
            LOG.info(name.getMethodName() + " - objectMapper is " + objectMapper);
            LOG.info(name.getMethodName() + " - objectMapper stringArrayOfInterest " + stringArrayOfInterest);
            json = objectMapper.writeValueAsString(stringArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing stringArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStringArrayOfInterest(json);
        ExtendedTypeCollectionEnumerationInTypeCollection enumerationOfInterest = ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION;
        try {
            json = objectMapper.writeValueAsString(enumerationOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing enumerationOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setEnumerationOfInterest(json);
        StructWithStringArray structWithStringArrayOfInterest = IltUtil.createStructWithStringArray();
        try {
            json = objectMapper.writeValueAsString(structWithStringArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing structWithStringArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStructWithStringArrayOfInterest(json);
        StructWithStringArray[] structWithStringArrayArrayOfInterest = IltUtil.createStructWithStringArrayArray();
        try {
            json = objectMapper.writeValueAsString(structWithStringArrayArrayOfInterest);
        } catch (JsonProcessingException je) {
            fail(name.getMethodName() + " - FAILED - got exception when serializing structWithStringArrayArrayOfInterest" + je.getMessage());
            return;
        }
        filterParameters.setStructWithStringArrayArrayOfInterest(json);
        subscriptionIdFuture = testInterfaceProxy.subscribeToBroadcastWithFilteringBroadcast(new BroadcastWithFilteringBroadcastAdapter() {

            @Override
            public void onReceive(String stringOut, String[] stringArrayOut, ExtendedTypeCollectionEnumerationInTypeCollection enumerationOut, StructWithStringArray structWithStringArrayOut, StructWithStringArray[] structWithStringArrayArrayOut) {
                LOG.info(name.getMethodName() + " - callback - got broadcast");
                if (!IltUtil.checkStringArray(stringArrayOut)) {
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (enumerationOut != ExtendedTypeCollectionEnumerationInTypeCollection.ENUM_2_VALUE_EXTENSION_FOR_TYPECOLLECTION) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (!IltUtil.checkStructWithStringArray(structWithStringArrayOut)) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else if (!IltUtil.checkStructWithStringArrayArray(structWithStringArrayArrayOut)) {
                    LOG.info(name.getMethodName() + " - callback - invalid content");
                    subscribeBroadcastWithFilteringCallbackResult = false;
                } else {
                    LOG.info(name.getMethodName() + " - callback - content OK");
                    subscribeBroadcastWithFilteringCallbackResult = true;
                }
                subscribeBroadcastWithFilteringCallbackDone = true;
            }

            @Override
            public void onError(SubscriptionException error) {
                LOG.info(name.getMethodName() + " - callback - error");
                subscribeBroadcastWithFilteringCallbackResult = false;
                subscribeBroadcastWithFilteringCallbackDone = true;
            }
        }, subscriptionQos, filterParameters);
        subscriptionId = subscriptionIdFuture.get(10000);
        LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
        LOG.info(name.getMethodName() + " - Waiting one second");
        Thread.sleep(1000);
        LOG.info(name.getMethodName() + " - Wait done, invoking fire method");
        String stringArg = "fireBroadcast";
        testInterfaceProxy.methodToFireBroadcastWithFiltering(stringArg);
        LOG.info(name.getMethodName() + " - fire method invoked");
        // should have been called ahead anyway
        if (subscribeBroadcastWithFilteringCallbackDone == false) {
            LOG.info(name.getMethodName() + " - about to wait for a second for callback");
            Thread.sleep(1000);
            LOG.info(name.getMethodName() + " - wait for callback is over");
        } else {
            LOG.info(name.getMethodName() + " - callback already done");
        }
        if (!subscribeBroadcastWithFilteringCallbackDone) {
            fail(name.getMethodName() + " - FAILED - callback did not get called in time");
            result = false;
        } else if (subscribeBroadcastWithFilteringCallbackResult) {
            LOG.info(name.getMethodName() + " - callback got called and received expected publication");
            result = true;
        } else {
            fail(name.getMethodName() + " - FAILED - callback got called but received unexpected error or publication content");
            result = false;
        }
        // get out, if first test run failed
        if (result == false) {
            return;
        }
        // reset counter for 2nd test
        subscribeBroadcastWithFilteringCallbackResult = false;
        subscribeBroadcastWithFilteringCallbackDone = false;
        LOG.info(name.getMethodName() + " - invoking fire method with wrong stringArg");
        stringArg = "doNotfireBroadcast";
        testInterfaceProxy.methodToFireBroadcastWithFiltering(stringArg);
        LOG.info(name.getMethodName() + " - fire method invoked");
        // should have been called ahead anyway
        if (subscribeBroadcastWithFilteringCallbackDone == false) {
            LOG.info(name.getMethodName() + " - about to wait for a second for callback");
            Thread.sleep(1000);
            LOG.info(name.getMethodName() + " - wait for callback is over");
        } else {
            LOG.info(name.getMethodName() + " - callback already done");
        }
        if (!subscribeBroadcastWithFilteringCallbackDone) {
            LOG.info(name.getMethodName() + " - callback did not get called in time (expected)");
            result = true;
        } else {
            fail(name.getMethodName() + " - FAILED - callback got called unexpectedly");
            result = false;
        }
        // try to unsubscribe
        try {
            testInterfaceProxy.unsubscribeFromBroadcastWithFilteringBroadcast(subscriptionId);
            LOG.info(name.getMethodName() + " - unsubscribe successful");
        } catch (Exception e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception on unsubscribe: " + e.getMessage());
            result = false;
        }
        if (!result) {
            LOG.info(name.getMethodName() + " - FAILED");
        } else {
            LOG.info(name.getMethodName() + " - OK");
        }
        return;
    } catch (Exception e) {
        // also catches InterruptedException from Thread.sleep() call
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        e.printStackTrace(printWriter);
        printWriter.flush();
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + stringWriter.toString());
        return;
    }
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) BroadcastWithFilteringBroadcastAdapter(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithFilteringBroadcastAdapter) ExtendedTypeCollectionEnumerationInTypeCollection(joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StringWriter(java.io.StringWriter) StructWithStringArray(joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray) BroadcastWithFilteringBroadcastFilterParameters(joynr.interlanguagetest.TestInterfaceBroadcastInterface.BroadcastWithFilteringBroadcastFilterParameters) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Example 5 with SuppressWarnings

use of edu.umd.cs.findbugs.annotations.SuppressWarnings in project st-js by st-js.

the class NodeJSExecutor method run.

/**
 * <p>run.</p>
 *
 * @param srcFile a {@link java.io.File} object.
 * @return a {@link org.stjs.generator.executor.ExecutionResult} object.
 */
@SuppressWarnings(value = "REC_CATCH_EXCEPTION")
public ExecutionResult run(File srcFile) {
    try {
        Process p = Runtime.getRuntime().exec(new String[] { NODE_JS, srcFile.getAbsolutePath() });
        int exitValue = p.waitFor();
        return new ExecutionResult(null, readStream(p.getInputStream()), readStream(p.getErrorStream()), exitValue);
    } catch (IOException e) {
        // TODO : this is not really going to be working on all OS!
        if (e.getMessage().contains("Cannot run program")) {
            String errMsg = "Please install node.js to use this feature https://github.com/joyent/node/wiki/Installation";
            throw new STJSRuntimeException(errMsg, e);
        }
        throw new STJSRuntimeException(e);
    } catch (InterruptedException e) {
        throw new STJSRuntimeException(e);
    }
}
Also used : STJSRuntimeException(org.stjs.generator.STJSRuntimeException) IOException(java.io.IOException) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Aggregations

SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)6 IOException (java.io.IOException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 DiscoveryException (io.joynr.exceptions.DiscoveryException)2 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)2 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)2 MessagingQos (io.joynr.messaging.MessagingQos)2 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)2 Optional (com.google.common.base.Optional)1 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1 ImmutableList (com.google.common.collect.ImmutableList)1 Closer (com.google.common.io.Closer)1 SubscriptionException (io.joynr.exceptions.SubscriptionException)1 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)1 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)1 Closeable (java.io.Closeable)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1